Get rid of duplicate char*/Section* TextSection
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 24 Sep 2008 22:15:21 +0000 (22:15 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 24 Sep 2008 22:15:21 +0000 (22:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56574 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/DwarfWriter.cpp
lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
lib/Target/DarwinTargetAsmInfo.cpp
lib/Target/ELFTargetAsmInfo.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index 931e31a63c65645a115fb4f80dc66279b98e1774..077f5b1e7749fe9c2c2fede8a983df5e8ca45687 100644 (file)
@@ -92,6 +92,7 @@ namespace llvm {
     /// CurrentSection - The current section we are emitting to.  This is
     /// controlled and used by the SwitchSection method.
     std::string CurrentSection;
+    const Section* CurrentSection_;
 
     /// IsInTextSection - True if the current section we are emitting to is a
     /// text section.
index 49a99c509e60e6e8e7faa00608707b8654b33a97..6e019fd73b7ef4c47a2ba66387abbe9cbde0c357 100644 (file)
@@ -131,8 +131,7 @@ namespace llvm {
 
     /// TextSection - Section directive for standard text.
     ///
-    const char *TextSection;              // Defaults to ".text".
-    const Section *TextSection_;
+    const Section *TextSection;              // Defaults to ".text".
 
     /// DataSection - Section directive for standard data.
     ///
@@ -599,12 +598,9 @@ namespace llvm {
 
     // Accessors.
     //
-    const char *getTextSection() const {
+    const Section *getTextSection() const {
       return TextSection;
     }
-    const Section *getTextSection_() const {
-      return TextSection_;
-    }
     const char *getDataSection() const {
       return DataSection;
     }
index 9fc57a9545c09baff5471476a1c74db2675bdf45..3c25ab73b21bcf3d9c3caa03f27df1fb32dd08d4 100644 (file)
@@ -114,6 +114,7 @@ void AsmPrinter::SwitchToSection(const Section* NS) {
 
   // FIXME: Make CurrentSection a Section* in the future
   CurrentSection = NewSection;
+  CurrentSection_ = NS;
 
   if (!CurrentSection.empty()) {
     // If section is named we need to switch into it via special '.section'
@@ -174,7 +175,7 @@ bool AsmPrinter::doFinalization(Module &M) {
 
   if (TAI->getSetDirective()) {
     if (!M.alias_empty())
-      SwitchToTextSection(TAI->getTextSection());
+      SwitchToSection(TAI->getTextSection());
 
     O << '\n';
     for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
index 99e94e2ac049b986e210962ad1c88ed3b209e387..5d2581f5f3baeadbc8e90ee0c8acdf3f6635474d 100644 (file)
@@ -1152,7 +1152,7 @@ private:
 
   /// SectionMap - Provides a unique id per text section.
   ///
-  UniqueVector<std::string> SectionMap;
+  UniqueVector<const Section*> SectionMap;
 
   /// SectionSourceLines - Tracks line numbers per text section.
   ///
@@ -2062,7 +2062,7 @@ private:
     Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
     EmitLabel("section_ranges", 0);
 
-    Asm->SwitchToTextSection(TAI->getTextSection());
+    Asm->SwitchToSection(TAI->getTextSection());
     EmitLabel("text_begin", 0);
     Asm->SwitchToDataSection(TAI->getDataSection());
     EmitLabel("data_begin", 0);
@@ -2353,9 +2353,10 @@ private:
       // Isolate current sections line info.
       const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
 
-      if (VerboseAsm)
-        Asm->EOL(std::string("Section ") + SectionMap[j + 1]);
-      else
+      if (VerboseAsm) {
+        const Section* S = SectionMap[j + 1];
+        Asm->EOL(std::string("Section ") + S->getName());
+      } else
         Asm->EOL();
 
       // Dwarf assumes we start with first line of first source file.
@@ -2747,14 +2748,14 @@ public:
     if (!ShouldEmitDwarf()) return;
 
     // Standard sections final addresses.
-    Asm->SwitchToTextSection(TAI->getTextSection());
+    Asm->SwitchToSection(TAI->getTextSection());
     EmitLabel("text_end", 0);
     Asm->SwitchToDataSection(TAI->getDataSection());
     EmitLabel("data_end", 0);
 
     // End text sections.
     for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
-      Asm->SwitchToTextSection(SectionMap[i].c_str());
+      Asm->SwitchToSection(SectionMap[i]);
       EmitLabel("section_end", i);
     }
 
@@ -2832,7 +2833,7 @@ public:
 
     if (!LineInfos.empty()) {
       // Get section line info.
-      unsigned ID = SectionMap.insert(Asm->CurrentSection);
+      unsigned ID = SectionMap.insert(Asm->CurrentSection_);
       if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
       std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
       // Append the function info to section info.
index 16abca22e11699144d3ad0c070c59629eb71c077..7f069f699a2f4ee5a7e03c918f399cc18e9dbeab 100644 (file)
@@ -62,7 +62,7 @@ static void EmitCamlGlobal(const Module &M, raw_ostream &OS, AsmPrinter &AP,
 
 void OcamlGCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
                                            const TargetAsmInfo &TAI) {
-  AP.SwitchToTextSection(TAI.getTextSection());
+  AP.SwitchToSection(TAI.getTextSection());
   EmitCamlGlobal(getModule(), OS, AP, TAI, "code_begin");
   
   AP.SwitchToDataSection(TAI.getDataSection());
@@ -97,7 +97,7 @@ void OcamlGCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
     AddressAlignLog = 3;
   }
 
-  AP.SwitchToTextSection(TAI.getTextSection());
+  AP.SwitchToSection(TAI.getTextSection());
   EmitCamlGlobal(getModule(), OS, AP, TAI, "code_end");
   
   AP.SwitchToDataSection(TAI.getDataSection());
index 2fc1d28d2b6b82ec80ae9da9bd8fd3c11cf97c7c..a5b72e3edd3abddd6620dd8da5bb842e46764f58 100644 (file)
@@ -82,7 +82,7 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
     if (isWeak)
       return TextCoalSection;
     else
-      return getTextSection_();
+      return getTextSection();
    case SectionKind::Data:
    case SectionKind::ThreadData:
    case SectionKind::BSS:
index 9ffc72d2340d5d98c4b0c586a7cc5d396c3177f2..4529d0158d9cafbb18bc55242a99dfb6ae5b48a9 100644 (file)
@@ -27,7 +27,6 @@ using namespace llvm;
 ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) {
   ETM = &TM;
 
-  TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code);
   DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable);
   BSSSection_  = getUnnamedSection("\t.bss",
                                    SectionFlags::Writeable | SectionFlags::BSS);
@@ -49,7 +48,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
      case Function::InternalLinkage:
      case Function::DLLExportLinkage:
      case Function::ExternalLinkage:
-      return getTextSection_();
+      return getTextSection();
      case Function::WeakLinkage:
      case Function::LinkOnceLinkage:
       std::string Name = UniqueSectionForGlobal(GV, Kind);
index 2d9ecbd71e3331c0167a3832b5f81cd089804b44..f21cb4e710faf3c9b609b38d5b16af365e7e3584 100644 (file)
@@ -637,7 +637,7 @@ bool PPCLinuxAsmPrinter::doInitialization(Module &M) {
   // GNU as handles section names wrapped in quotes
   Mang->setUseQuotes(true);
 
-  SwitchToTextSection(TAI->getTextSection());
+  SwitchToSection(TAI->getTextSection());
 
   return Result;
 }
@@ -864,7 +864,7 @@ bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
     SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
                         "pure_instructions,16");
   }
-  SwitchToTextSection(TAI->getTextSection());
+  SwitchToSection(TAI->getTextSection());
 
   return Result;
 }
index 536f16d6578a22d6e0d62ecca9bddba3c2366763..df540393d5c56aeb3a0be1617b52a3737c373a3a 100644 (file)
@@ -26,8 +26,7 @@
 using namespace llvm;
 
 TargetAsmInfo::TargetAsmInfo() :
-  TextSection("\t.text"),
-  TextSection_(0),
+  TextSection(0),
   DataSection("\t.data"),
   DataSection_(0),
   BSSSection("\t.bss"),
@@ -126,7 +125,7 @@ TargetAsmInfo::TargetAsmInfo() :
   DwarfEHFrameSection(".eh_frame"),
   DwarfExceptionSection(".gcc_except_table"),
   AsmTransCBE(0) {
-  TextSection_ = getUnnamedSection(TextSection);
+  TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
   DataSection_ = getUnnamedSection(DataSection);
 }
 
@@ -300,7 +299,7 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
     return getNamedSection(Name.c_str(), Flags);
   } else {
     if (Kind == SectionKind::Text)
-      return getTextSection_();
+      return getTextSection();
     else if (isBSS(Kind) && getBSSSection_())
       return getBSSSection_();
     else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
index 64858f89bd5b5dc22fde1560ffe45105997a1f44..9f9e2ed7d6842006395224de8b87bc67383221a1 100644 (file)
@@ -433,7 +433,7 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
   Data64bitsDirective = "\tdq\t";
   HasDotTypeDotSizeDirective = false;
 
-  TextSection = "_text";
+  TextSection = getUnnamedSection("_text", SectionFlags::Code);
   DataSection = "_data";
   JumpTableDataSection = NULL;
   SwitchToSectionDirective = "";