TargetRegistry.h revision 320296a4cfe414ce59f406b8a5ce15272f563103
1//===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file exposes the TargetRegistry interface, which tools can use to access 11// the appropriate target specific classes (TargetMachine, AsmPrinter, etc.) 12// which have been registered. 13// 14// Target specific class implementations should register themselves using the 15// appropriate TargetRegistry interfaces. 16// 17//===----------------------------------------------------------------------===// 18 19#ifndef LLVM_SUPPORT_TARGETREGISTRY_H 20#define LLVM_SUPPORT_TARGETREGISTRY_H 21 22#include "llvm/ADT/Triple.h" 23#include "llvm/Support/CodeGen.h" 24#include "llvm-c/Disassembler.h" 25#include <cassert> 26#include <string> 27 28namespace llvm { 29 class AsmPrinter; 30 class Module; 31 class MCAssembler; 32 class MCAsmBackend; 33 class MCAsmInfo; 34 class MCAsmParser; 35 class MCCodeEmitter; 36 class MCCodeGenInfo; 37 class MCContext; 38 class MCDisassembler; 39 class MCInstrAnalysis; 40 class MCInstPrinter; 41 class MCInstrInfo; 42 class MCRegisterInfo; 43 class MCStreamer; 44 class MCSubtargetInfo; 45 class MCSymbolizer; 46 class MCRelocationInfo; 47 class MCTargetAsmParser; 48 class TargetMachine; 49 class MCTargetStreamer; 50 class TargetOptions; 51 class raw_ostream; 52 class formatted_raw_ostream; 53 54 MCStreamer *createAsmStreamer(MCContext &Ctx, 55 MCTargetStreamer *TargetStreamer, 56 formatted_raw_ostream &OS, bool isVerboseAsm, 57 bool useLoc, bool useCFI, 58 bool useDwarfDirectory, 59 MCInstPrinter *InstPrint, MCCodeEmitter *CE, 60 MCAsmBackend *TAB, bool ShowInst); 61 62 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx); 63 64 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, 65 LLVMSymbolLookupCallback SymbolLookUp, 66 void *DisInfo, 67 MCContext *Ctx, 68 MCRelocationInfo *RelInfo); 69 70 /// Target - Wrapper for Target specific information. 71 /// 72 /// For registration purposes, this is a POD type so that targets can be 73 /// registered without the use of static constructors. 74 /// 75 /// Targets should implement a single global instance of this class (which 76 /// will be zero initialized), and pass that instance to the TargetRegistry as 77 /// part of their initialization. 78 class Target { 79 public: 80 friend struct TargetRegistry; 81 82 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT); 83 84 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI, 85 StringRef TT); 86 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT, 87 Reloc::Model RM, 88 CodeModel::Model CM, 89 CodeGenOpt::Level OL); 90 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void); 91 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info); 92 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT); 93 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT, 94 StringRef CPU, 95 StringRef Features); 96 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T, 97 StringRef TT, 98 StringRef CPU, 99 StringRef Features, 100 const TargetOptions &Options, 101 Reloc::Model RM, 102 CodeModel::Model CM, 103 CodeGenOpt::Level OL); 104 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM, 105 MCStreamer &Streamer); 106 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, 107 const MCRegisterInfo &MRI, 108 StringRef TT, 109 StringRef CPU); 110 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI, 111 MCAsmParser &P, 112 const MCInstrInfo &MII); 113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T, 114 const MCSubtargetInfo &STI); 115 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T, 116 unsigned SyntaxVariant, 117 const MCAsmInfo &MAI, 118 const MCInstrInfo &MII, 119 const MCRegisterInfo &MRI, 120 const MCSubtargetInfo &STI); 121 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II, 122 const MCRegisterInfo &MRI, 123 const MCSubtargetInfo &STI, 124 MCContext &Ctx); 125 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T, 126 StringRef TT, 127 MCContext &Ctx, 128 MCAsmBackend &TAB, 129 raw_ostream &_OS, 130 MCCodeEmitter *_Emitter, 131 bool RelaxAll, 132 bool NoExecStack); 133 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx, 134 formatted_raw_ostream &OS, 135 bool isVerboseAsm, 136 bool useLoc, 137 bool useCFI, 138 bool useDwarfDirectory, 139 MCInstPrinter *InstPrint, 140 MCCodeEmitter *CE, 141 MCAsmBackend *TAB, 142 bool ShowInst); 143 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT, 144 MCContext &Ctx); 145 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT, 146 LLVMOpInfoCallback GetOpInfo, 147 LLVMSymbolLookupCallback SymbolLookUp, 148 void *DisInfo, 149 MCContext *Ctx, 150 MCRelocationInfo *RelInfo); 151 152 private: 153 /// Next - The next registered target in the linked list, maintained by the 154 /// TargetRegistry. 155 Target *Next; 156 157 /// TripleMatchQualityFn - The target function for rating the match quality 158 /// of a triple. 159 TripleMatchQualityFnTy TripleMatchQualityFn; 160 161 /// Name - The target name. 162 const char *Name; 163 164 /// ShortDesc - A short description of the target. 165 const char *ShortDesc; 166 167 /// HasJIT - Whether this target supports the JIT. 168 bool HasJIT; 169 170 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if 171 /// registered. 172 MCAsmInfoCtorFnTy MCAsmInfoCtorFn; 173 174 /// MCCodeGenInfoCtorFn - Constructor function for this target's 175 /// MCCodeGenInfo, if registered. 176 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn; 177 178 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo, 179 /// if registered. 180 MCInstrInfoCtorFnTy MCInstrInfoCtorFn; 181 182 /// MCInstrAnalysisCtorFn - Constructor function for this target's 183 /// MCInstrAnalysis, if registered. 184 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn; 185 186 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo, 187 /// if registered. 188 MCRegInfoCtorFnTy MCRegInfoCtorFn; 189 190 /// MCSubtargetInfoCtorFn - Constructor function for this target's 191 /// MCSubtargetInfo, if registered. 192 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn; 193 194 /// TargetMachineCtorFn - Construction function for this target's 195 /// TargetMachine, if registered. 196 TargetMachineCtorTy TargetMachineCtorFn; 197 198 /// MCAsmBackendCtorFn - Construction function for this target's 199 /// MCAsmBackend, if registered. 200 MCAsmBackendCtorTy MCAsmBackendCtorFn; 201 202 /// MCAsmParserCtorFn - Construction function for this target's 203 /// MCTargetAsmParser, if registered. 204 MCAsmParserCtorTy MCAsmParserCtorFn; 205 206 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter, 207 /// if registered. 208 AsmPrinterCtorTy AsmPrinterCtorFn; 209 210 /// MCDisassemblerCtorFn - Construction function for this target's 211 /// MCDisassembler, if registered. 212 MCDisassemblerCtorTy MCDisassemblerCtorFn; 213 214 /// MCInstPrinterCtorFn - Construction function for this target's 215 /// MCInstPrinter, if registered. 216 MCInstPrinterCtorTy MCInstPrinterCtorFn; 217 218 /// MCCodeEmitterCtorFn - Construction function for this target's 219 /// CodeEmitter, if registered. 220 MCCodeEmitterCtorTy MCCodeEmitterCtorFn; 221 222 /// MCObjectStreamerCtorFn - Construction function for this target's 223 /// MCObjectStreamer, if registered. 224 MCObjectStreamerCtorTy MCObjectStreamerCtorFn; 225 226 /// AsmStreamerCtorFn - Construction function for this target's 227 /// AsmStreamer, if registered (default = llvm::createAsmStreamer). 228 AsmStreamerCtorTy AsmStreamerCtorFn; 229 230 /// MCRelocationInfoCtorFn - Construction function for this target's 231 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo) 232 MCRelocationInfoCtorTy MCRelocationInfoCtorFn; 233 234 /// MCSymbolizerCtorFn - Construction function for this target's 235 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer) 236 MCSymbolizerCtorTy MCSymbolizerCtorFn; 237 238 static MCStreamer * 239 createDefaultAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, 240 bool isVerboseAsm, bool useLoc, bool useCFI, 241 bool useDwarfDirectory, MCInstPrinter *InstPrint, 242 MCCodeEmitter *CE, MCAsmBackend *TAB, 243 bool ShowInst) { 244 return llvm::createAsmStreamer(Ctx, 0, OS, isVerboseAsm, useLoc, useCFI, 245 useDwarfDirectory, InstPrint, CE, TAB, 246 ShowInst); 247 } 248 249 public: 250 Target() 251 : AsmStreamerCtorFn(createDefaultAsmStreamer), 252 MCRelocationInfoCtorFn(llvm::createMCRelocationInfo), 253 MCSymbolizerCtorFn(llvm::createMCSymbolizer) {} 254 255 /// @name Target Information 256 /// @{ 257 258 // getNext - Return the next registered target. 259 const Target *getNext() const { return Next; } 260 261 /// getName - Get the target name. 262 const char *getName() const { return Name; } 263 264 /// getShortDescription - Get a short description of the target. 265 const char *getShortDescription() const { return ShortDesc; } 266 267 /// @} 268 /// @name Feature Predicates 269 /// @{ 270 271 /// hasJIT - Check if this targets supports the just-in-time compilation. 272 bool hasJIT() const { return HasJIT; } 273 274 /// hasTargetMachine - Check if this target supports code generation. 275 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; } 276 277 /// hasMCAsmBackend - Check if this target supports .o generation. 278 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; } 279 280 /// hasAsmParser - Check if this target supports .s parsing. 281 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; } 282 283 /// hasAsmPrinter - Check if this target supports .s printing. 284 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; } 285 286 /// hasMCDisassembler - Check if this target has a disassembler. 287 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; } 288 289 /// hasMCInstPrinter - Check if this target has an instruction printer. 290 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; } 291 292 /// hasMCCodeEmitter - Check if this target supports instruction encoding. 293 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; } 294 295 /// hasMCObjectStreamer - Check if this target supports streaming to files. 296 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; } 297 298 /// hasAsmStreamer - Check if this target supports streaming to files. 299 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; } 300 301 /// @} 302 /// @name Feature Constructors 303 /// @{ 304 305 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified 306 /// target triple. 307 /// 308 /// \param Triple This argument is used to determine the target machine 309 /// feature set; it should always be provided. Generally this should be 310 /// either the target triple from the module, or the target triple of the 311 /// host if that does not exist. 312 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, 313 StringRef Triple) const { 314 if (!MCAsmInfoCtorFn) 315 return 0; 316 return MCAsmInfoCtorFn(MRI, Triple); 317 } 318 319 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation. 320 /// 321 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM, 322 CodeModel::Model CM, 323 CodeGenOpt::Level OL) const { 324 if (!MCCodeGenInfoCtorFn) 325 return 0; 326 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL); 327 } 328 329 /// createMCInstrInfo - Create a MCInstrInfo implementation. 330 /// 331 MCInstrInfo *createMCInstrInfo() const { 332 if (!MCInstrInfoCtorFn) 333 return 0; 334 return MCInstrInfoCtorFn(); 335 } 336 337 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation. 338 /// 339 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const { 340 if (!MCInstrAnalysisCtorFn) 341 return 0; 342 return MCInstrAnalysisCtorFn(Info); 343 } 344 345 /// createMCRegInfo - Create a MCRegisterInfo implementation. 346 /// 347 MCRegisterInfo *createMCRegInfo(StringRef Triple) const { 348 if (!MCRegInfoCtorFn) 349 return 0; 350 return MCRegInfoCtorFn(Triple); 351 } 352 353 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation. 354 /// 355 /// \param Triple This argument is used to determine the target machine 356 /// feature set; it should always be provided. Generally this should be 357 /// either the target triple from the module, or the target triple of the 358 /// host if that does not exist. 359 /// \param CPU This specifies the name of the target CPU. 360 /// \param Features This specifies the string representation of the 361 /// additional target features. 362 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU, 363 StringRef Features) const { 364 if (!MCSubtargetInfoCtorFn) 365 return 0; 366 return MCSubtargetInfoCtorFn(Triple, CPU, Features); 367 } 368 369 /// createTargetMachine - Create a target specific machine implementation 370 /// for the specified \p Triple. 371 /// 372 /// \param Triple This argument is used to determine the target machine 373 /// feature set; it should always be provided. Generally this should be 374 /// either the target triple from the module, or the target triple of the 375 /// host if that does not exist. 376 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU, 377 StringRef Features, const TargetOptions &Options, 378 Reloc::Model RM = Reloc::Default, 379 CodeModel::Model CM = CodeModel::Default, 380 CodeGenOpt::Level OL = CodeGenOpt::Default) const { 381 if (!TargetMachineCtorFn) 382 return 0; 383 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options, 384 RM, CM, OL); 385 } 386 387 /// createMCAsmBackend - Create a target specific assembly parser. 388 /// 389 /// \param Triple The target triple string. 390 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI, 391 StringRef Triple, StringRef CPU) const { 392 if (!MCAsmBackendCtorFn) 393 return 0; 394 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU); 395 } 396 397 /// createMCAsmParser - Create a target specific assembly parser. 398 /// 399 /// \param Parser The target independent parser implementation to use for 400 /// parsing and lexing. 401 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI, 402 MCAsmParser &Parser, 403 const MCInstrInfo &MII) const { 404 if (!MCAsmParserCtorFn) 405 return 0; 406 return MCAsmParserCtorFn(STI, Parser, MII); 407 } 408 409 /// createAsmPrinter - Create a target specific assembly printer pass. This 410 /// takes ownership of the MCStreamer object. 411 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{ 412 if (!AsmPrinterCtorFn) 413 return 0; 414 return AsmPrinterCtorFn(TM, Streamer); 415 } 416 417 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const { 418 if (!MCDisassemblerCtorFn) 419 return 0; 420 return MCDisassemblerCtorFn(*this, STI); 421 } 422 423 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant, 424 const MCAsmInfo &MAI, 425 const MCInstrInfo &MII, 426 const MCRegisterInfo &MRI, 427 const MCSubtargetInfo &STI) const { 428 if (!MCInstPrinterCtorFn) 429 return 0; 430 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI); 431 } 432 433 434 /// createMCCodeEmitter - Create a target specific code emitter. 435 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II, 436 const MCRegisterInfo &MRI, 437 const MCSubtargetInfo &STI, 438 MCContext &Ctx) const { 439 if (!MCCodeEmitterCtorFn) 440 return 0; 441 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx); 442 } 443 444 /// createMCObjectStreamer - Create a target specific MCStreamer. 445 /// 446 /// \param TT The target triple. 447 /// \param Ctx The target context. 448 /// \param TAB The target assembler backend object. Takes ownership. 449 /// \param _OS The stream object. 450 /// \param _Emitter The target independent assembler object.Takes ownership. 451 /// \param RelaxAll Relax all fixups? 452 /// \param NoExecStack Mark file as not needing a executable stack. 453 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx, 454 MCAsmBackend &TAB, 455 raw_ostream &_OS, 456 MCCodeEmitter *_Emitter, 457 bool RelaxAll, 458 bool NoExecStack) const { 459 if (!MCObjectStreamerCtorFn) 460 return 0; 461 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, 462 RelaxAll, NoExecStack); 463 } 464 465 /// createAsmStreamer - Create a target specific MCStreamer. 466 MCStreamer *createAsmStreamer(MCContext &Ctx, 467 formatted_raw_ostream &OS, 468 bool isVerboseAsm, 469 bool useLoc, 470 bool useCFI, 471 bool useDwarfDirectory, 472 MCInstPrinter *InstPrint, 473 MCCodeEmitter *CE, 474 MCAsmBackend *TAB, 475 bool ShowInst) const { 476 // AsmStreamerCtorFn is default to llvm::createAsmStreamer 477 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI, 478 useDwarfDirectory, InstPrint, CE, TAB, ShowInst); 479 } 480 481 /// createMCRelocationInfo - Create a target specific MCRelocationInfo. 482 /// 483 /// \param TT The target triple. 484 /// \param Ctx The target context. 485 MCRelocationInfo * 486 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const { 487 return MCRelocationInfoCtorFn(TT, Ctx); 488 } 489 490 /// createMCSymbolizer - Create a target specific MCSymbolizer. 491 /// 492 /// \param TT The target triple. 493 /// \param GetOpInfo The function to get the symbolic information for operands. 494 /// \param SymbolLookUp The function to lookup a symbol name. 495 /// \param DisInfo The pointer to the block of symbolic information for above call 496 /// back. 497 /// \param Ctx The target context. 498 /// \param RelInfo The relocation information for this target. Takes ownership. 499 MCSymbolizer * 500 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, 501 LLVMSymbolLookupCallback SymbolLookUp, 502 void *DisInfo, 503 MCContext *Ctx, MCRelocationInfo *RelInfo) const { 504 return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo, 505 Ctx, RelInfo); 506 } 507 508 /// @} 509 }; 510 511 /// TargetRegistry - Generic interface to target specific features. 512 struct TargetRegistry { 513 class iterator { 514 const Target *Current; 515 explicit iterator(Target *T) : Current(T) {} 516 friend struct TargetRegistry; 517 public: 518 iterator(const iterator &I) : Current(I.Current) {} 519 iterator() : Current(0) {} 520 521 bool operator==(const iterator &x) const { 522 return Current == x.Current; 523 } 524 bool operator!=(const iterator &x) const { 525 return !operator==(x); 526 } 527 528 // Iterator traversal: forward iteration only 529 iterator &operator++() { // Preincrement 530 assert(Current && "Cannot increment end iterator!"); 531 Current = Current->getNext(); 532 return *this; 533 } 534 iterator operator++(int) { // Postincrement 535 iterator tmp = *this; 536 ++*this; 537 return tmp; 538 } 539 540 const Target &operator*() const { 541 assert(Current && "Cannot dereference end iterator!"); 542 return *Current; 543 } 544 545 const Target *operator->() const { 546 return &operator*(); 547 } 548 }; 549 550 /// printRegisteredTargetsForVersion - Print the registered targets 551 /// appropriately for inclusion in a tool's version output. 552 static void printRegisteredTargetsForVersion(); 553 554 /// @name Registry Access 555 /// @{ 556 557 static iterator begin(); 558 559 static iterator end() { return iterator(); } 560 561 /// lookupTarget - Lookup a target based on a target triple. 562 /// 563 /// \param Triple - The triple to use for finding a target. 564 /// \param Error - On failure, an error string describing why no target was 565 /// found. 566 static const Target *lookupTarget(const std::string &Triple, 567 std::string &Error); 568 569 /// lookupTarget - Lookup a target based on an architecture name 570 /// and a target triple. If the architecture name is non-empty, 571 /// then the lookup is done by architecture. Otherwise, the target 572 /// triple is used. 573 /// 574 /// \param ArchName - The architecture to use for finding a target. 575 /// \param TheTriple - The triple to use for finding a target. The 576 /// triple is updated with canonical architecture name if a lookup 577 /// by architecture is done. 578 /// \param Error - On failure, an error string describing why no target was 579 /// found. 580 static const Target *lookupTarget(const std::string &ArchName, 581 Triple &TheTriple, 582 std::string &Error); 583 584 /// getClosestTargetForJIT - Pick the best target that is compatible with 585 /// the current host. If no close target can be found, this returns null 586 /// and sets the Error string to a reason. 587 /// 588 /// Maintained for compatibility through 2.6. 589 static const Target *getClosestTargetForJIT(std::string &Error); 590 591 /// @} 592 /// @name Target Registration 593 /// @{ 594 595 /// RegisterTarget - Register the given target. Attempts to register a 596 /// target which has already been registered will be ignored. 597 /// 598 /// Clients are responsible for ensuring that registration doesn't occur 599 /// while another thread is attempting to access the registry. Typically 600 /// this is done by initializing all targets at program startup. 601 /// 602 /// @param T - The target being registered. 603 /// @param Name - The target name. This should be a static string. 604 /// @param ShortDesc - A short target description. This should be a static 605 /// string. 606 /// @param TQualityFn - The triple match quality computation function for 607 /// this target. 608 /// @param HasJIT - Whether the target supports JIT code 609 /// generation. 610 static void RegisterTarget(Target &T, 611 const char *Name, 612 const char *ShortDesc, 613 Target::TripleMatchQualityFnTy TQualityFn, 614 bool HasJIT = false); 615 616 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the 617 /// given target. 618 /// 619 /// Clients are responsible for ensuring that registration doesn't occur 620 /// while another thread is attempting to access the registry. Typically 621 /// this is done by initializing all targets at program startup. 622 /// 623 /// @param T - The target being registered. 624 /// @param Fn - A function to construct a MCAsmInfo for the target. 625 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) { 626 // Ignore duplicate registration. 627 if (!T.MCAsmInfoCtorFn) 628 T.MCAsmInfoCtorFn = Fn; 629 } 630 631 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the 632 /// given target. 633 /// 634 /// Clients are responsible for ensuring that registration doesn't occur 635 /// while another thread is attempting to access the registry. Typically 636 /// this is done by initializing all targets at program startup. 637 /// 638 /// @param T - The target being registered. 639 /// @param Fn - A function to construct a MCCodeGenInfo for the target. 640 static void RegisterMCCodeGenInfo(Target &T, 641 Target::MCCodeGenInfoCtorFnTy Fn) { 642 // Ignore duplicate registration. 643 if (!T.MCCodeGenInfoCtorFn) 644 T.MCCodeGenInfoCtorFn = Fn; 645 } 646 647 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the 648 /// given target. 649 /// 650 /// Clients are responsible for ensuring that registration doesn't occur 651 /// while another thread is attempting to access the registry. Typically 652 /// this is done by initializing all targets at program startup. 653 /// 654 /// @param T - The target being registered. 655 /// @param Fn - A function to construct a MCInstrInfo for the target. 656 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) { 657 // Ignore duplicate registration. 658 if (!T.MCInstrInfoCtorFn) 659 T.MCInstrInfoCtorFn = Fn; 660 } 661 662 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for 663 /// the given target. 664 static void RegisterMCInstrAnalysis(Target &T, 665 Target::MCInstrAnalysisCtorFnTy Fn) { 666 // Ignore duplicate registration. 667 if (!T.MCInstrAnalysisCtorFn) 668 T.MCInstrAnalysisCtorFn = Fn; 669 } 670 671 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the 672 /// given target. 673 /// 674 /// Clients are responsible for ensuring that registration doesn't occur 675 /// while another thread is attempting to access the registry. Typically 676 /// this is done by initializing all targets at program startup. 677 /// 678 /// @param T - The target being registered. 679 /// @param Fn - A function to construct a MCRegisterInfo for the target. 680 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) { 681 // Ignore duplicate registration. 682 if (!T.MCRegInfoCtorFn) 683 T.MCRegInfoCtorFn = Fn; 684 } 685 686 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for 687 /// the given target. 688 /// 689 /// Clients are responsible for ensuring that registration doesn't occur 690 /// while another thread is attempting to access the registry. Typically 691 /// this is done by initializing all targets at program startup. 692 /// 693 /// @param T - The target being registered. 694 /// @param Fn - A function to construct a MCSubtargetInfo for the target. 695 static void RegisterMCSubtargetInfo(Target &T, 696 Target::MCSubtargetInfoCtorFnTy Fn) { 697 // Ignore duplicate registration. 698 if (!T.MCSubtargetInfoCtorFn) 699 T.MCSubtargetInfoCtorFn = Fn; 700 } 701 702 /// RegisterTargetMachine - Register a TargetMachine implementation for the 703 /// given target. 704 /// 705 /// Clients are responsible for ensuring that registration doesn't occur 706 /// while another thread is attempting to access the registry. Typically 707 /// this is done by initializing all targets at program startup. 708 /// 709 /// @param T - The target being registered. 710 /// @param Fn - A function to construct a TargetMachine for the target. 711 static void RegisterTargetMachine(Target &T, 712 Target::TargetMachineCtorTy Fn) { 713 // Ignore duplicate registration. 714 if (!T.TargetMachineCtorFn) 715 T.TargetMachineCtorFn = Fn; 716 } 717 718 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the 719 /// given target. 720 /// 721 /// Clients are responsible for ensuring that registration doesn't occur 722 /// while another thread is attempting to access the registry. Typically 723 /// this is done by initializing all targets at program startup. 724 /// 725 /// @param T - The target being registered. 726 /// @param Fn - A function to construct an AsmBackend for the target. 727 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) { 728 if (!T.MCAsmBackendCtorFn) 729 T.MCAsmBackendCtorFn = Fn; 730 } 731 732 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for 733 /// the given target. 734 /// 735 /// Clients are responsible for ensuring that registration doesn't occur 736 /// while another thread is attempting to access the registry. Typically 737 /// this is done by initializing all targets at program startup. 738 /// 739 /// @param T - The target being registered. 740 /// @param Fn - A function to construct an MCTargetAsmParser for the target. 741 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) { 742 if (!T.MCAsmParserCtorFn) 743 T.MCAsmParserCtorFn = Fn; 744 } 745 746 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given 747 /// target. 748 /// 749 /// Clients are responsible for ensuring that registration doesn't occur 750 /// while another thread is attempting to access the registry. Typically 751 /// this is done by initializing all targets at program startup. 752 /// 753 /// @param T - The target being registered. 754 /// @param Fn - A function to construct an AsmPrinter for the target. 755 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) { 756 // Ignore duplicate registration. 757 if (!T.AsmPrinterCtorFn) 758 T.AsmPrinterCtorFn = Fn; 759 } 760 761 /// RegisterMCDisassembler - Register a MCDisassembler implementation for 762 /// the given target. 763 /// 764 /// Clients are responsible for ensuring that registration doesn't occur 765 /// while another thread is attempting to access the registry. Typically 766 /// this is done by initializing all targets at program startup. 767 /// 768 /// @param T - The target being registered. 769 /// @param Fn - A function to construct an MCDisassembler for the target. 770 static void RegisterMCDisassembler(Target &T, 771 Target::MCDisassemblerCtorTy Fn) { 772 if (!T.MCDisassemblerCtorFn) 773 T.MCDisassemblerCtorFn = Fn; 774 } 775 776 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the 777 /// given target. 778 /// 779 /// Clients are responsible for ensuring that registration doesn't occur 780 /// while another thread is attempting to access the registry. Typically 781 /// this is done by initializing all targets at program startup. 782 /// 783 /// @param T - The target being registered. 784 /// @param Fn - A function to construct an MCInstPrinter for the target. 785 static void RegisterMCInstPrinter(Target &T, 786 Target::MCInstPrinterCtorTy Fn) { 787 if (!T.MCInstPrinterCtorFn) 788 T.MCInstPrinterCtorFn = Fn; 789 } 790 791 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the 792 /// given target. 793 /// 794 /// Clients are responsible for ensuring that registration doesn't occur 795 /// while another thread is attempting to access the registry. Typically 796 /// this is done by initializing all targets at program startup. 797 /// 798 /// @param T - The target being registered. 799 /// @param Fn - A function to construct an MCCodeEmitter for the target. 800 static void RegisterMCCodeEmitter(Target &T, 801 Target::MCCodeEmitterCtorTy Fn) { 802 if (!T.MCCodeEmitterCtorFn) 803 T.MCCodeEmitterCtorFn = Fn; 804 } 805 806 /// RegisterMCObjectStreamer - Register a object code MCStreamer 807 /// implementation for the given target. 808 /// 809 /// Clients are responsible for ensuring that registration doesn't occur 810 /// while another thread is attempting to access the registry. Typically 811 /// this is done by initializing all targets at program startup. 812 /// 813 /// @param T - The target being registered. 814 /// @param Fn - A function to construct an MCStreamer for the target. 815 static void RegisterMCObjectStreamer(Target &T, 816 Target::MCObjectStreamerCtorTy Fn) { 817 if (!T.MCObjectStreamerCtorFn) 818 T.MCObjectStreamerCtorFn = Fn; 819 } 820 821 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation 822 /// for the given target. 823 /// 824 /// Clients are responsible for ensuring that registration doesn't occur 825 /// while another thread is attempting to access the registry. Typically 826 /// this is done by initializing all targets at program startup. 827 /// 828 /// @param T - The target being registered. 829 /// @param Fn - A function to construct an MCStreamer for the target. 830 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) { 831 if (T.AsmStreamerCtorFn == Target::createDefaultAsmStreamer) 832 T.AsmStreamerCtorFn = Fn; 833 } 834 835 /// RegisterMCRelocationInfo - Register an MCRelocationInfo 836 /// implementation for the given target. 837 /// 838 /// Clients are responsible for ensuring that registration doesn't occur 839 /// while another thread is attempting to access the registry. Typically 840 /// this is done by initializing all targets at program startup. 841 /// 842 /// @param T - The target being registered. 843 /// @param Fn - A function to construct an MCRelocationInfo for the target. 844 static void RegisterMCRelocationInfo(Target &T, 845 Target::MCRelocationInfoCtorTy Fn) { 846 if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo) 847 T.MCRelocationInfoCtorFn = Fn; 848 } 849 850 /// RegisterMCSymbolizer - Register an MCSymbolizer 851 /// implementation for the given target. 852 /// 853 /// Clients are responsible for ensuring that registration doesn't occur 854 /// while another thread is attempting to access the registry. Typically 855 /// this is done by initializing all targets at program startup. 856 /// 857 /// @param T - The target being registered. 858 /// @param Fn - A function to construct an MCSymbolizer for the target. 859 static void RegisterMCSymbolizer(Target &T, 860 Target::MCSymbolizerCtorTy Fn) { 861 if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer) 862 T.MCSymbolizerCtorFn = Fn; 863 } 864 865 /// @} 866 }; 867 868 869 //===--------------------------------------------------------------------===// 870 871 /// RegisterTarget - Helper template for registering a target, for use in the 872 /// target's initialization function. Usage: 873 /// 874 /// 875 /// Target TheFooTarget; // The global target instance. 876 /// 877 /// extern "C" void LLVMInitializeFooTargetInfo() { 878 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description"); 879 /// } 880 template<Triple::ArchType TargetArchType = Triple::UnknownArch, 881 bool HasJIT = false> 882 struct RegisterTarget { 883 RegisterTarget(Target &T, const char *Name, const char *Desc) { 884 TargetRegistry::RegisterTarget(T, Name, Desc, 885 &getTripleMatchQuality, 886 HasJIT); 887 } 888 889 static unsigned getTripleMatchQuality(const std::string &TT) { 890 if (Triple(TT).getArch() == TargetArchType) 891 return 20; 892 return 0; 893 } 894 }; 895 896 /// RegisterMCAsmInfo - Helper template for registering a target assembly info 897 /// implementation. This invokes the static "Create" method on the class to 898 /// actually do the construction. Usage: 899 /// 900 /// extern "C" void LLVMInitializeFooTarget() { 901 /// extern Target TheFooTarget; 902 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget); 903 /// } 904 template<class MCAsmInfoImpl> 905 struct RegisterMCAsmInfo { 906 RegisterMCAsmInfo(Target &T) { 907 TargetRegistry::RegisterMCAsmInfo(T, &Allocator); 908 } 909 private: 910 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) { 911 return new MCAsmInfoImpl(TT); 912 } 913 914 }; 915 916 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info 917 /// implementation. This invokes the specified function to do the 918 /// construction. Usage: 919 /// 920 /// extern "C" void LLVMInitializeFooTarget() { 921 /// extern Target TheFooTarget; 922 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction); 923 /// } 924 struct RegisterMCAsmInfoFn { 925 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) { 926 TargetRegistry::RegisterMCAsmInfo(T, Fn); 927 } 928 }; 929 930 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info 931 /// implementation. This invokes the static "Create" method on the class 932 /// to actually do the construction. Usage: 933 /// 934 /// extern "C" void LLVMInitializeFooTarget() { 935 /// extern Target TheFooTarget; 936 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget); 937 /// } 938 template<class MCCodeGenInfoImpl> 939 struct RegisterMCCodeGenInfo { 940 RegisterMCCodeGenInfo(Target &T) { 941 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator); 942 } 943 private: 944 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/, 945 CodeModel::Model /*CM*/, 946 CodeGenOpt::Level /*OL*/) { 947 return new MCCodeGenInfoImpl(); 948 } 949 }; 950 951 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen 952 /// info implementation. This invokes the specified function to do the 953 /// construction. Usage: 954 /// 955 /// extern "C" void LLVMInitializeFooTarget() { 956 /// extern Target TheFooTarget; 957 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction); 958 /// } 959 struct RegisterMCCodeGenInfoFn { 960 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) { 961 TargetRegistry::RegisterMCCodeGenInfo(T, Fn); 962 } 963 }; 964 965 /// RegisterMCInstrInfo - Helper template for registering a target instruction 966 /// info implementation. This invokes the static "Create" method on the class 967 /// to actually do the construction. Usage: 968 /// 969 /// extern "C" void LLVMInitializeFooTarget() { 970 /// extern Target TheFooTarget; 971 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget); 972 /// } 973 template<class MCInstrInfoImpl> 974 struct RegisterMCInstrInfo { 975 RegisterMCInstrInfo(Target &T) { 976 TargetRegistry::RegisterMCInstrInfo(T, &Allocator); 977 } 978 private: 979 static MCInstrInfo *Allocator() { 980 return new MCInstrInfoImpl(); 981 } 982 }; 983 984 /// RegisterMCInstrInfoFn - Helper template for registering a target 985 /// instruction info implementation. This invokes the specified function to 986 /// do the construction. Usage: 987 /// 988 /// extern "C" void LLVMInitializeFooTarget() { 989 /// extern Target TheFooTarget; 990 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction); 991 /// } 992 struct RegisterMCInstrInfoFn { 993 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) { 994 TargetRegistry::RegisterMCInstrInfo(T, Fn); 995 } 996 }; 997 998 /// RegisterMCInstrAnalysis - Helper template for registering a target 999 /// instruction analyzer implementation. This invokes the static "Create" 1000 /// method on the class to actually do the construction. Usage: 1001 /// 1002 /// extern "C" void LLVMInitializeFooTarget() { 1003 /// extern Target TheFooTarget; 1004 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget); 1005 /// } 1006 template<class MCInstrAnalysisImpl> 1007 struct RegisterMCInstrAnalysis { 1008 RegisterMCInstrAnalysis(Target &T) { 1009 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator); 1010 } 1011 private: 1012 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) { 1013 return new MCInstrAnalysisImpl(Info); 1014 } 1015 }; 1016 1017 /// RegisterMCInstrAnalysisFn - Helper template for registering a target 1018 /// instruction analyzer implementation. This invokes the specified function 1019 /// to do the construction. Usage: 1020 /// 1021 /// extern "C" void LLVMInitializeFooTarget() { 1022 /// extern Target TheFooTarget; 1023 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction); 1024 /// } 1025 struct RegisterMCInstrAnalysisFn { 1026 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) { 1027 TargetRegistry::RegisterMCInstrAnalysis(T, Fn); 1028 } 1029 }; 1030 1031 /// RegisterMCRegInfo - Helper template for registering a target register info 1032 /// implementation. This invokes the static "Create" method on the class to 1033 /// actually do the construction. Usage: 1034 /// 1035 /// extern "C" void LLVMInitializeFooTarget() { 1036 /// extern Target TheFooTarget; 1037 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget); 1038 /// } 1039 template<class MCRegisterInfoImpl> 1040 struct RegisterMCRegInfo { 1041 RegisterMCRegInfo(Target &T) { 1042 TargetRegistry::RegisterMCRegInfo(T, &Allocator); 1043 } 1044 private: 1045 static MCRegisterInfo *Allocator(StringRef /*TT*/) { 1046 return new MCRegisterInfoImpl(); 1047 } 1048 }; 1049 1050 /// RegisterMCRegInfoFn - Helper template for registering a target register 1051 /// info implementation. This invokes the specified function to do the 1052 /// construction. Usage: 1053 /// 1054 /// extern "C" void LLVMInitializeFooTarget() { 1055 /// extern Target TheFooTarget; 1056 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction); 1057 /// } 1058 struct RegisterMCRegInfoFn { 1059 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) { 1060 TargetRegistry::RegisterMCRegInfo(T, Fn); 1061 } 1062 }; 1063 1064 /// RegisterMCSubtargetInfo - Helper template for registering a target 1065 /// subtarget info implementation. This invokes the static "Create" method 1066 /// on the class to actually do the construction. Usage: 1067 /// 1068 /// extern "C" void LLVMInitializeFooTarget() { 1069 /// extern Target TheFooTarget; 1070 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget); 1071 /// } 1072 template<class MCSubtargetInfoImpl> 1073 struct RegisterMCSubtargetInfo { 1074 RegisterMCSubtargetInfo(Target &T) { 1075 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator); 1076 } 1077 private: 1078 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/, 1079 StringRef /*FS*/) { 1080 return new MCSubtargetInfoImpl(); 1081 } 1082 }; 1083 1084 /// RegisterMCSubtargetInfoFn - Helper template for registering a target 1085 /// subtarget info implementation. This invokes the specified function to 1086 /// do the construction. Usage: 1087 /// 1088 /// extern "C" void LLVMInitializeFooTarget() { 1089 /// extern Target TheFooTarget; 1090 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction); 1091 /// } 1092 struct RegisterMCSubtargetInfoFn { 1093 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) { 1094 TargetRegistry::RegisterMCSubtargetInfo(T, Fn); 1095 } 1096 }; 1097 1098 /// RegisterTargetMachine - Helper template for registering a target machine 1099 /// implementation, for use in the target machine initialization 1100 /// function. Usage: 1101 /// 1102 /// extern "C" void LLVMInitializeFooTarget() { 1103 /// extern Target TheFooTarget; 1104 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget); 1105 /// } 1106 template<class TargetMachineImpl> 1107 struct RegisterTargetMachine { 1108 RegisterTargetMachine(Target &T) { 1109 TargetRegistry::RegisterTargetMachine(T, &Allocator); 1110 } 1111 1112 private: 1113 static TargetMachine *Allocator(const Target &T, StringRef TT, 1114 StringRef CPU, StringRef FS, 1115 const TargetOptions &Options, 1116 Reloc::Model RM, 1117 CodeModel::Model CM, 1118 CodeGenOpt::Level OL) { 1119 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL); 1120 } 1121 }; 1122 1123 /// RegisterMCAsmBackend - Helper template for registering a target specific 1124 /// assembler backend. Usage: 1125 /// 1126 /// extern "C" void LLVMInitializeFooMCAsmBackend() { 1127 /// extern Target TheFooTarget; 1128 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget); 1129 /// } 1130 template<class MCAsmBackendImpl> 1131 struct RegisterMCAsmBackend { 1132 RegisterMCAsmBackend(Target &T) { 1133 TargetRegistry::RegisterMCAsmBackend(T, &Allocator); 1134 } 1135 1136 private: 1137 static MCAsmBackend *Allocator(const Target &T, 1138 const MCRegisterInfo &MRI, 1139 StringRef Triple, StringRef CPU) { 1140 return new MCAsmBackendImpl(T, MRI, Triple, CPU); 1141 } 1142 }; 1143 1144 /// RegisterMCAsmParser - Helper template for registering a target specific 1145 /// assembly parser, for use in the target machine initialization 1146 /// function. Usage: 1147 /// 1148 /// extern "C" void LLVMInitializeFooMCAsmParser() { 1149 /// extern Target TheFooTarget; 1150 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget); 1151 /// } 1152 template<class MCAsmParserImpl> 1153 struct RegisterMCAsmParser { 1154 RegisterMCAsmParser(Target &T) { 1155 TargetRegistry::RegisterMCAsmParser(T, &Allocator); 1156 } 1157 1158 private: 1159 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P, 1160 const MCInstrInfo &MII) { 1161 return new MCAsmParserImpl(STI, P, MII); 1162 } 1163 }; 1164 1165 /// RegisterAsmPrinter - Helper template for registering a target specific 1166 /// assembly printer, for use in the target machine initialization 1167 /// function. Usage: 1168 /// 1169 /// extern "C" void LLVMInitializeFooAsmPrinter() { 1170 /// extern Target TheFooTarget; 1171 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget); 1172 /// } 1173 template<class AsmPrinterImpl> 1174 struct RegisterAsmPrinter { 1175 RegisterAsmPrinter(Target &T) { 1176 TargetRegistry::RegisterAsmPrinter(T, &Allocator); 1177 } 1178 1179 private: 1180 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) { 1181 return new AsmPrinterImpl(TM, Streamer); 1182 } 1183 }; 1184 1185 /// RegisterMCCodeEmitter - Helper template for registering a target specific 1186 /// machine code emitter, for use in the target initialization 1187 /// function. Usage: 1188 /// 1189 /// extern "C" void LLVMInitializeFooMCCodeEmitter() { 1190 /// extern Target TheFooTarget; 1191 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget); 1192 /// } 1193 template<class MCCodeEmitterImpl> 1194 struct RegisterMCCodeEmitter { 1195 RegisterMCCodeEmitter(Target &T) { 1196 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator); 1197 } 1198 1199 private: 1200 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/, 1201 const MCRegisterInfo &/*MRI*/, 1202 const MCSubtargetInfo &/*STI*/, 1203 MCContext &/*Ctx*/) { 1204 return new MCCodeEmitterImpl(); 1205 } 1206 }; 1207 1208} 1209 1210#endif 1211