[llvm-commits] [llvm] r77252 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h

Chris Lattner sabre at nondot.org
Mon Jul 27 14:28:04 PDT 2009


Author: lattner
Date: Mon Jul 27 16:28:04 2009
New Revision: 77252

URL: http://llvm.org/viewvc/llvm-project?rev=77252&view=rev
Log:
hoist MCContext/MCStreamer up to AsmPrinter since we're going to start creating
MCSections soon instead of Section for all targets, and we need something to
own them.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=77252&r1=77251&r2=77252&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Jul 27 16:28:04 2009
@@ -33,6 +33,8 @@
   class MachineConstantPoolValue;
   class MachineModuleInfo;
   class MCInst;
+  class MCContext;
+  class MCStreamer;
   class DwarfWriter;
   class Mangler;
   class Section;
@@ -81,6 +83,17 @@
     ///
     const TargetRegisterInfo *TRI;
 
+    /// OutContext - This is the context for the output file that we are
+    /// streaming.  This owns all of the global MC-related objects for the
+    /// generated translation unit.
+    MCContext &OutContext;
+    
+    /// OutStreamer - This is the MCStreamer object for the file we are
+    /// generating.  This contains the transient state for the current
+    /// translation unit that we are generating (such as the current section
+    /// etc).
+    MCStreamer &OutStreamer;
+    
     /// The current machine function.
     const MachineFunction *MF;
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=77252&r1=77251&r2=77252&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Jul 27 16:28:04 2009
@@ -22,6 +22,8 @@
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/Analysis/DebugInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -47,6 +49,10 @@
                        const TargetAsmInfo *T, bool VDef)
   : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
     TM(tm), TAI(T), TRI(tm.getRegisterInfo()),
+
+    OutContext(*new MCContext()),
+    OutStreamer(*createAsmStreamer(OutContext, O)),
+
     IsInTextSection(false), LastMI(0), LastFn(0), Counter(~0U),
     PrevDLT(0, ~0U, ~0U) {
   DW = 0; MMI = 0;
@@ -61,6 +67,9 @@
   for (gcp_iterator I = GCMetadataPrinters.begin(),
                     E = GCMetadataPrinters.end(); I != E; ++I)
     delete I->second;
+  
+  delete &OutStreamer;
+  delete &OutContext;
 }
 
 /// SwitchToTextSection - Switch to the specified text section of the executable
@@ -270,6 +279,8 @@
 
   delete Mang; Mang = 0;
   DW = 0; MMI = 0;
+  
+  OutStreamer.Finish();
   return false;
 }
 

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=77252&r1=77251&r2=77252&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Mon Jul 27 16:28:04 2009
@@ -751,18 +751,6 @@
   printInstruction(MI);
 }
 
-/// doInitialization
-bool X86ATTAsmPrinter::doInitialization(Module &M) {
-  if (NewAsmPrinter) {
-    Context = new MCContext();
-    // FIXME: Send this to "O" instead of outs().  For now, we force it to
-    // stdout to make it easy to compare.
-    Streamer = createAsmStreamer(*Context, outs());
-  }
-  
-  return AsmPrinter::doInitialization(M);
-}
-
 void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
   const TargetData *TD = TM.getTargetData();
 
@@ -988,18 +976,7 @@
   }
   
   // Do common shutdown.
-  bool Changed = AsmPrinter::doFinalization(M);
-  
-  if (NewAsmPrinter) {
-    Streamer->Finish();
-    
-    delete Streamer;
-    delete Context;
-    Streamer = 0;
-    Context = 0;
-  }
-  
-  return Changed;
+  return AsmPrinter::doFinalization(M);
 }
 
 // Include the auto-generated portion of the assembly writer.

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h?rev=77252&r1=77251&r2=77252&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h Mon Jul 27 16:28:04 2009
@@ -33,16 +33,11 @@
 
 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
   const X86Subtarget *Subtarget;
-  
-  MCContext *Context;
-  MCStreamer *Streamer;
  public:
   explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
                             const TargetAsmInfo *T, bool V)
     : AsmPrinter(O, TM, T, V) {
     Subtarget = &TM.getSubtarget<X86Subtarget>();
-    Context = 0;
-    Streamer = 0;
   }
 
   virtual const char *getPassName() const {
@@ -60,7 +55,6 @@
     AsmPrinter::getAnalysisUsage(AU);
   }
 
-  bool doInitialization(Module &M);
   bool doFinalization(Module &M);
 
   /// printInstruction - This method is automatically generated by tablegen





More information about the llvm-commits mailing list