LLVM API Documentation

TargetRegistry.h
Go to the documentation of this file.
00001 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file exposes the TargetRegistry interface, which tools can use to access
00011 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
00012 // which have been registered.
00013 //
00014 // Target specific class implementations should register themselves using the
00015 // appropriate TargetRegistry interfaces.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
00020 #define LLVM_SUPPORT_TARGETREGISTRY_H
00021 
00022 #include "llvm-c/Disassembler.h"
00023 #include "llvm/ADT/Triple.h"
00024 #include "llvm/Support/CodeGen.h"
00025 #include <cassert>
00026 #include <string>
00027 
00028 namespace llvm {
00029   class AsmPrinter;
00030   class Module;
00031   class MCAssembler;
00032   class MCAsmBackend;
00033   class MCAsmInfo;
00034   class MCAsmParser;
00035   class MCCodeEmitter;
00036   class MCCodeGenInfo;
00037   class MCContext;
00038   class MCDisassembler;
00039   class MCInstrAnalysis;
00040   class MCInstPrinter;
00041   class MCInstrInfo;
00042   class MCRegisterInfo;
00043   class MCStreamer;
00044   class MCSubtargetInfo;
00045   class MCSymbolizer;
00046   class MCRelocationInfo;
00047   class MCTargetAsmParser;
00048   class MCTargetOptions;
00049   class TargetMachine;
00050   class TargetOptions;
00051   class raw_ostream;
00052   class formatted_raw_ostream;
00053 
00054   MCStreamer *createNullStreamer(MCContext &Ctx);
00055   MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
00056                                 bool isVerboseAsm, bool useDwarfDirectory,
00057                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00058                                 MCAsmBackend *TAB, bool ShowInst);
00059 
00060   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
00061 
00062   MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
00063                                    LLVMSymbolLookupCallback SymbolLookUp,
00064                                    void *DisInfo,
00065                                    MCContext *Ctx,
00066                                    MCRelocationInfo *RelInfo);
00067 
00068   /// Target - Wrapper for Target specific information.
00069   ///
00070   /// For registration purposes, this is a POD type so that targets can be
00071   /// registered without the use of static constructors.
00072   ///
00073   /// Targets should implement a single global instance of this class (which
00074   /// will be zero initialized), and pass that instance to the TargetRegistry as
00075   /// part of their initialization.
00076   class Target {
00077   public:
00078     friend struct TargetRegistry;
00079 
00080     typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
00081 
00082     typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
00083                                             StringRef TT);
00084     typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
00085                                                     Reloc::Model RM,
00086                                                     CodeModel::Model CM,
00087                                                     CodeGenOpt::Level OL);
00088     typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
00089     typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
00090     typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
00091     typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
00092                                                         StringRef CPU,
00093                                                         StringRef Features);
00094     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
00095                                                   StringRef TT,
00096                                                   StringRef CPU,
00097                                                   StringRef Features,
00098                                                   const TargetOptions &Options,
00099                                                   Reloc::Model RM,
00100                                                   CodeModel::Model CM,
00101                                                   CodeGenOpt::Level OL);
00102     typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
00103                                             MCStreamer &Streamer);
00104     typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
00105                                                 const MCRegisterInfo &MRI,
00106                                                 StringRef TT,
00107                                                 StringRef CPU);
00108     typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
00109         MCSubtargetInfo &STI,
00110         MCAsmParser &P,
00111         const MCInstrInfo &MII,
00112         const MCTargetOptions &Options);
00113     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
00114                                                     const MCSubtargetInfo &STI,
00115                                                     MCContext &Ctx);
00116     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
00117                                                   unsigned SyntaxVariant,
00118                                                   const MCAsmInfo &MAI,
00119                                                   const MCInstrInfo &MII,
00120                                                   const MCRegisterInfo &MRI,
00121                                                   const MCSubtargetInfo &STI);
00122     typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
00123                                                   const MCRegisterInfo &MRI,
00124                                                   const MCSubtargetInfo &STI,
00125                                                   MCContext &Ctx);
00126     typedef MCStreamer *(*MCObjectStreamerCtorTy)(
00127         const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB,
00128         raw_ostream &_OS, MCCodeEmitter *_Emitter, const MCSubtargetInfo &STI,
00129         bool RelaxAll);
00130     typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
00131                                              formatted_raw_ostream &OS,
00132                                              bool isVerboseAsm,
00133                                              bool useDwarfDirectory,
00134                                              MCInstPrinter *InstPrint,
00135                                              MCCodeEmitter *CE,
00136                                              MCAsmBackend *TAB,
00137                                              bool ShowInst);
00138     typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);
00139     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
00140                                                         MCContext &Ctx);
00141     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
00142                                    LLVMOpInfoCallback GetOpInfo,
00143                                    LLVMSymbolLookupCallback SymbolLookUp,
00144                                    void *DisInfo,
00145                                    MCContext *Ctx,
00146                                    MCRelocationInfo *RelInfo);
00147 
00148   private:
00149     /// Next - The next registered target in the linked list, maintained by the
00150     /// TargetRegistry.
00151     Target *Next;
00152 
00153     /// The target function for checking if an architecture is supported.
00154     ArchMatchFnTy ArchMatchFn;
00155 
00156     /// Name - The target name.
00157     const char *Name;
00158 
00159     /// ShortDesc - A short description of the target.
00160     const char *ShortDesc;
00161 
00162     /// HasJIT - Whether this target supports the JIT.
00163     bool HasJIT;
00164 
00165     /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
00166     /// registered.
00167     MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
00168 
00169     /// MCCodeGenInfoCtorFn - Constructor function for this target's
00170     /// MCCodeGenInfo, if registered.
00171     MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
00172 
00173     /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
00174     /// if registered.
00175     MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
00176 
00177     /// MCInstrAnalysisCtorFn - Constructor function for this target's
00178     /// MCInstrAnalysis, if registered.
00179     MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
00180 
00181     /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
00182     /// if registered.
00183     MCRegInfoCtorFnTy MCRegInfoCtorFn;
00184 
00185     /// MCSubtargetInfoCtorFn - Constructor function for this target's
00186     /// MCSubtargetInfo, if registered.
00187     MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
00188 
00189     /// TargetMachineCtorFn - Construction function for this target's
00190     /// TargetMachine, if registered.
00191     TargetMachineCtorTy TargetMachineCtorFn;
00192 
00193     /// MCAsmBackendCtorFn - Construction function for this target's
00194     /// MCAsmBackend, if registered.
00195     MCAsmBackendCtorTy MCAsmBackendCtorFn;
00196 
00197     /// MCAsmParserCtorFn - Construction function for this target's
00198     /// MCTargetAsmParser, if registered.
00199     MCAsmParserCtorTy MCAsmParserCtorFn;
00200 
00201     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
00202     /// if registered.
00203     AsmPrinterCtorTy AsmPrinterCtorFn;
00204 
00205     /// MCDisassemblerCtorFn - Construction function for this target's
00206     /// MCDisassembler, if registered.
00207     MCDisassemblerCtorTy MCDisassemblerCtorFn;
00208 
00209     /// MCInstPrinterCtorFn - Construction function for this target's
00210     /// MCInstPrinter, if registered.
00211     MCInstPrinterCtorTy MCInstPrinterCtorFn;
00212 
00213     /// MCCodeEmitterCtorFn - Construction function for this target's
00214     /// CodeEmitter, if registered.
00215     MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
00216 
00217     /// MCObjectStreamerCtorFn - Construction function for this target's
00218     /// MCObjectStreamer, if registered.
00219     MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
00220 
00221     /// AsmStreamerCtorFn - Construction function for this target's
00222     /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
00223     AsmStreamerCtorTy AsmStreamerCtorFn;
00224 
00225     /// Construction function for this target's NullStreamer, if registered
00226     /// (default = llvm::createNullStreamer).
00227     NullStreamerCtorTy NullStreamerCtorFn;
00228 
00229     /// MCRelocationInfoCtorFn - Construction function for this target's
00230     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
00231     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
00232 
00233     /// MCSymbolizerCtorFn - Construction function for this target's
00234     /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
00235     MCSymbolizerCtorTy MCSymbolizerCtorFn;
00236 
00237   public:
00238     Target()
00239         : AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr),
00240           MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
00241 
00242     /// @name Target Information
00243     /// @{
00244 
00245     // getNext - Return the next registered target.
00246     const Target *getNext() const { return Next; }
00247 
00248     /// getName - Get the target name.
00249     const char *getName() const { return Name; }
00250 
00251     /// getShortDescription - Get a short description of the target.
00252     const char *getShortDescription() const { return ShortDesc; }
00253 
00254     /// @}
00255     /// @name Feature Predicates
00256     /// @{
00257 
00258     /// hasJIT - Check if this targets supports the just-in-time compilation.
00259     bool hasJIT() const { return HasJIT; }
00260 
00261     /// hasTargetMachine - Check if this target supports code generation.
00262     bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
00263 
00264     /// hasMCAsmBackend - Check if this target supports .o generation.
00265     bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
00266 
00267     /// @}
00268     /// @name Feature Constructors
00269     /// @{
00270 
00271     /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
00272     /// target triple.
00273     ///
00274     /// \param Triple This argument is used to determine the target machine
00275     /// feature set; it should always be provided. Generally this should be
00276     /// either the target triple from the module, or the target triple of the
00277     /// host if that does not exist.
00278     MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
00279                                StringRef Triple) const {
00280       if (!MCAsmInfoCtorFn)
00281         return nullptr;
00282       return MCAsmInfoCtorFn(MRI, Triple);
00283     }
00284 
00285     /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
00286     ///
00287     MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
00288                                        CodeModel::Model CM,
00289                                        CodeGenOpt::Level OL) const {
00290       if (!MCCodeGenInfoCtorFn)
00291         return nullptr;
00292       return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
00293     }
00294 
00295     /// createMCInstrInfo - Create a MCInstrInfo implementation.
00296     ///
00297     MCInstrInfo *createMCInstrInfo() const {
00298       if (!MCInstrInfoCtorFn)
00299         return nullptr;
00300       return MCInstrInfoCtorFn();
00301     }
00302 
00303     /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
00304     ///
00305     MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
00306       if (!MCInstrAnalysisCtorFn)
00307         return nullptr;
00308       return MCInstrAnalysisCtorFn(Info);
00309     }
00310 
00311     /// createMCRegInfo - Create a MCRegisterInfo implementation.
00312     ///
00313     MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
00314       if (!MCRegInfoCtorFn)
00315         return nullptr;
00316       return MCRegInfoCtorFn(Triple);
00317     }
00318 
00319     /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
00320     ///
00321     /// \param Triple This argument is used to determine the target machine
00322     /// feature set; it should always be provided. Generally this should be
00323     /// either the target triple from the module, or the target triple of the
00324     /// host if that does not exist.
00325     /// \param CPU This specifies the name of the target CPU.
00326     /// \param Features This specifies the string representation of the
00327     /// additional target features.
00328     MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
00329                                            StringRef Features) const {
00330       if (!MCSubtargetInfoCtorFn)
00331         return nullptr;
00332       return MCSubtargetInfoCtorFn(Triple, CPU, Features);
00333     }
00334 
00335     /// createTargetMachine - Create a target specific machine implementation
00336     /// for the specified \p Triple.
00337     ///
00338     /// \param Triple This argument is used to determine the target machine
00339     /// feature set; it should always be provided. Generally this should be
00340     /// either the target triple from the module, or the target triple of the
00341     /// host if that does not exist.
00342     TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
00343                              StringRef Features, const TargetOptions &Options,
00344                              Reloc::Model RM = Reloc::Default,
00345                              CodeModel::Model CM = CodeModel::Default,
00346                              CodeGenOpt::Level OL = CodeGenOpt::Default) const {
00347       if (!TargetMachineCtorFn)
00348         return nullptr;
00349       return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
00350                                  RM, CM, OL);
00351     }
00352 
00353     /// createMCAsmBackend - Create a target specific assembly parser.
00354     ///
00355     /// \param Triple The target triple string.
00356     MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
00357                                      StringRef Triple, StringRef CPU) const {
00358       if (!MCAsmBackendCtorFn)
00359         return nullptr;
00360       return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
00361     }
00362 
00363     /// createMCAsmParser - Create a target specific assembly parser.
00364     ///
00365     /// \param Parser The target independent parser implementation to use for
00366     /// parsing and lexing.
00367     MCTargetAsmParser *createMCAsmParser(
00368         MCSubtargetInfo &STI,
00369         MCAsmParser &Parser,
00370         const MCInstrInfo &MII,
00371         const MCTargetOptions &Options) const {
00372       if (!MCAsmParserCtorFn)
00373         return nullptr;
00374       return MCAsmParserCtorFn(STI, Parser, MII, Options);
00375     }
00376 
00377     /// createAsmPrinter - Create a target specific assembly printer pass.  This
00378     /// takes ownership of the MCStreamer object.
00379     AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
00380       if (!AsmPrinterCtorFn)
00381         return nullptr;
00382       return AsmPrinterCtorFn(TM, Streamer);
00383     }
00384 
00385     MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
00386                                          MCContext &Ctx) const {
00387       if (!MCDisassemblerCtorFn)
00388         return nullptr;
00389       return MCDisassemblerCtorFn(*this, STI, Ctx);
00390     }
00391 
00392     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
00393                                        const MCAsmInfo &MAI,
00394                                        const MCInstrInfo &MII,
00395                                        const MCRegisterInfo &MRI,
00396                                        const MCSubtargetInfo &STI) const {
00397       if (!MCInstPrinterCtorFn)
00398         return nullptr;
00399       return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
00400     }
00401 
00402 
00403     /// createMCCodeEmitter - Create a target specific code emitter.
00404     MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
00405                                        const MCRegisterInfo &MRI,
00406                                        const MCSubtargetInfo &STI,
00407                                        MCContext &Ctx) const {
00408       if (!MCCodeEmitterCtorFn)
00409         return nullptr;
00410       return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
00411     }
00412 
00413     /// createMCObjectStreamer - Create a target specific MCStreamer.
00414     ///
00415     /// \param TT The target triple.
00416     /// \param Ctx The target context.
00417     /// \param TAB The target assembler backend object. Takes ownership.
00418     /// \param _OS The stream object.
00419     /// \param _Emitter The target independent assembler object.Takes ownership.
00420     /// \param RelaxAll Relax all fixups?
00421     MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
00422                                        MCAsmBackend &TAB, raw_ostream &_OS,
00423                                        MCCodeEmitter *_Emitter,
00424                                        const MCSubtargetInfo &STI,
00425                                        bool RelaxAll) const {
00426       if (!MCObjectStreamerCtorFn)
00427         return nullptr;
00428       return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
00429                                     RelaxAll);
00430     }
00431 
00432     /// createAsmStreamer - Create a target specific MCStreamer.
00433     MCStreamer *createAsmStreamer(MCContext &Ctx,
00434                                   formatted_raw_ostream &OS,
00435                                   bool isVerboseAsm,
00436                                   bool useDwarfDirectory,
00437                                   MCInstPrinter *InstPrint,
00438                                   MCCodeEmitter *CE,
00439                                   MCAsmBackend *TAB,
00440                                   bool ShowInst) const {
00441       if (AsmStreamerCtorFn)
00442         return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
00443                                  InstPrint, CE, TAB, ShowInst);
00444       return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
00445                                      InstPrint, CE, TAB, ShowInst);
00446     }
00447 
00448     MCStreamer *createNullStreamer(MCContext &Ctx) const {
00449       if (NullStreamerCtorFn)
00450         return NullStreamerCtorFn(Ctx);
00451       return llvm::createNullStreamer(Ctx);
00452     }
00453 
00454     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
00455     ///
00456     /// \param TT The target triple.
00457     /// \param Ctx The target context.
00458     MCRelocationInfo *
00459       createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
00460       MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
00461                                       ? MCRelocationInfoCtorFn
00462                                       : llvm::createMCRelocationInfo;
00463       return Fn(TT, Ctx);
00464     }
00465 
00466     /// createMCSymbolizer - Create a target specific MCSymbolizer.
00467     ///
00468     /// \param TT The target triple.
00469     /// \param GetOpInfo The function to get the symbolic information for operands.
00470     /// \param SymbolLookUp The function to lookup a symbol name.
00471     /// \param DisInfo The pointer to the block of symbolic information for above call
00472     /// back.
00473     /// \param Ctx The target context.
00474     /// \param RelInfo The relocation information for this target. Takes ownership.
00475     MCSymbolizer *
00476     createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
00477                        LLVMSymbolLookupCallback SymbolLookUp,
00478                        void *DisInfo,
00479                        MCContext *Ctx, MCRelocationInfo *RelInfo) const {
00480       MCSymbolizerCtorTy Fn =
00481           MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
00482       return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
00483     }
00484 
00485     /// @}
00486   };
00487 
00488   /// TargetRegistry - Generic interface to target specific features.
00489   struct TargetRegistry {
00490     class iterator {
00491       const Target *Current;
00492       explicit iterator(Target *T) : Current(T) {}
00493       friend struct TargetRegistry;
00494     public:
00495       iterator() : Current(nullptr) {}
00496 
00497       bool operator==(const iterator &x) const {
00498         return Current == x.Current;
00499       }
00500       bool operator!=(const iterator &x) const {
00501         return !operator==(x);
00502       }
00503 
00504       // Iterator traversal: forward iteration only
00505       iterator &operator++() {          // Preincrement
00506         assert(Current && "Cannot increment end iterator!");
00507         Current = Current->getNext();
00508         return *this;
00509       }
00510       iterator operator++(int) {        // Postincrement
00511         iterator tmp = *this;
00512         ++*this;
00513         return tmp;
00514       }
00515 
00516       const Target &operator*() const {
00517         assert(Current && "Cannot dereference end iterator!");
00518         return *Current;
00519       }
00520 
00521       const Target *operator->() const {
00522         return &operator*();
00523       }
00524     };
00525 
00526     /// printRegisteredTargetsForVersion - Print the registered targets
00527     /// appropriately for inclusion in a tool's version output.
00528     static void printRegisteredTargetsForVersion();
00529 
00530     /// @name Registry Access
00531     /// @{
00532 
00533     static iterator begin();
00534 
00535     static iterator end() { return iterator(); }
00536 
00537     /// lookupTarget - Lookup a target based on a target triple.
00538     ///
00539     /// \param Triple - The triple to use for finding a target.
00540     /// \param Error - On failure, an error string describing why no target was
00541     /// found.
00542     static const Target *lookupTarget(const std::string &Triple,
00543                                       std::string &Error);
00544 
00545     /// lookupTarget - Lookup a target based on an architecture name
00546     /// and a target triple.  If the architecture name is non-empty,
00547     /// then the lookup is done by architecture.  Otherwise, the target
00548     /// triple is used.
00549     ///
00550     /// \param ArchName - The architecture to use for finding a target.
00551     /// \param TheTriple - The triple to use for finding a target.  The
00552     /// triple is updated with canonical architecture name if a lookup
00553     /// by architecture is done.
00554     /// \param Error - On failure, an error string describing why no target was
00555     /// found.
00556     static const Target *lookupTarget(const std::string &ArchName,
00557                                       Triple &TheTriple,
00558                                       std::string &Error);
00559 
00560     /// @}
00561     /// @name Target Registration
00562     /// @{
00563 
00564     /// RegisterTarget - Register the given target. Attempts to register a
00565     /// target which has already been registered will be ignored.
00566     ///
00567     /// Clients are responsible for ensuring that registration doesn't occur
00568     /// while another thread is attempting to access the registry. Typically
00569     /// this is done by initializing all targets at program startup.
00570     ///
00571     /// @param T - The target being registered.
00572     /// @param Name - The target name. This should be a static string.
00573     /// @param ShortDesc - A short target description. This should be a static
00574     /// string.
00575     /// @param ArchMatchFn - The arch match checking function for this target.
00576     /// @param HasJIT - Whether the target supports JIT code
00577     /// generation.
00578     static void RegisterTarget(Target &T,
00579                                const char *Name,
00580                                const char *ShortDesc,
00581                                Target::ArchMatchFnTy ArchMatchFn,
00582                                bool HasJIT = false);
00583 
00584     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
00585     /// given target.
00586     ///
00587     /// Clients are responsible for ensuring that registration doesn't occur
00588     /// while another thread is attempting to access the registry. Typically
00589     /// this is done by initializing all targets at program startup.
00590     ///
00591     /// @param T - The target being registered.
00592     /// @param Fn - A function to construct a MCAsmInfo for the target.
00593     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00594       T.MCAsmInfoCtorFn = Fn;
00595     }
00596 
00597     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
00598     /// given target.
00599     ///
00600     /// Clients are responsible for ensuring that registration doesn't occur
00601     /// while another thread is attempting to access the registry. Typically
00602     /// this is done by initializing all targets at program startup.
00603     ///
00604     /// @param T - The target being registered.
00605     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
00606     static void RegisterMCCodeGenInfo(Target &T,
00607                                      Target::MCCodeGenInfoCtorFnTy Fn) {
00608       T.MCCodeGenInfoCtorFn = Fn;
00609     }
00610 
00611     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
00612     /// given target.
00613     ///
00614     /// Clients are responsible for ensuring that registration doesn't occur
00615     /// while another thread is attempting to access the registry. Typically
00616     /// this is done by initializing all targets at program startup.
00617     ///
00618     /// @param T - The target being registered.
00619     /// @param Fn - A function to construct a MCInstrInfo for the target.
00620     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00621       T.MCInstrInfoCtorFn = Fn;
00622     }
00623 
00624     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
00625     /// the given target.
00626     static void RegisterMCInstrAnalysis(Target &T,
00627                                         Target::MCInstrAnalysisCtorFnTy Fn) {
00628       T.MCInstrAnalysisCtorFn = Fn;
00629     }
00630 
00631     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
00632     /// given target.
00633     ///
00634     /// Clients are responsible for ensuring that registration doesn't occur
00635     /// while another thread is attempting to access the registry. Typically
00636     /// this is done by initializing all targets at program startup.
00637     ///
00638     /// @param T - The target being registered.
00639     /// @param Fn - A function to construct a MCRegisterInfo for the target.
00640     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
00641       T.MCRegInfoCtorFn = Fn;
00642     }
00643 
00644     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
00645     /// the given target.
00646     ///
00647     /// Clients are responsible for ensuring that registration doesn't occur
00648     /// while another thread is attempting to access the registry. Typically
00649     /// this is done by initializing all targets at program startup.
00650     ///
00651     /// @param T - The target being registered.
00652     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
00653     static void RegisterMCSubtargetInfo(Target &T,
00654                                         Target::MCSubtargetInfoCtorFnTy Fn) {
00655       T.MCSubtargetInfoCtorFn = Fn;
00656     }
00657 
00658     /// RegisterTargetMachine - Register a TargetMachine implementation for the
00659     /// given target.
00660     ///
00661     /// Clients are responsible for ensuring that registration doesn't occur
00662     /// while another thread is attempting to access the registry. Typically
00663     /// this is done by initializing all targets at program startup.
00664     ///
00665     /// @param T - The target being registered.
00666     /// @param Fn - A function to construct a TargetMachine for the target.
00667     static void RegisterTargetMachine(Target &T,
00668                                       Target::TargetMachineCtorTy Fn) {
00669       T.TargetMachineCtorFn = Fn;
00670     }
00671 
00672     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
00673     /// given target.
00674     ///
00675     /// Clients are responsible for ensuring that registration doesn't occur
00676     /// while another thread is attempting to access the registry. Typically
00677     /// this is done by initializing all targets at program startup.
00678     ///
00679     /// @param T - The target being registered.
00680     /// @param Fn - A function to construct an AsmBackend for the target.
00681     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
00682       T.MCAsmBackendCtorFn = Fn;
00683     }
00684 
00685     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
00686     /// the given target.
00687     ///
00688     /// Clients are responsible for ensuring that registration doesn't occur
00689     /// while another thread is attempting to access the registry. Typically
00690     /// this is done by initializing all targets at program startup.
00691     ///
00692     /// @param T - The target being registered.
00693     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
00694     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
00695       T.MCAsmParserCtorFn = Fn;
00696     }
00697 
00698     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
00699     /// target.
00700     ///
00701     /// Clients are responsible for ensuring that registration doesn't occur
00702     /// while another thread is attempting to access the registry. Typically
00703     /// this is done by initializing all targets at program startup.
00704     ///
00705     /// @param T - The target being registered.
00706     /// @param Fn - A function to construct an AsmPrinter for the target.
00707     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
00708       T.AsmPrinterCtorFn = Fn;
00709     }
00710 
00711     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
00712     /// the given target.
00713     ///
00714     /// Clients are responsible for ensuring that registration doesn't occur
00715     /// while another thread is attempting to access the registry. Typically
00716     /// this is done by initializing all targets at program startup.
00717     ///
00718     /// @param T - The target being registered.
00719     /// @param Fn - A function to construct an MCDisassembler for the target.
00720     static void RegisterMCDisassembler(Target &T,
00721                                        Target::MCDisassemblerCtorTy Fn) {
00722       T.MCDisassemblerCtorFn = Fn;
00723     }
00724 
00725     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
00726     /// given target.
00727     ///
00728     /// Clients are responsible for ensuring that registration doesn't occur
00729     /// while another thread is attempting to access the registry. Typically
00730     /// this is done by initializing all targets at program startup.
00731     ///
00732     /// @param T - The target being registered.
00733     /// @param Fn - A function to construct an MCInstPrinter for the target.
00734     static void RegisterMCInstPrinter(Target &T,
00735                                       Target::MCInstPrinterCtorTy Fn) {
00736       T.MCInstPrinterCtorFn = Fn;
00737     }
00738 
00739     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
00740     /// given target.
00741     ///
00742     /// Clients are responsible for ensuring that registration doesn't occur
00743     /// while another thread is attempting to access the registry. Typically
00744     /// this is done by initializing all targets at program startup.
00745     ///
00746     /// @param T - The target being registered.
00747     /// @param Fn - A function to construct an MCCodeEmitter for the target.
00748     static void RegisterMCCodeEmitter(Target &T,
00749                                       Target::MCCodeEmitterCtorTy Fn) {
00750       T.MCCodeEmitterCtorFn = Fn;
00751     }
00752 
00753     /// RegisterMCObjectStreamer - Register a object code MCStreamer
00754     /// implementation for the given target.
00755     ///
00756     /// Clients are responsible for ensuring that registration doesn't occur
00757     /// while another thread is attempting to access the registry. Typically
00758     /// this is done by initializing all targets at program startup.
00759     ///
00760     /// @param T - The target being registered.
00761     /// @param Fn - A function to construct an MCStreamer for the target.
00762     static void RegisterMCObjectStreamer(Target &T,
00763                                          Target::MCObjectStreamerCtorTy Fn) {
00764       T.MCObjectStreamerCtorFn = Fn;
00765     }
00766 
00767     /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
00768     /// for the given target.
00769     ///
00770     /// Clients are responsible for ensuring that registration doesn't occur
00771     /// while another thread is attempting to access the registry. Typically
00772     /// this is done by initializing all targets at program startup.
00773     ///
00774     /// @param T - The target being registered.
00775     /// @param Fn - A function to construct an MCStreamer for the target.
00776     static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
00777       T.AsmStreamerCtorFn = Fn;
00778     }
00779 
00780     static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
00781       T.NullStreamerCtorFn = Fn;
00782     }
00783 
00784     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
00785     /// implementation for the given target.
00786     ///
00787     /// Clients are responsible for ensuring that registration doesn't occur
00788     /// while another thread is attempting to access the registry. Typically
00789     /// this is done by initializing all targets at program startup.
00790     ///
00791     /// @param T - The target being registered.
00792     /// @param Fn - A function to construct an MCRelocationInfo for the target.
00793     static void RegisterMCRelocationInfo(Target &T,
00794                                          Target::MCRelocationInfoCtorTy Fn) {
00795       T.MCRelocationInfoCtorFn = Fn;
00796     }
00797 
00798     /// RegisterMCSymbolizer - Register an MCSymbolizer
00799     /// implementation for the given target.
00800     ///
00801     /// Clients are responsible for ensuring that registration doesn't occur
00802     /// while another thread is attempting to access the registry. Typically
00803     /// this is done by initializing all targets at program startup.
00804     ///
00805     /// @param T - The target being registered.
00806     /// @param Fn - A function to construct an MCSymbolizer for the target.
00807     static void RegisterMCSymbolizer(Target &T,
00808                                      Target::MCSymbolizerCtorTy Fn) {
00809       T.MCSymbolizerCtorFn = Fn;
00810     }
00811 
00812     /// @}
00813   };
00814 
00815 
00816   //===--------------------------------------------------------------------===//
00817 
00818   /// RegisterTarget - Helper template for registering a target, for use in the
00819   /// target's initialization function. Usage:
00820   ///
00821   ///
00822   /// Target TheFooTarget; // The global target instance.
00823   ///
00824   /// extern "C" void LLVMInitializeFooTargetInfo() {
00825   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
00826   /// }
00827   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
00828            bool HasJIT = false>
00829   struct RegisterTarget {
00830     RegisterTarget(Target &T, const char *Name, const char *Desc) {
00831       TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
00832     }
00833 
00834     static bool getArchMatch(Triple::ArchType Arch) {
00835       return Arch == TargetArchType;
00836     }
00837   };
00838 
00839   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
00840   /// implementation.  This invokes the static "Create" method on the class to
00841   /// actually do the construction.  Usage:
00842   ///
00843   /// extern "C" void LLVMInitializeFooTarget() {
00844   ///   extern Target TheFooTarget;
00845   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
00846   /// }
00847   template<class MCAsmInfoImpl>
00848   struct RegisterMCAsmInfo {
00849     RegisterMCAsmInfo(Target &T) {
00850       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
00851     }
00852   private:
00853     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
00854       return new MCAsmInfoImpl(TT);
00855     }
00856 
00857   };
00858 
00859   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
00860   /// implementation.  This invokes the specified function to do the
00861   /// construction.  Usage:
00862   ///
00863   /// extern "C" void LLVMInitializeFooTarget() {
00864   ///   extern Target TheFooTarget;
00865   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
00866   /// }
00867   struct RegisterMCAsmInfoFn {
00868     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00869       TargetRegistry::RegisterMCAsmInfo(T, Fn);
00870     }
00871   };
00872 
00873   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
00874   /// implementation.  This invokes the static "Create" method on the class
00875   /// to actually do the construction.  Usage:
00876   ///
00877   /// extern "C" void LLVMInitializeFooTarget() {
00878   ///   extern Target TheFooTarget;
00879   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
00880   /// }
00881   template<class MCCodeGenInfoImpl>
00882   struct RegisterMCCodeGenInfo {
00883     RegisterMCCodeGenInfo(Target &T) {
00884       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
00885     }
00886   private:
00887     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
00888                                     CodeModel::Model /*CM*/,
00889                                     CodeGenOpt::Level /*OL*/) {
00890       return new MCCodeGenInfoImpl();
00891     }
00892   };
00893 
00894   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
00895   /// info implementation.  This invokes the specified function to do the
00896   /// construction.  Usage:
00897   ///
00898   /// extern "C" void LLVMInitializeFooTarget() {
00899   ///   extern Target TheFooTarget;
00900   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
00901   /// }
00902   struct RegisterMCCodeGenInfoFn {
00903     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
00904       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
00905     }
00906   };
00907 
00908   /// RegisterMCInstrInfo - Helper template for registering a target instruction
00909   /// info implementation.  This invokes the static "Create" method on the class
00910   /// to actually do the construction.  Usage:
00911   ///
00912   /// extern "C" void LLVMInitializeFooTarget() {
00913   ///   extern Target TheFooTarget;
00914   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
00915   /// }
00916   template<class MCInstrInfoImpl>
00917   struct RegisterMCInstrInfo {
00918     RegisterMCInstrInfo(Target &T) {
00919       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
00920     }
00921   private:
00922     static MCInstrInfo *Allocator() {
00923       return new MCInstrInfoImpl();
00924     }
00925   };
00926 
00927   /// RegisterMCInstrInfoFn - Helper template for registering a target
00928   /// instruction info implementation.  This invokes the specified function to
00929   /// do the construction.  Usage:
00930   ///
00931   /// extern "C" void LLVMInitializeFooTarget() {
00932   ///   extern Target TheFooTarget;
00933   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
00934   /// }
00935   struct RegisterMCInstrInfoFn {
00936     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00937       TargetRegistry::RegisterMCInstrInfo(T, Fn);
00938     }
00939   };
00940 
00941   /// RegisterMCInstrAnalysis - Helper template for registering a target
00942   /// instruction analyzer implementation.  This invokes the static "Create"
00943   /// method on the class to actually do the construction.  Usage:
00944   ///
00945   /// extern "C" void LLVMInitializeFooTarget() {
00946   ///   extern Target TheFooTarget;
00947   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
00948   /// }
00949   template<class MCInstrAnalysisImpl>
00950   struct RegisterMCInstrAnalysis {
00951     RegisterMCInstrAnalysis(Target &T) {
00952       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
00953     }
00954   private:
00955     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
00956       return new MCInstrAnalysisImpl(Info);
00957     }
00958   };
00959 
00960   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
00961   /// instruction analyzer implementation.  This invokes the specified function
00962   /// to do the construction.  Usage:
00963   ///
00964   /// extern "C" void LLVMInitializeFooTarget() {
00965   ///   extern Target TheFooTarget;
00966   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
00967   /// }
00968   struct RegisterMCInstrAnalysisFn {
00969     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
00970       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
00971     }
00972   };
00973 
00974   /// RegisterMCRegInfo - Helper template for registering a target register info
00975   /// implementation.  This invokes the static "Create" method on the class to
00976   /// actually do the construction.  Usage:
00977   ///
00978   /// extern "C" void LLVMInitializeFooTarget() {
00979   ///   extern Target TheFooTarget;
00980   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
00981   /// }
00982   template<class MCRegisterInfoImpl>
00983   struct RegisterMCRegInfo {
00984     RegisterMCRegInfo(Target &T) {
00985       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
00986     }
00987   private:
00988     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
00989       return new MCRegisterInfoImpl();
00990     }
00991   };
00992 
00993   /// RegisterMCRegInfoFn - Helper template for registering a target register
00994   /// info implementation.  This invokes the specified function to do the
00995   /// construction.  Usage:
00996   ///
00997   /// extern "C" void LLVMInitializeFooTarget() {
00998   ///   extern Target TheFooTarget;
00999   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
01000   /// }
01001   struct RegisterMCRegInfoFn {
01002     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
01003       TargetRegistry::RegisterMCRegInfo(T, Fn);
01004     }
01005   };
01006 
01007   /// RegisterMCSubtargetInfo - Helper template for registering a target
01008   /// subtarget info implementation.  This invokes the static "Create" method
01009   /// on the class to actually do the construction.  Usage:
01010   ///
01011   /// extern "C" void LLVMInitializeFooTarget() {
01012   ///   extern Target TheFooTarget;
01013   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
01014   /// }
01015   template<class MCSubtargetInfoImpl>
01016   struct RegisterMCSubtargetInfo {
01017     RegisterMCSubtargetInfo(Target &T) {
01018       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
01019     }
01020   private:
01021     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
01022                                       StringRef /*FS*/) {
01023       return new MCSubtargetInfoImpl();
01024     }
01025   };
01026 
01027   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
01028   /// subtarget info implementation.  This invokes the specified function to
01029   /// do the construction.  Usage:
01030   ///
01031   /// extern "C" void LLVMInitializeFooTarget() {
01032   ///   extern Target TheFooTarget;
01033   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
01034   /// }
01035   struct RegisterMCSubtargetInfoFn {
01036     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
01037       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
01038     }
01039   };
01040 
01041   /// RegisterTargetMachine - Helper template for registering a target machine
01042   /// implementation, for use in the target machine initialization
01043   /// function. Usage:
01044   ///
01045   /// extern "C" void LLVMInitializeFooTarget() {
01046   ///   extern Target TheFooTarget;
01047   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
01048   /// }
01049   template<class TargetMachineImpl>
01050   struct RegisterTargetMachine {
01051     RegisterTargetMachine(Target &T) {
01052       TargetRegistry::RegisterTargetMachine(T, &Allocator);
01053     }
01054 
01055   private:
01056     static TargetMachine *Allocator(const Target &T, StringRef TT,
01057                                     StringRef CPU, StringRef FS,
01058                                     const TargetOptions &Options,
01059                                     Reloc::Model RM,
01060                                     CodeModel::Model CM,
01061                                     CodeGenOpt::Level OL) {
01062       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
01063     }
01064   };
01065 
01066   /// RegisterMCAsmBackend - Helper template for registering a target specific
01067   /// assembler backend. Usage:
01068   ///
01069   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
01070   ///   extern Target TheFooTarget;
01071   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
01072   /// }
01073   template<class MCAsmBackendImpl>
01074   struct RegisterMCAsmBackend {
01075     RegisterMCAsmBackend(Target &T) {
01076       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
01077     }
01078 
01079   private:
01080     static MCAsmBackend *Allocator(const Target &T,
01081                                    const MCRegisterInfo &MRI,
01082                                    StringRef Triple, StringRef CPU) {
01083       return new MCAsmBackendImpl(T, MRI, Triple, CPU);
01084     }
01085   };
01086 
01087   /// RegisterMCAsmParser - Helper template for registering a target specific
01088   /// assembly parser, for use in the target machine initialization
01089   /// function. Usage:
01090   ///
01091   /// extern "C" void LLVMInitializeFooMCAsmParser() {
01092   ///   extern Target TheFooTarget;
01093   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
01094   /// }
01095   template<class MCAsmParserImpl>
01096   struct RegisterMCAsmParser {
01097     RegisterMCAsmParser(Target &T) {
01098       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
01099     }
01100 
01101   private:
01102     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
01103                                         const MCInstrInfo &MII,
01104                                         const MCTargetOptions &Options) {
01105       return new MCAsmParserImpl(STI, P, MII, Options);
01106     }
01107   };
01108 
01109   /// RegisterAsmPrinter - Helper template for registering a target specific
01110   /// assembly printer, for use in the target machine initialization
01111   /// function. Usage:
01112   ///
01113   /// extern "C" void LLVMInitializeFooAsmPrinter() {
01114   ///   extern Target TheFooTarget;
01115   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
01116   /// }
01117   template<class AsmPrinterImpl>
01118   struct RegisterAsmPrinter {
01119     RegisterAsmPrinter(Target &T) {
01120       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
01121     }
01122 
01123   private:
01124     static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
01125       return new AsmPrinterImpl(TM, Streamer);
01126     }
01127   };
01128 
01129   /// RegisterMCCodeEmitter - Helper template for registering a target specific
01130   /// machine code emitter, for use in the target initialization
01131   /// function. Usage:
01132   ///
01133   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
01134   ///   extern Target TheFooTarget;
01135   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
01136   /// }
01137   template<class MCCodeEmitterImpl>
01138   struct RegisterMCCodeEmitter {
01139     RegisterMCCodeEmitter(Target &T) {
01140       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
01141     }
01142 
01143   private:
01144     static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
01145                                     const MCRegisterInfo &/*MRI*/,
01146                                     const MCSubtargetInfo &/*STI*/,
01147                                     MCContext &/*Ctx*/) {
01148       return new MCCodeEmitterImpl();
01149     }
01150   };
01151 
01152 }
01153 
01154 #endif