diff options
author | Chris Lattner <sabre@nondot.org> | 2006-05-09 04:59:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-05-09 04:59:56 +0000 |
commit | 4632d7a57008564c4b0f8246e85bd813a200d2c6 (patch) | |
tree | 8b69e32644052f6eb34fe57fd56e1024a5f56f77 /lib/CodeGen | |
parent | f668ffc4c2cf3da8ef0948b316d971c4b41b0e05 (diff) |
Split SwitchSection into SwitchTo{Text|Data}Section methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 70 | ||||
-rw-r--r-- | lib/CodeGen/DwarfWriter.cpp | 50 |
2 files changed, 81 insertions, 39 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 9aca4e25ac..5b44c9ca5d 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -59,10 +59,11 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) } -/// SwitchSection - Switch to the specified section of the executable if we -/// are not already in it! +/// SwitchToTextSection - Switch to the specified text section of the executable +/// if we are not already in it! /// -void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { +void AsmPrinter::SwitchToTextSection(const char *NewSection, + const GlobalValue *GV) { std::string NS; // Microsoft ML/MASM has a fundamentally different approach to handling @@ -78,12 +79,8 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { return; } - bool isData = strcmp(NewSection , ".data") == 0; - if (GV && GV->hasSection()) NS = GV->getSection(); - else if (isData) - NS = "_data"; else NS = "_text"; @@ -91,8 +88,7 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { if (!CurrentSection.empty()) O << CurrentSection << "\tends\n\n"; CurrentSection = NS; - O << CurrentSection << (isData ? "\tsegment 'DATA'\n" - : "\tsegment 'CODE'\n"); + O << CurrentSection << "\tsegment 'CODE'\n"; } } else { if (GV && GV->hasSection()) @@ -108,6 +104,52 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { } } +/// SwitchToTextSection - Switch to the specified text section of the executable +/// if we are not already in it! +/// +void AsmPrinter::SwitchToDataSection(const char *NewSection, + const GlobalValue *GV) { + std::string NS; + + // Microsoft ML/MASM has a fundamentally different approach to handling + // sections. + + if (MLSections) { + if (*NewSection == 0) { + // Simply end the current section, if any. + if (!CurrentSection.empty()) { + O << CurrentSection << "\tends\n\n"; + CurrentSection.clear(); + } + return; + } + + if (GV && GV->hasSection()) + NS = GV->getSection(); + else + NS = "_data"; + + if (CurrentSection != NS) { + if (!CurrentSection.empty()) + O << CurrentSection << "\tends\n\n"; + CurrentSection = NS; + O << CurrentSection << "\tsegment 'DATA'\n"; + } + } else { + if (GV && GV->hasSection()) + NS = SwitchToSectionDirective + GV->getSection(); + else + NS = std::string("\t")+NewSection; + + if (CurrentSection != NS) { + CurrentSection = NS; + if (!CurrentSection.empty()) + O << CurrentSection << '\n'; + } + } +} + + bool AsmPrinter::doInitialization(Module &M) { Mang = new Mangler(M, GlobalPrefix); @@ -116,7 +158,7 @@ bool AsmPrinter::doInitialization(Module &M) { << M.getModuleInlineAsm() << "\n" << CommentString << " End of file scope inline assembly\n"; - SwitchSection("", 0); // Reset back to no section. + SwitchToDataSection("", 0); // Reset back to no section. if (MachineDebugInfo *DebugInfo = getAnalysisToUpdate<MachineDebugInfo>()) { DebugInfo->AnalyzeModule(M); @@ -146,7 +188,7 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { if (CP.empty()) return; const TargetData *TD = TM.getTargetData(); - SwitchSection(ConstantPoolSection, 0); + SwitchToDataSection(ConstantPoolSection, 0); EmitAlignment(MCP->getConstantPoolAlignment()); for (unsigned i = 0, e = CP.size(); i != e; ++i) { O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i @@ -175,7 +217,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) { TM.getRelocationModel() == Reloc::DynamicNoPIC) && "Unhandled relocation model emitting jump table information!"); - SwitchSection(JumpTableSection, 0); + SwitchToDataSection(JumpTableSection, 0); EmitAlignment(Log2_32(TD->getPointerAlignment())); for (unsigned i = 0, e = JT.size(); i != e; ++i) { O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i @@ -204,14 +246,14 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { return true; // No need to emit this at all. if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) { - SwitchSection(StaticCtorsSection, 0); + SwitchToDataSection(StaticCtorsSection, 0); EmitAlignment(2, 0); EmitXXStructorList(GV->getInitializer()); return true; } if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) { - SwitchSection(StaticDtorsSection, 0); + SwitchToDataSection(StaticDtorsSection, 0); EmitAlignment(2, 0); EmitXXStructorList(GV->getInitializer()); return true; diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index b700618267..5a664ff367 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -1647,33 +1647,33 @@ void DwarfWriter::ConstructRootScope(DebugScope *RootScope) { /// void DwarfWriter::EmitInitial() const { // Dwarf sections base addresses. - Asm->SwitchSection(DwarfFrameSection, 0); + Asm->SwitchToDataSection(DwarfFrameSection, 0); EmitLabel("section_frame", 0); - Asm->SwitchSection(DwarfInfoSection, 0); + Asm->SwitchToDataSection(DwarfInfoSection, 0); EmitLabel("section_info", 0); EmitLabel("info", 0); - Asm->SwitchSection(DwarfAbbrevSection, 0); + Asm->SwitchToDataSection(DwarfAbbrevSection, 0); EmitLabel("section_abbrev", 0); EmitLabel("abbrev", 0); - Asm->SwitchSection(DwarfARangesSection, 0); + Asm->SwitchToDataSection(DwarfARangesSection, 0); EmitLabel("section_aranges", 0); - Asm->SwitchSection(DwarfMacInfoSection, 0); + Asm->SwitchToDataSection(DwarfMacInfoSection, 0); EmitLabel("section_macinfo", 0); - Asm->SwitchSection(DwarfLineSection, 0); + Asm->SwitchToDataSection(DwarfLineSection, 0); EmitLabel("section_line", 0); EmitLabel("line", 0); - Asm->SwitchSection(DwarfLocSection, 0); + Asm->SwitchToDataSection(DwarfLocSection, 0); EmitLabel("section_loc", 0); - Asm->SwitchSection(DwarfPubNamesSection, 0); + Asm->SwitchToDataSection(DwarfPubNamesSection, 0); EmitLabel("section_pubnames", 0); - Asm->SwitchSection(DwarfStrSection, 0); + Asm->SwitchToDataSection(DwarfStrSection, 0); EmitLabel("section_str", 0); - Asm->SwitchSection(DwarfRangesSection, 0); + Asm->SwitchToDataSection(DwarfRangesSection, 0); EmitLabel("section_ranges", 0); - Asm->SwitchSection(TextSection, 0); + Asm->SwitchToDataSection(TextSection, 0); EmitLabel("text_begin", 0); - Asm->SwitchSection(DataSection, 0); + Asm->SwitchToDataSection(DataSection, 0); EmitLabel("data_begin", 0); } @@ -1849,7 +1849,7 @@ void DwarfWriter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, /// void DwarfWriter::EmitDebugInfo() const { // Start debug info section. - Asm->SwitchSection(DwarfInfoSection, 0); + Asm->SwitchToDataSection(DwarfInfoSection, 0); // Process each compile unit. for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { @@ -1884,7 +1884,7 @@ void DwarfWriter::EmitAbbreviations() const { // Check to see if it is worth the effort. if (!Abbreviations.empty()) { // Start the debug abbrev section. - Asm->SwitchSection(DwarfAbbrevSection, 0); + Asm->SwitchToDataSection(DwarfAbbrevSection, 0); EmitLabel("abbrev_begin", 0); @@ -1918,7 +1918,7 @@ void DwarfWriter::EmitDebugLines() const { const int MaxLineDelta = 255 + MinLineDelta; // Start the dwarf line section. - Asm->SwitchSection(DwarfLineSection, 0); + Asm->SwitchToDataSection(DwarfLineSection, 0); // Construct the section header. @@ -2061,7 +2061,7 @@ void DwarfWriter::EmitInitialDebugFrame() { AddressSize : -AddressSize; // Start the dwarf frame section. - Asm->SwitchSection(DwarfFrameSection, 0); + Asm->SwitchToDataSection(DwarfFrameSection, 0); EmitDifference("frame_common_end", 0, "frame_common_begin", 0); @@ -2090,7 +2090,7 @@ void DwarfWriter::EmitInitialDebugFrame() { /// section. void DwarfWriter::EmitFunctionDebugFrame() { // Start the dwarf frame section. - Asm->SwitchSection(DwarfFrameSection, 0); + Asm->SwitchToDataSection(DwarfFrameSection, 0); EmitDifference("frame_end", SubprogramCount, "frame_begin", SubprogramCount); @@ -2119,7 +2119,7 @@ void DwarfWriter::EmitFunctionDebugFrame() { /// void DwarfWriter::EmitDebugPubNames() { // Start the dwarf pubnames section. - Asm->SwitchSection(DwarfPubNamesSection, 0); + Asm->SwitchToDataSection(DwarfPubNamesSection, 0); // Process each compile unit. for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { @@ -2166,7 +2166,7 @@ void DwarfWriter::EmitDebugStr() { // Check to see if it is worth the effort. if (!StringPool.empty()) { // Start the dwarf str section. - Asm->SwitchSection(DwarfStrSection, 0); + Asm->SwitchToDataSection(DwarfStrSection, 0); // For each of strings in the string pool. for (unsigned StringID = 1, N = StringPool.size(); @@ -2186,7 +2186,7 @@ void DwarfWriter::EmitDebugStr() { /// void DwarfWriter::EmitDebugLoc() { // Start the dwarf loc section. - Asm->SwitchSection(DwarfLocSection, 0); + Asm->SwitchToDataSection(DwarfLocSection, 0); O << "\n"; } @@ -2195,7 +2195,7 @@ void DwarfWriter::EmitDebugLoc() { /// void DwarfWriter::EmitDebugARanges() { // Start the dwarf aranges section. - Asm->SwitchSection(DwarfARangesSection, 0); + Asm->SwitchToDataSection(DwarfARangesSection, 0); // FIXME - Mock up #if 0 @@ -2236,7 +2236,7 @@ void DwarfWriter::EmitDebugARanges() { /// void DwarfWriter::EmitDebugRanges() { // Start the dwarf ranges section. - Asm->SwitchSection(DwarfRangesSection, 0); + Asm->SwitchToDataSection(DwarfRangesSection, 0); O << "\n"; } @@ -2245,7 +2245,7 @@ void DwarfWriter::EmitDebugRanges() { /// void DwarfWriter::EmitDebugMacInfo() { // Start the dwarf macinfo section. - Asm->SwitchSection(DwarfMacInfoSection, 0); + Asm->SwitchToDataSection(DwarfMacInfoSection, 0); O << "\n"; } @@ -2381,9 +2381,9 @@ void DwarfWriter::EndModule() { EOL("Dwarf End Module"); // Standard sections final addresses. - Asm->SwitchSection(TextSection, 0); + Asm->SwitchToTextSection(TextSection, 0); EmitLabel("text_end", 0); - Asm->SwitchSection(DataSection, 0); + Asm->SwitchToDataSection(DataSection, 0); EmitLabel("data_end", 0); // Compute DIE offsets and sizes. |