[llvm-commits] [llvm] r118394 - in /llvm/trunk: include/llvm/Target/TargetRegistry.h lib/CodeGen/LLVMTargetMachine.cpp tools/llvm-mc/llvm-mc.cpp

Che-Liang Chiou clchiou at gmail.com
Sun Nov 7 18:21:17 PST 2010


Author: clchiou
Date: Sun Nov  7 20:21:17 2010
New Revision: 118394

URL: http://llvm.org/viewvc/llvm-project?rev=118394&view=rev
Log:
Add registry hook for assembly text output

Modified:
    llvm/trunk/include/llvm/Target/TargetRegistry.h
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegistry.h?rev=118394&r1=118393&r2=118394&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegistry.h Sun Nov  7 20:21:17 2010
@@ -39,6 +39,13 @@
   class TargetAsmParser;
   class TargetMachine;
   class raw_ostream;
+  class formatted_raw_ostream;
+
+  MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
+                                bool isLittleEndian, bool isVerboseAsm,
+                                MCInstPrinter *InstPrint,
+                                MCCodeEmitter *CE,
+                                bool ShowInst);
 
   /// Target - Wrapper for Target specific information.
   ///
@@ -81,6 +88,13 @@
                                                 raw_ostream &_OS,
                                                 MCCodeEmitter *_Emitter,
                                                 bool RelaxAll);
+    typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
+                                             formatted_raw_ostream &OS,
+                                             bool isLittleEndian,
+                                             bool isVerboseAsm,
+                                             MCInstPrinter *InstPrint,
+                                             MCCodeEmitter *CE,
+                                             bool ShowInst);
 
   private:
     /// Next - The next registered target in the linked list, maintained by the
@@ -138,7 +152,13 @@
     /// ObjectStreamer, if registered.
     ObjectStreamerCtorTy ObjectStreamerCtorFn;
 
+    /// AsmStreamerCtorFn - Construction function for this target's
+    /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
+    AsmStreamerCtorTy AsmStreamerCtorFn;
+
   public:
+    Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
+
     /// @name Target Information
     /// @{
 
@@ -185,6 +205,9 @@
     /// hasObjectStreamer - Check if this target supports streaming to files.
     bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
 
+    /// hasAsmStreamer - Check if this target supports streaming to files.
+    bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
+
     /// @}
     /// @name Feature Constructors
     /// @{
@@ -292,6 +315,19 @@
       return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll);
     }
 
+    /// createAsmStreamer - Create a target specific MCStreamer.
+    MCStreamer *createAsmStreamer(MCContext &Ctx,
+                                  formatted_raw_ostream &OS,
+                                  bool isLittleEndian,
+                                  bool isVerboseAsm,
+                                  MCInstPrinter *InstPrint,
+                                  MCCodeEmitter *CE,
+                                  bool ShowInst) const {
+      // AsmStreamerCtorFn is default to llvm::createAsmStreamer
+      return AsmStreamerCtorFn(Ctx, OS, isLittleEndian, isVerboseAsm,
+                               InstPrint, CE, ShowInst);
+    }
+
     /// @}
   };
 
@@ -513,7 +549,7 @@
         T.CodeEmitterCtorFn = Fn;
     }
 
-    /// RegisterObjectStreamer - Register an MCStreamer implementation
+    /// RegisterObjectStreamer - Register a object code MCStreamer implementation
     /// for the given target.
     ///
     /// Clients are responsible for ensuring that registration doesn't occur
@@ -527,6 +563,20 @@
         T.ObjectStreamerCtorFn = Fn;
     }
 
+    /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
+    /// for the given target.
+    ///
+    /// Clients are responsible for ensuring that registration doesn't occur
+    /// while another thread is attempting to access the registry. Typically
+    /// this is done by initializing all targets at program startup.
+    ///
+    /// @param T - The target being registered.
+    /// @param Fn - A function to construct an MCStreamer for the target.
+    static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
+      if (T.AsmStreamerCtorFn == createAsmStreamer)
+        T.AsmStreamerCtorFn = Fn;
+    }
+
     /// @}
   };
 

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=118394&r1=118393&r2=118394&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Sun Nov  7 20:21:17 2010
@@ -144,10 +144,11 @@
     if (ShowMCEncoding)
       MCE = getTarget().createCodeEmitter(*this, *Context);
 
-    AsmStreamer.reset(createAsmStreamer(*Context, Out,
-                                        getTargetData()->isLittleEndian(),
-                                        getVerboseAsm(), InstPrinter,
-                                        MCE, ShowMCInst));
+    AsmStreamer.reset(getTarget().createAsmStreamer(*Context, Out,
+                                                    getTargetData()->isLittleEndian(),
+                                                    getVerboseAsm(),
+                                                    InstPrinter, MCE,
+                                                    ShowMCInst));
     break;
   }
   case CGFT_ObjectFile: {

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=118394&r1=118393&r2=118394&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Sun Nov  7 20:21:17 2010
@@ -342,9 +342,9 @@
     MCCodeEmitter *CE = 0;
     if (ShowEncoding)
       CE = TheTarget->createCodeEmitter(*TM, Ctx);
-    Str.reset(createAsmStreamer(Ctx, FOS,
-                                TM->getTargetData()->isLittleEndian(),
-                                /*asmverbose*/true, IP, CE, ShowInst));
+    Str.reset(TheTarget->createAsmStreamer(Ctx, FOS,
+                                           TM->getTargetData()->isLittleEndian(),
+                                           /*asmverbose*/true, IP, CE, ShowInst));
   } else if (FileType == OFT_Null) {
     Str.reset(createNullStreamer(Ctx));
   } else {





More information about the llvm-commits mailing list