Get rid of duplicate char*/Section* TextSection

llvm-svn: 56574
This commit is contained in:
Anton Korobeynikov 2008-09-24 22:15:21 +00:00
parent 076e905b94
commit f8dc8aac3c
10 changed files with 24 additions and 27 deletions

View File

@ -92,6 +92,7 @@ namespace llvm {
/// CurrentSection - The current section we are emitting to. This is /// CurrentSection - The current section we are emitting to. This is
/// controlled and used by the SwitchSection method. /// controlled and used by the SwitchSection method.
std::string CurrentSection; std::string CurrentSection;
const Section* CurrentSection_;
/// IsInTextSection - True if the current section we are emitting to is a /// IsInTextSection - True if the current section we are emitting to is a
/// text section. /// text section.

View File

@ -131,8 +131,7 @@ namespace llvm {
/// TextSection - Section directive for standard text. /// TextSection - Section directive for standard text.
/// ///
const char *TextSection; // Defaults to ".text". const Section *TextSection; // Defaults to ".text".
const Section *TextSection_;
/// DataSection - Section directive for standard data. /// DataSection - Section directive for standard data.
/// ///
@ -599,12 +598,9 @@ namespace llvm {
// Accessors. // Accessors.
// //
const char *getTextSection() const { const Section *getTextSection() const {
return TextSection; return TextSection;
} }
const Section *getTextSection_() const {
return TextSection_;
}
const char *getDataSection() const { const char *getDataSection() const {
return DataSection; return DataSection;
} }

View File

@ -114,6 +114,7 @@ void AsmPrinter::SwitchToSection(const Section* NS) {
// FIXME: Make CurrentSection a Section* in the future // FIXME: Make CurrentSection a Section* in the future
CurrentSection = NewSection; CurrentSection = NewSection;
CurrentSection_ = NS;
if (!CurrentSection.empty()) { if (!CurrentSection.empty()) {
// If section is named we need to switch into it via special '.section' // 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 (TAI->getSetDirective()) {
if (!M.alias_empty()) if (!M.alias_empty())
SwitchToTextSection(TAI->getTextSection()); SwitchToSection(TAI->getTextSection());
O << '\n'; O << '\n';
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();

View File

@ -1152,7 +1152,7 @@ private:
/// SectionMap - Provides a unique id per text section. /// SectionMap - Provides a unique id per text section.
/// ///
UniqueVector<std::string> SectionMap; UniqueVector<const Section*> SectionMap;
/// SectionSourceLines - Tracks line numbers per text section. /// SectionSourceLines - Tracks line numbers per text section.
/// ///
@ -2062,7 +2062,7 @@ private:
Asm->SwitchToDataSection(TAI->getDwarfRangesSection()); Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
EmitLabel("section_ranges", 0); EmitLabel("section_ranges", 0);
Asm->SwitchToTextSection(TAI->getTextSection()); Asm->SwitchToSection(TAI->getTextSection());
EmitLabel("text_begin", 0); EmitLabel("text_begin", 0);
Asm->SwitchToDataSection(TAI->getDataSection()); Asm->SwitchToDataSection(TAI->getDataSection());
EmitLabel("data_begin", 0); EmitLabel("data_begin", 0);
@ -2353,9 +2353,10 @@ private:
// Isolate current sections line info. // Isolate current sections line info.
const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j]; const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
if (VerboseAsm) if (VerboseAsm) {
Asm->EOL(std::string("Section ") + SectionMap[j + 1]); const Section* S = SectionMap[j + 1];
else Asm->EOL(std::string("Section ") + S->getName());
} else
Asm->EOL(); Asm->EOL();
// Dwarf assumes we start with first line of first source file. // Dwarf assumes we start with first line of first source file.
@ -2747,14 +2748,14 @@ public:
if (!ShouldEmitDwarf()) return; if (!ShouldEmitDwarf()) return;
// Standard sections final addresses. // Standard sections final addresses.
Asm->SwitchToTextSection(TAI->getTextSection()); Asm->SwitchToSection(TAI->getTextSection());
EmitLabel("text_end", 0); EmitLabel("text_end", 0);
Asm->SwitchToDataSection(TAI->getDataSection()); Asm->SwitchToDataSection(TAI->getDataSection());
EmitLabel("data_end", 0); EmitLabel("data_end", 0);
// End text sections. // End text sections.
for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
Asm->SwitchToTextSection(SectionMap[i].c_str()); Asm->SwitchToSection(SectionMap[i]);
EmitLabel("section_end", i); EmitLabel("section_end", i);
} }
@ -2832,7 +2833,7 @@ public:
if (!LineInfos.empty()) { if (!LineInfos.empty()) {
// Get section line info. // Get section line info.
unsigned ID = SectionMap.insert(Asm->CurrentSection); unsigned ID = SectionMap.insert(Asm->CurrentSection_);
if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID); if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1]; std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
// Append the function info to section info. // Append the function info to section info.

View File

@ -62,7 +62,7 @@ static void EmitCamlGlobal(const Module &M, raw_ostream &OS, AsmPrinter &AP,
void OcamlGCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP, void OcamlGCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) { const TargetAsmInfo &TAI) {
AP.SwitchToTextSection(TAI.getTextSection()); AP.SwitchToSection(TAI.getTextSection());
EmitCamlGlobal(getModule(), OS, AP, TAI, "code_begin"); EmitCamlGlobal(getModule(), OS, AP, TAI, "code_begin");
AP.SwitchToDataSection(TAI.getDataSection()); AP.SwitchToDataSection(TAI.getDataSection());
@ -97,7 +97,7 @@ void OcamlGCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
AddressAlignLog = 3; AddressAlignLog = 3;
} }
AP.SwitchToTextSection(TAI.getTextSection()); AP.SwitchToSection(TAI.getTextSection());
EmitCamlGlobal(getModule(), OS, AP, TAI, "code_end"); EmitCamlGlobal(getModule(), OS, AP, TAI, "code_end");
AP.SwitchToDataSection(TAI.getDataSection()); AP.SwitchToDataSection(TAI.getDataSection());

View File

@ -82,7 +82,7 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
if (isWeak) if (isWeak)
return TextCoalSection; return TextCoalSection;
else else
return getTextSection_(); return getTextSection();
case SectionKind::Data: case SectionKind::Data:
case SectionKind::ThreadData: case SectionKind::ThreadData:
case SectionKind::BSS: case SectionKind::BSS:

View File

@ -27,7 +27,6 @@ using namespace llvm;
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) { ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) {
ETM = &TM; ETM = &TM;
TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code);
DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable); DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable);
BSSSection_ = getUnnamedSection("\t.bss", BSSSection_ = getUnnamedSection("\t.bss",
SectionFlags::Writeable | SectionFlags::BSS); SectionFlags::Writeable | SectionFlags::BSS);
@ -49,7 +48,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
case Function::InternalLinkage: case Function::InternalLinkage:
case Function::DLLExportLinkage: case Function::DLLExportLinkage:
case Function::ExternalLinkage: case Function::ExternalLinkage:
return getTextSection_(); return getTextSection();
case Function::WeakLinkage: case Function::WeakLinkage:
case Function::LinkOnceLinkage: case Function::LinkOnceLinkage:
std::string Name = UniqueSectionForGlobal(GV, Kind); std::string Name = UniqueSectionForGlobal(GV, Kind);

View File

@ -637,7 +637,7 @@ bool PPCLinuxAsmPrinter::doInitialization(Module &M) {
// GNU as handles section names wrapped in quotes // GNU as handles section names wrapped in quotes
Mang->setUseQuotes(true); Mang->setUseQuotes(true);
SwitchToTextSection(TAI->getTextSection()); SwitchToSection(TAI->getTextSection());
return Result; return Result;
} }
@ -864,7 +864,7 @@ bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs," SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
"pure_instructions,16"); "pure_instructions,16");
} }
SwitchToTextSection(TAI->getTextSection()); SwitchToSection(TAI->getTextSection());
return Result; return Result;
} }

View File

@ -26,8 +26,7 @@
using namespace llvm; using namespace llvm;
TargetAsmInfo::TargetAsmInfo() : TargetAsmInfo::TargetAsmInfo() :
TextSection("\t.text"), TextSection(0),
TextSection_(0),
DataSection("\t.data"), DataSection("\t.data"),
DataSection_(0), DataSection_(0),
BSSSection("\t.bss"), BSSSection("\t.bss"),
@ -126,7 +125,7 @@ TargetAsmInfo::TargetAsmInfo() :
DwarfEHFrameSection(".eh_frame"), DwarfEHFrameSection(".eh_frame"),
DwarfExceptionSection(".gcc_except_table"), DwarfExceptionSection(".gcc_except_table"),
AsmTransCBE(0) { AsmTransCBE(0) {
TextSection_ = getUnnamedSection(TextSection); TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
DataSection_ = getUnnamedSection(DataSection); DataSection_ = getUnnamedSection(DataSection);
} }
@ -300,7 +299,7 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
return getNamedSection(Name.c_str(), Flags); return getNamedSection(Name.c_str(), Flags);
} else { } else {
if (Kind == SectionKind::Text) if (Kind == SectionKind::Text)
return getTextSection_(); return getTextSection();
else if (isBSS(Kind) && getBSSSection_()) else if (isBSS(Kind) && getBSSSection_())
return getBSSSection_(); return getBSSSection_();
else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind)) else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))

View File

@ -433,7 +433,7 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Data64bitsDirective = "\tdq\t"; Data64bitsDirective = "\tdq\t";
HasDotTypeDotSizeDirective = false; HasDotTypeDotSizeDirective = false;
TextSection = "_text"; TextSection = getUnnamedSection("_text", SectionFlags::Code);
DataSection = "_data"; DataSection = "_data";
JumpTableDataSection = NULL; JumpTableDataSection = NULL;
SwitchToSectionDirective = ""; SwitchToSectionDirective = "";