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