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