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