diff options
author | Jeff Cohen <jeffc@jolt-lang.org> | 2006-05-02 03:58:45 +0000 |
---|---|---|
committer | Jeff Cohen <jeffc@jolt-lang.org> | 2006-05-02 03:58:45 +0000 |
commit | 51b776d25915ca7fbfc14578ff479352a772da06 (patch) | |
tree | b8d009e5524555f69bd9a0e00a8ba8fc84a9f392 /lib/CodeGen/AsmPrinter.cpp | |
parent | c6a057b04db506152c98355b51ba15d82a15b90a (diff) |
De-virtualize SwitchSection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28047 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/AsmPrinter.cpp')
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index aad02327c6..1753160e1f 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -47,6 +47,7 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) AlignDirective("\t.align\t"), AlignmentIsInBytes(true), SwitchToSectionDirective("\t.section\t"), + MLSections(false), ConstantPoolSection("\t.section .rodata\n"), JumpTableSection("\t.section .rodata\n"), StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"), @@ -63,16 +64,47 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) /// void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { std::string NS; - - 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'; + + // 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 != "") { + O << CurrentSection << "\tends\n"; + CurrentSection = ""; + } + return; + } + + bool isData = strcmp(NewSection , ".data") == 0; + + if (GV && GV->hasSection()) + NS = GV->getSection(); + else if (isData) + NS = "_data"; + else + NS = "_text"; + + if (CurrentSection != NS) { + if (CurrentSection != "") + O << CurrentSection << "\tends\n"; + CurrentSection = NS; + O << CurrentSection << (isData ? "\tsegment 'DATA'\n" + : "\tsegment 'CODE'\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'; + } } } |