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