Changes in directory llvm/lib/CodeGen:
AsmPrinter.cpp updated: 1.68 -> 1.69 DwarfWriter.cpp updated: 1.58 -> 1.59 --- Log message: Split SwitchSection into SwitchTo{Text|Data}Section methods. --- Diffs of the changes: (+81 -39) AsmPrinter.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++------------ DwarfWriter.cpp | 50 ++++++++++++++++++++-------------------- 2 files changed, 81 insertions(+), 39 deletions(-) Index: llvm/lib/CodeGen/AsmPrinter.cpp diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.68 llvm/lib/CodeGen/AsmPrinter.cpp:1.69 --- llvm/lib/CodeGen/AsmPrinter.cpp:1.68 Sat May 6 16:27:14 2006 +++ llvm/lib/CodeGen/AsmPrinter.cpp Mon May 8 23:59:56 2006 @@ -59,10 +59,11 @@ } -/// 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 @@ 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 @@ 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 @@ } } +/// 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 @@ << 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 @@ 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 @@ 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 @@ 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; Index: llvm/lib/CodeGen/DwarfWriter.cpp diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.58 llvm/lib/CodeGen/DwarfWriter.cpp:1.59 --- llvm/lib/CodeGen/DwarfWriter.cpp:1.58 Tue May 2 20:29:56 2006 +++ llvm/lib/CodeGen/DwarfWriter.cpp Mon May 8 23:59:56 2006 @@ -1647,33 +1647,33 @@ /// 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::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 @@ // 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 @@ 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 @@ 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 @@ /// 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::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 @@ // 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::EmitDebugLoc() { // Start the dwarf loc section. - Asm->SwitchSection(DwarfLocSection, 0); + Asm->SwitchToDataSection(DwarfLocSection, 0); O << "\n"; } @@ -2195,7 +2195,7 @@ /// 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::EmitDebugRanges() { // Start the dwarf ranges section. - Asm->SwitchSection(DwarfRangesSection, 0); + Asm->SwitchToDataSection(DwarfRangesSection, 0); O << "\n"; } @@ -2245,7 +2245,7 @@ /// void DwarfWriter::EmitDebugMacInfo() { // Start the dwarf macinfo section. - Asm->SwitchSection(DwarfMacInfoSection, 0); + Asm->SwitchToDataSection(DwarfMacInfoSection, 0); O << "\n"; } @@ -2381,9 +2381,9 @@ 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. _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits