change AsmPrinter to switch sections using AsmStreamer instead of
authorChris Lattner <sabre@nondot.org>
Mon, 17 Aug 2009 05:49:08 +0000 (05:49 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 17 Aug 2009 05:49:08 +0000 (05:49 +0000)
doing it directly.  This requires const'izing a bunch of stuff that
took sections, but this seems like the right semantic thing to do:
emitting a label to a section shouldn't mutate the MCSection object
itself, for example.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79227 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
include/llvm/MC/MCSymbol.h
include/llvm/MC/MCValue.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/MC/MCAsmStreamer.cpp
lib/MC/MCNullStreamer.cpp

index b8399d0115a805d7af390b329cd7051ba4ff81f2..48096c708ace1eba152dc12cd0cdf2b932c9fc45 100644 (file)
@@ -81,7 +81,7 @@ namespace llvm {
     /// @param Section.
     ///
     /// This corresponds to assembler directives like .section, .text, etc.
-    virtual void SwitchSection(MCSection *Section) = 0;
+    virtual void SwitchSection(const MCSection *Section) = 0;
 
     /// EmitLabel - Emit a label for @param Symbol into the current section.
     ///
index e857ebab70b45a1b76302150e5d0e09b8593a076..a5176bc24ffa26c1f6f52436ee21a583fc25b26c 100644 (file)
@@ -34,7 +34,7 @@ namespace llvm {
     std::string Name;
     /// Section - The section the symbol is defined in, or null if the symbol
     /// has not been defined in the associated translation unit.
-    MCSection *Section;
+    const MCSection *Section;
     
     /// IsTemporary - True if this is an assembler temporary label, which
     /// typically does not survive in the .o file's symbol table.  Usually
@@ -55,8 +55,8 @@ namespace llvm {
     void operator=(const MCSymbol&); // DO NOT IMPLEMENT
   public:
     
-    MCSection *getSection() const { return Section; }
-    void setSection(MCSection *Value) { Section = Value; }
+    const MCSection *getSection() const { return Section; }
+    void setSection(const MCSection *S) { Section = S; }
 
     bool isExternal() const { return IsExternal; }
     void setExternal(bool Value) { IsExternal = Value; }
index ee5ba84dd0f467c7a2343e7e0a5134c6d2cf8926..ec323fe1b3f960a6ecaf22d9e032f379169f520d 100644 (file)
@@ -49,7 +49,7 @@ public:
   ///
   /// @result - The value's associated section, or null for external or constant
   /// values.
-  MCSection *getAssociatedSection() const {
+  const MCSection *getAssociatedSection() const {
     return SymA ? SymA->getSection() : 0;
   }
 
index d46043b29cd08695e1ada9276dac6e5174a12687..7f23abe4ee139caf449bae6911b7ae23890ca52b 100644 (file)
@@ -98,23 +98,18 @@ TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
 /// FIXME: Remove support for null sections.
 ///
 void AsmPrinter::SwitchToSection(const MCSection *NS) {
-  // If we're already in this section, we're done.
-  if (CurrentSection == NS) return;
-
   CurrentSection = NS;
-
-  if (NS == 0) return;
-  
-  NS->PrintSwitchToSection(*TAI, O);
+  // FIXME: Remove support for null sections!
+  if (NS)
+    OutStreamer.SwitchSection(NS);
 }
 
 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
   MachineFunctionPass::getAnalysisUsage(AU);
   AU.addRequired<GCModuleInfo>();
-  if (ExuberantAsm) {
+  if (ExuberantAsm)
     AU.addRequired<MachineLoopInfo>();
-  }
 }
 
 bool AsmPrinter::doInitialization(Module &M) {
index db39fb8b1cbc79c98e4e803bd59cf09b4bf818d1..60d66f93af96a3e2063b1b0eee50aa6be9df9195 100644 (file)
@@ -24,7 +24,7 @@ class MCAsmStreamer : public MCStreamer {
   raw_ostream &OS;
   const TargetAsmInfo &TAI;
   AsmPrinter *Printer;
-  MCSection *CurSection;
+  const MCSection *CurSection;
 public:
   MCAsmStreamer(MCContext &Context, raw_ostream &_OS, const TargetAsmInfo &tai,
                 AsmPrinter *_AsmPrinter)
@@ -35,7 +35,7 @@ public:
   /// @name MCStreamer Interface
   /// @{
 
-  virtual void SwitchSection(MCSection *Section);
+  virtual void SwitchSection(const MCSection *Section);
 
   virtual void EmitLabel(MCSymbol *Symbol);
 
@@ -98,12 +98,10 @@ static inline MCValue truncateToSize(const MCValue &Value, unsigned Bytes) {
                       truncateToSize(Value.getConstant(), Bytes));
 }
 
-void MCAsmStreamer::SwitchSection(MCSection *Section) {
+void MCAsmStreamer::SwitchSection(const MCSection *Section) {
   if (Section != CurSection) {
     CurSection = Section;
-
-    // FIXME: Needs TargetAsmInfo!
-    Section->PrintSwitchToSection(*(const TargetAsmInfo*)0, OS);
+    Section->PrintSwitchToSection(TAI, OS);
   }
 }
 
index 3ac79cbf0a246e657508158b39d82466164a1c62..fcdd087e67ac4c1e0d07405e604f7fb9acbdd32e 100644 (file)
@@ -26,7 +26,7 @@ namespace {
     /// @name MCStreamer Interface
     /// @{
 
-    virtual void SwitchSection(MCSection *Section) {}
+    virtual void SwitchSection(const MCSection *Section) {}
 
     virtual void EmitLabel(MCSymbol *Symbol) {}