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