MC/Matcher: Add support for over-riding the default MatchInstruction function
[oota-llvm.git] / include / llvm / Target / TargetRegistry.h
index 395526fa39422cbdc0c5f502bd638de20d64c0c9..36bbe000025c8390d5e127ba61a9e05c57e71cef 100644 (file)
 
 namespace llvm {
   class AsmPrinter;
-  class MCAsmParser;
-  class MCCodeEmitter;
   class Module;
+  class MCAssembler;
   class MCAsmInfo;
+  class MCAsmParser;
+  class MCCodeEmitter;
+  class MCContext;
   class MCDisassembler;
   class MCInstPrinter;
+  class MCStreamer;
+  class TargetAsmBackend;
+  class TargetAsmLexer;
   class TargetAsmParser;
   class TargetMachine;
-  class formatted_raw_ostream;
   class raw_ostream;
 
   /// Target - Wrapper for Target specific information.
@@ -50,24 +54,25 @@ namespace llvm {
 
     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
 
-    typedef const MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
-                                                const StringRef &TT);
+    typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
+                                                StringRef TT);
     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
                                                   const std::string &TT,
                                                   const std::string &Features);
-    typedef AsmPrinter *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
-                                            TargetMachine &TM,
-                                            const MCAsmInfo *MAI,
-                                            bool VerboseAsm);
-    typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,
-                                                MCAsmParser &P);
-    typedef const MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
+    typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
+                                            MCStreamer &Streamer);
+    typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
+                                                  const std::string &TT);
+    typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
+                                              const MCAsmInfo &MAI);
+    typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P);
+    typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
                                                   unsigned SyntaxVariant,
-                                                  const MCAsmInfo &MAI,
-                                                  raw_ostream &O);
+                                                  const MCAsmInfo &MAI);
     typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
-                                                TargetMachine &TM);
+                                                TargetMachine &TM,
+                                                MCContext &Ctx);
 
   private:
     /// Next - The next registered target in the linked list, maintained by the
@@ -88,28 +93,35 @@ namespace llvm {
     bool HasJIT;
 
     AsmInfoCtorFnTy AsmInfoCtorFn;
-    
+
     /// TargetMachineCtorFn - Construction function for this target's
     /// TargetMachine, if registered.
     TargetMachineCtorTy TargetMachineCtorFn;
 
+    /// AsmBackendCtorFn - Construction function for this target's
+    /// TargetAsmBackend, if registered.
+    AsmBackendCtorTy AsmBackendCtorFn;
+
+    /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
+    /// if registered.
+    AsmLexerCtorTy AsmLexerCtorFn;
+
+    /// AsmParserCtorFn - Construction function for this target's
+    /// TargetAsmParser, if registered.
+    AsmParserCtorTy AsmParserCtorFn;
+
     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
     /// if registered.
     AsmPrinterCtorTy AsmPrinterCtorFn;
 
-    /// AsmParserCtorFn - Construction function for this target's AsmParser,
-    /// if registered.
-    AsmParserCtorTy AsmParserCtorFn;
-    
     /// MCDisassemblerCtorFn - Construction function for this target's
     /// MCDisassembler, if registered.
     MCDisassemblerCtorTy MCDisassemblerCtorFn;
 
-    
-    /// MCInstPrinterCtorFn - Construction function for this target's 
+    /// MCInstPrinterCtorFn - Construction function for this target's
     /// MCInstPrinter, if registered.
     MCInstPrinterCtorTy MCInstPrinterCtorFn;
-    
+
     /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
     /// if registered.
     CodeEmitterCtorTy CodeEmitterCtorFn;
@@ -137,12 +149,18 @@ namespace llvm {
     /// hasTargetMachine - Check if this target supports code generation.
     bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
 
-    /// hasAsmPrinter - Check if this target supports .s printing.
-    bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
+    /// hasAsmBackend - Check if this target supports .o generation.
+    bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
+
+    /// hasAsmLexer - Check if this target supports .s lexing.
+    bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
 
     /// hasAsmParser - Check if this target supports .s parsing.
     bool hasAsmParser() const { return AsmParserCtorFn != 0; }
-    
+
+    /// hasAsmPrinter - Check if this target supports .s printing.
+    bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
+
     /// hasMCDisassembler - Check if this target has a disassembler.
     bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
 
@@ -155,7 +173,7 @@ namespace llvm {
     /// @}
     /// @name Feature Constructors
     /// @{
-    
+
     /// createAsmInfo - Create a MCAsmInfo implementation for the specified
     /// target triple.
     ///
@@ -163,12 +181,12 @@ namespace llvm {
     /// feature set; it should always be provided. Generally this should be
     /// either the target triple from the module, or the target triple of the
     /// host if that does not exist.
-    const MCAsmInfo *createAsmInfo(const StringRef &Triple) const {
+    MCAsmInfo *createAsmInfo(StringRef Triple) const {
       if (!AsmInfoCtorFn)
         return 0;
       return AsmInfoCtorFn(*this, Triple);
     }
-    
+
     /// createTargetMachine - Create a target specific machine implementation
     /// for the specified \arg Triple.
     ///
@@ -183,12 +201,22 @@ namespace llvm {
       return TargetMachineCtorFn(*this, Triple, Features);
     }
 
-    /// createAsmPrinter - Create a target specific assembly printer pass.
-    AsmPrinter *createAsmPrinter(formatted_raw_ostream &OS, TargetMachine &TM,
-                                 const MCAsmInfo *MAI, bool Verbose) const {
-      if (!AsmPrinterCtorFn)
+    /// createAsmBackend - Create a target specific assembly parser.
+    ///
+    /// \arg Triple - The target triple string.
+    /// \arg Backend - The target independent assembler object.
+    TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
+      if (!AsmBackendCtorFn)
         return 0;
-      return AsmPrinterCtorFn(OS, TM, MAI, Verbose);
+      return AsmBackendCtorFn(*this, Triple);
+    }
+
+    /// createAsmLexer - Create a target specific assembly lexer.
+    ///
+    TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
+      if (!AsmLexerCtorFn)
+        return 0;
+      return AsmLexerCtorFn(*this, MAI);
     }
 
     /// createAsmParser - Create a target specific assembly parser.
@@ -200,27 +228,34 @@ namespace llvm {
         return 0;
       return AsmParserCtorFn(*this, Parser);
     }
-    
-    const MCDisassembler *createMCDisassembler() const {
+
+    /// createAsmPrinter - Create a target specific assembly printer pass.  This
+    /// takes ownership of the MCStreamer object.
+    AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
+      if (!AsmPrinterCtorFn)
+        return 0;
+      return AsmPrinterCtorFn(TM, Streamer);
+    }
+
+    MCDisassembler *createMCDisassembler() const {
       if (!MCDisassemblerCtorFn)
         return 0;
       return MCDisassemblerCtorFn(*this);
     }
 
     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
-                                       const MCAsmInfo &MAI,
-                                       raw_ostream &O) const {
+                                       const MCAsmInfo &MAI) const {
       if (!MCInstPrinterCtorFn)
         return 0;
-      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
+      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
     }
-    
-    
+
+
     /// createCodeEmitter - Create a target specific code emitter.
-    MCCodeEmitter *createCodeEmitter(TargetMachine &TM) const {
+    MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
       if (!CodeEmitterCtorFn)
         return 0;
-      return CodeEmitterCtorFn(*this, TM);
+      return CodeEmitterCtorFn(*this, TM, Ctx);
     }
 
     /// @}
@@ -250,8 +285,8 @@ namespace llvm {
         return *this;
       }
       iterator operator++(int) {        // Postincrement
-        iterator tmp = *this; 
-        ++*this; 
+        iterator tmp = *this;
+        ++*this;
         return tmp;
       }
 
@@ -293,7 +328,7 @@ namespace llvm {
 
     /// RegisterTarget - Register the given target. Attempts to register a
     /// target which has already been registered will be ignored.
-    /// 
+    ///
     /// 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.
@@ -301,7 +336,7 @@ namespace llvm {
     /// @param T - The target being registered.
     /// @param Name - The target name. This should be a static string.
     /// @param ShortDesc - A short target description. This should be a static
-    /// string. 
+    /// string.
     /// @param TQualityFn - The triple match quality computation function for
     /// this target.
     /// @param HasJIT - Whether the target supports JIT code
@@ -314,11 +349,11 @@ namespace llvm {
 
     /// RegisterAsmInfo - Register a MCAsmInfo 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 a MCAsmInfo for the target.
     static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
@@ -326,62 +361,90 @@ namespace llvm {
       if (!T.AsmInfoCtorFn)
         T.AsmInfoCtorFn = Fn;
     }
-    
+
     /// RegisterTargetMachine - Register a TargetMachine 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 a TargetMachine for the target.
-    static void RegisterTargetMachine(Target &T, 
+    static void RegisterTargetMachine(Target &T,
                                       Target::TargetMachineCtorTy Fn) {
       // Ignore duplicate registration.
       if (!T.TargetMachineCtorFn)
         T.TargetMachineCtorFn = Fn;
     }
 
-    /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
-    /// target.
-    /// 
+    /// RegisterAsmBackend - Register a TargetAsmBackend 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 AsmPrinter for the target.
-    static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
-      // Ignore duplicate registration.
-      if (!T.AsmPrinterCtorFn)
-        T.AsmPrinterCtorFn = Fn;
+    /// @param Fn - A function to construct an AsmBackend for the target.
+    static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
+      if (!T.AsmBackendCtorFn)
+        T.AsmBackendCtorFn = Fn;
+    }
+
+    /// RegisterAsmLexer - Register a TargetAsmLexer 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 AsmLexer for the target.
+    static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
+      if (!T.AsmLexerCtorFn)
+        T.AsmLexerCtorFn = Fn;
     }
 
     /// RegisterAsmParser - Register a TargetAsmParser 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 AsmPrinter for the target.
+    /// @param Fn - A function to construct an AsmParser for the target.
     static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
       if (!T.AsmParserCtorFn)
         T.AsmParserCtorFn = Fn;
     }
-    
+
+    /// RegisterAsmPrinter - Register an AsmPrinter 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 AsmPrinter for the target.
+    static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
+      // Ignore duplicate registration.
+      if (!T.AsmPrinterCtorFn)
+        T.AsmPrinterCtorFn = Fn;
+    }
+
     /// RegisterMCDisassembler - Register a MCDisassembler 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 MCDisassembler for the target.
-    static void RegisterMCDisassembler(Target &T, 
+    static void RegisterMCDisassembler(Target &T,
                                        Target::MCDisassemblerCtorTy Fn) {
       if (!T.MCDisassemblerCtorFn)
         T.MCDisassemblerCtorFn = Fn;
@@ -389,7 +452,7 @@ namespace llvm {
 
     /// RegisterMCInstPrinter - Register a MCInstPrinter 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.
@@ -401,7 +464,7 @@ namespace llvm {
       if (!T.MCInstPrinterCtorFn)
         T.MCInstPrinterCtorFn = Fn;
     }
-    
+
     /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
     /// given target.
     ///
@@ -410,7 +473,7 @@ namespace llvm {
     /// this is done by initializing all targets at program startup.
     ///
     /// @param T - The target being registered.
-    /// @param Fn - A function to construct an AsmPrinter for the target.
+    /// @param Fn - A function to construct an MCCodeEmitter for the target.
     static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
       if (!T.CodeEmitterCtorFn)
         T.CodeEmitterCtorFn = Fn;
@@ -461,10 +524,10 @@ namespace llvm {
       TargetRegistry::RegisterAsmInfo(T, &Allocator);
     }
   private:
-    static const MCAsmInfo *Allocator(const Target &T, const StringRef &TT) {
+    static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
       return new MCAsmInfoImpl(T, TT);
     }
-    
+
   };
 
   /// RegisterAsmInfoFn - Helper template for registering a target assembly info
@@ -503,24 +566,43 @@ namespace llvm {
     }
   };
 
-  /// RegisterAsmPrinter - Helper template for registering a target specific
-  /// assembly printer, for use in the target machine initialization
+  /// RegisterAsmBackend - Helper template for registering a target specific
+  /// assembler backend. Usage:
+  ///
+  /// extern "C" void LLVMInitializeFooAsmBackend() {
+  ///   extern Target TheFooTarget;
+  ///   RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
+  /// }
+  template<class AsmBackendImpl>
+  struct RegisterAsmBackend {
+    RegisterAsmBackend(Target &T) {
+      TargetRegistry::RegisterAsmBackend(T, &Allocator);
+    }
+
+  private:
+    static TargetAsmBackend *Allocator(const Target &T,
+                                       const std::string &Triple) {
+      return new AsmBackendImpl(T, Triple);
+    }
+  };
+
+  /// RegisterAsmLexer - Helper template for registering a target specific
+  /// assembly lexer, for use in the target machine initialization
   /// function. Usage:
   ///
-  /// extern "C" void LLVMInitializeFooAsmPrinter() {
+  /// extern "C" void LLVMInitializeFooAsmLexer() {
   ///   extern Target TheFooTarget;
-  ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
+  ///   RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
   /// }
-  template<class AsmPrinterImpl>
-  struct RegisterAsmPrinter {
-    RegisterAsmPrinter(Target &T) {
-      TargetRegistry::RegisterAsmPrinter(T, &Allocator);
+  template<class AsmLexerImpl>
+  struct RegisterAsmLexer {
+    RegisterAsmLexer(Target &T) {
+      TargetRegistry::RegisterAsmLexer(T, &Allocator);
     }
 
   private:
-    static AsmPrinter *Allocator(formatted_raw_ostream &OS, TargetMachine &TM,
-                                 const MCAsmInfo *MAI, bool Verbose) {
-      return new AsmPrinterImpl(OS, TM, MAI, Verbose);
+    static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
+      return new AsmLexerImpl(T, MAI);
     }
   };
 
@@ -544,6 +626,26 @@ namespace llvm {
     }
   };
 
+  /// RegisterAsmPrinter - Helper template for registering a target specific
+  /// assembly printer, for use in the target machine initialization
+  /// function. Usage:
+  ///
+  /// extern "C" void LLVMInitializeFooAsmPrinter() {
+  ///   extern Target TheFooTarget;
+  ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
+  /// }
+  template<class AsmPrinterImpl>
+  struct RegisterAsmPrinter {
+    RegisterAsmPrinter(Target &T) {
+      TargetRegistry::RegisterAsmPrinter(T, &Allocator);
+    }
+
+  private:
+    static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
+      return new AsmPrinterImpl(TM, Streamer);
+    }
+  };
+
   /// RegisterCodeEmitter - Helper template for registering a target specific
   /// machine code emitter, for use in the target initialization
   /// function. Usage:
@@ -559,8 +661,9 @@ namespace llvm {
     }
 
   private:
-    static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM) {
-      return new CodeEmitterImpl(T, TM);
+    static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
+                                    MCContext &Ctx) {
+      return new CodeEmitterImpl(T, TM, Ctx);
     }
   };