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