convert a bunch of std::strings to use StringRef. This should eliminate
[oota-llvm.git] / include / llvm / Target / TargetRegistry.h
index bfb23ef930f7364e1dbc984fb715ff1539575741..8042d2363677b415f08706d08304809ebb59cee9 100644 (file)
 #include <cassert>
 
 namespace llvm {
-  class FunctionPass;
+  class AsmPrinter;
   class MCAsmParser;
+  class MCCodeEmitter;
   class Module;
-  class TargetAsmInfo;
+  class MCAsmInfo;
+  class MCDisassembler;
+  class MCInstPrinter;
   class TargetAsmParser;
   class TargetMachine;
   class formatted_raw_ostream;
+  class raw_ostream;
 
   /// Target - Wrapper for Target specific information.
   ///
@@ -46,17 +50,25 @@ namespace llvm {
 
     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
 
-    typedef const TargetAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
-                                                    const StringRef &TT);
+    typedef const MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
+                                                const StringRef &TT);
     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
                                                   const std::string &TT,
                                                   const std::string &Features);
-    typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &OS,
-                                              TargetMachine &TM,
-                                              const TargetAsmInfo *TAI,
-                                              bool VerboseAsm);
+    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 MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
+                                                  unsigned SyntaxVariant,
+                                                  const MCAsmInfo &MAI,
+                                                  raw_ostream &O);
+    typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
+                                                TargetMachine &TM);
+
   private:
     /// Next - The next registered target in the linked list, maintained by the
     /// TargetRegistry.
@@ -88,8 +100,24 @@ namespace llvm {
     /// 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 
+    /// MCInstPrinter, if registered.
+    MCInstPrinterCtorTy MCInstPrinterCtorFn;
+    
+    /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
+    /// if registered.
+    CodeEmitterCtorTy CodeEmitterCtorFn;
 
   public:
+    /// @name Target Information
+    /// @{
+
     // getNext - Return the next registered target.
     const Target *getNext() const { return Next; }
 
@@ -99,6 +127,11 @@ namespace llvm {
     /// getShortDescription - Get a short description of the target.
     const char *getShortDescription() const { return ShortDesc; }
 
+    /// @}
+    /// @name Feature Predicates
+    /// @{
+
+    /// hasJIT - Check if this targets supports the just-in-time compilation.
     bool hasJIT() const { return HasJIT; }
 
     /// hasTargetMachine - Check if this target supports code generation.
@@ -109,16 +142,28 @@ namespace llvm {
 
     /// hasAsmParser - Check if this target supports .s parsing.
     bool hasAsmParser() const { return AsmParserCtorFn != 0; }
+    
+    /// hasMCDisassembler - Check if this target has a disassembler.
+    bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
 
+    /// hasMCInstPrinter - Check if this target has an instruction printer.
+    bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
+
+    /// hasCodeEmitter - Check if this target supports instruction encoding.
+    bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
+
+    /// @}
+    /// @name Feature Constructors
+    /// @{
     
-    /// createAsmInfo - Create a TargetAsmInfo implementation for the specified
+    /// createAsmInfo - Create a MCAsmInfo implementation for the specified
     /// target triple.
     ///
     /// \arg Triple - This argument is used to determine the target machine
     /// 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 TargetAsmInfo *createAsmInfo(const StringRef &Triple) const {
+    const MCAsmInfo *createAsmInfo(const StringRef &Triple) const {
       if (!AsmInfoCtorFn)
         return 0;
       return AsmInfoCtorFn(*this, Triple);
@@ -139,13 +184,11 @@ namespace llvm {
     }
 
     /// createAsmPrinter - Create a target specific assembly printer pass.
-    FunctionPass *createAsmPrinter(formatted_raw_ostream &OS,
-                                   TargetMachine &TM,
-                                   const TargetAsmInfo *TAI,
-                                   bool Verbose) const {
+    AsmPrinter *createAsmPrinter(formatted_raw_ostream &OS, TargetMachine &TM,
+                                 const MCAsmInfo *MAI, bool Verbose) const {
       if (!AsmPrinterCtorFn)
         return 0;
-      return AsmPrinterCtorFn(OS, TM, TAI, Verbose);
+      return AsmPrinterCtorFn(OS, TM, MAI, Verbose);
     }
 
     /// createAsmParser - Create a target specific assembly parser.
@@ -157,6 +200,30 @@ namespace llvm {
         return 0;
       return AsmParserCtorFn(*this, Parser);
     }
+    
+    const MCDisassembler *createMCDisassembler() const {
+      if (!MCDisassemblerCtorFn)
+        return 0;
+      return MCDisassemblerCtorFn(*this);
+    }
+
+    MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
+                                       const MCAsmInfo &MAI,
+                                       raw_ostream &O) const {
+      if (!MCInstPrinterCtorFn)
+        return 0;
+      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
+    }
+    
+    
+    /// createCodeEmitter - Create a target specific code emitter.
+    MCCodeEmitter *createCodeEmitter(TargetMachine &TM) const {
+      if (!CodeEmitterCtorFn)
+        return 0;
+      return CodeEmitterCtorFn(*this, TM);
+    }
+
+    /// @}
   };
 
   /// TargetRegistry - Generic interface to target specific features.
@@ -245,7 +312,7 @@ namespace llvm {
                                Target::TripleMatchQualityFnTy TQualityFn,
                                bool HasJIT = false);
 
-    /// RegisterAsmInfo - Register a TargetAsmInfo implementation for the
+    /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
     /// given target.
     /// 
     /// Clients are responsible for ensuring that registration doesn't occur
@@ -253,7 +320,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 a TargetAsmInfo for the target.
+    /// @param Fn - A function to construct a MCAsmInfo for the target.
     static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
       // Ignore duplicate registration.
       if (!T.AsmInfoCtorFn)
@@ -304,6 +371,41 @@ namespace llvm {
       if (!T.AsmParserCtorFn)
         T.AsmParserCtorFn = 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, 
+                                       Target::MCDisassemblerCtorTy Fn) {
+      if (!T.MCDisassemblerCtorFn)
+        T.MCDisassemblerCtorFn = Fn;
+    }
+
+    static void RegisterMCInstPrinter(Target &T,
+                                      Target::MCInstPrinterCtorTy Fn) {
+      if (!T.MCInstPrinterCtorFn)
+        T.MCInstPrinterCtorFn = Fn;
+    }
+    
+    /// RegisterCodeEmitter - Register a MCCodeEmitter 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 RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
+      if (!T.CodeEmitterCtorFn)
+        T.CodeEmitterCtorFn = Fn;
+    }
 
     /// @}
   };
@@ -330,7 +432,7 @@ namespace llvm {
     }
 
     static unsigned getTripleMatchQuality(const std::string &TT) {
-      if (Triple(TT.c_str()).getArch() == TargetArchType)
+      if (Triple(TT).getArch() == TargetArchType)
         return 20;
       return 0;
     }
@@ -342,16 +444,16 @@ namespace llvm {
   ///
   /// extern "C" void LLVMInitializeFooTarget() {
   ///   extern Target TheFooTarget;
-  ///   RegisterAsmInfo<FooTargetAsmInfo> X(TheFooTarget);
+  ///   RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
   /// }
-  template<class TargetAsmInfoImpl>
+  template<class MCAsmInfoImpl>
   struct RegisterAsmInfo {
     RegisterAsmInfo(Target &T) {
       TargetRegistry::RegisterAsmInfo(T, &Allocator);
     }
   private:
-    static const TargetAsmInfo *Allocator(const Target &T, const StringRef &TT){
-      return new TargetAsmInfoImpl(T, TT);
+    static const MCAsmInfo *Allocator(const Target &T, const StringRef &TT) {
+      return new MCAsmInfoImpl(T, TT);
     }
     
   };
@@ -407,11 +509,9 @@ namespace llvm {
     }
 
   private:
-    static FunctionPass *Allocator(formatted_raw_ostream &OS,
-                                   TargetMachine &TM,
-                                   const TargetAsmInfo *TAI,
-                                   bool Verbose) {
-      return new AsmPrinterImpl(OS, TM, TAI, Verbose);
+    static AsmPrinter *Allocator(formatted_raw_ostream &OS, TargetMachine &TM,
+                                 const MCAsmInfo *MAI, bool Verbose) {
+      return new AsmPrinterImpl(OS, TM, MAI, Verbose);
     }
   };
 
@@ -435,6 +535,26 @@ namespace llvm {
     }
   };
 
+  /// RegisterCodeEmitter - Helper template for registering a target specific
+  /// machine code emitter, for use in the target initialization
+  /// function. Usage:
+  ///
+  /// extern "C" void LLVMInitializeFooCodeEmitter() {
+  ///   extern Target TheFooTarget;
+  ///   RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
+  /// }
+  template<class CodeEmitterImpl>
+  struct RegisterCodeEmitter {
+    RegisterCodeEmitter(Target &T) {
+      TargetRegistry::RegisterCodeEmitter(T, &Allocator);
+    }
+
+  private:
+    static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM) {
+      return new CodeEmitterImpl(T, TM);
+    }
+  };
+
 }
 
 #endif