1 //===-- Target/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_TARGET_TARGETREGISTRY_H
20 #define LLVM_TARGET_TARGETREGISTRY_H
22 #include "llvm/ADT/Triple.h"
39 class TargetAsmBackend;
41 class TargetAsmParser;
44 class formatted_raw_ostream;
46 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
48 bool useLoc, bool useCFI,
49 MCInstPrinter *InstPrint,
51 TargetAsmBackend *TAB,
54 /// Target - Wrapper for Target specific information.
56 /// For registration purposes, this is a POD type so that targets can be
57 /// registered without the use of static constructors.
59 /// Targets should implement a single global instance of this class (which
60 /// will be zero initialized), and pass that instance to the TargetRegistry as
61 /// part of their initialization.
64 friend struct TargetRegistry;
66 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
68 typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
70 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
71 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(void);
72 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
73 const std::string &TT,
74 const std::string &CPU,
75 const std::string &Features);
76 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
77 MCStreamer &Streamer);
78 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
79 const std::string &TT);
80 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
81 const MCAsmInfo &MAI);
82 typedef TargetAsmParser *(*AsmParserCtorTy)(StringRef TT,
83 StringRef CPU, StringRef Features,
85 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
86 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
87 unsigned SyntaxVariant,
88 const MCAsmInfo &MAI);
89 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
92 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
93 const std::string &TT,
95 TargetAsmBackend &TAB,
97 MCCodeEmitter *_Emitter,
100 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
101 formatted_raw_ostream &OS,
105 MCInstPrinter *InstPrint,
107 TargetAsmBackend *TAB,
111 /// Next - The next registered target in the linked list, maintained by the
115 /// TripleMatchQualityFn - The target function for rating the match quality
117 TripleMatchQualityFnTy TripleMatchQualityFn;
119 /// Name - The target name.
122 /// ShortDesc - A short description of the target.
123 const char *ShortDesc;
125 /// HasJIT - Whether this target supports the JIT.
128 /// AsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
130 AsmInfoCtorFnTy AsmInfoCtorFn;
132 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
134 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
136 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
138 MCRegInfoCtorFnTy MCRegInfoCtorFn;
140 /// TargetMachineCtorFn - Construction function for this target's
141 /// TargetMachine, if registered.
142 TargetMachineCtorTy TargetMachineCtorFn;
144 /// AsmBackendCtorFn - Construction function for this target's
145 /// TargetAsmBackend, if registered.
146 AsmBackendCtorTy AsmBackendCtorFn;
148 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
150 AsmLexerCtorTy AsmLexerCtorFn;
152 /// AsmParserCtorFn - Construction function for this target's
153 /// TargetAsmParser, if registered.
154 AsmParserCtorTy AsmParserCtorFn;
156 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
158 AsmPrinterCtorTy AsmPrinterCtorFn;
160 /// MCDisassemblerCtorFn - Construction function for this target's
161 /// MCDisassembler, if registered.
162 MCDisassemblerCtorTy MCDisassemblerCtorFn;
164 /// MCInstPrinterCtorFn - Construction function for this target's
165 /// MCInstPrinter, if registered.
166 MCInstPrinterCtorTy MCInstPrinterCtorFn;
168 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
170 CodeEmitterCtorTy CodeEmitterCtorFn;
172 /// ObjectStreamerCtorFn - Construction function for this target's
173 /// ObjectStreamer, if registered.
174 ObjectStreamerCtorTy ObjectStreamerCtorFn;
176 /// AsmStreamerCtorFn - Construction function for this target's
177 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
178 AsmStreamerCtorTy AsmStreamerCtorFn;
181 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
183 /// @name Target Information
186 // getNext - Return the next registered target.
187 const Target *getNext() const { return Next; }
189 /// getName - Get the target name.
190 const char *getName() const { return Name; }
192 /// getShortDescription - Get a short description of the target.
193 const char *getShortDescription() const { return ShortDesc; }
196 /// @name Feature Predicates
199 /// hasJIT - Check if this targets supports the just-in-time compilation.
200 bool hasJIT() const { return HasJIT; }
202 /// hasTargetMachine - Check if this target supports code generation.
203 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
205 /// hasAsmBackend - Check if this target supports .o generation.
206 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
208 /// hasAsmLexer - Check if this target supports .s lexing.
209 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
211 /// hasAsmParser - Check if this target supports .s parsing.
212 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
214 /// hasAsmPrinter - Check if this target supports .s printing.
215 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
217 /// hasMCDisassembler - Check if this target has a disassembler.
218 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
220 /// hasMCInstPrinter - Check if this target has an instruction printer.
221 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
223 /// hasCodeEmitter - Check if this target supports instruction encoding.
224 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
226 /// hasObjectStreamer - Check if this target supports streaming to files.
227 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
229 /// hasAsmStreamer - Check if this target supports streaming to files.
230 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
233 /// @name Feature Constructors
236 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
239 /// \arg Triple - This argument is used to determine the target machine
240 /// feature set; it should always be provided. Generally this should be
241 /// either the target triple from the module, or the target triple of the
242 /// host if that does not exist.
243 MCAsmInfo *createAsmInfo(StringRef Triple) const {
246 return AsmInfoCtorFn(*this, Triple);
249 /// createMCInstrInfo - Create a MCInstrInfo implementation.
251 MCInstrInfo *createMCInstrInfo() const {
252 if (!MCInstrInfoCtorFn)
254 return MCInstrInfoCtorFn();
257 /// createMCRegInfo - Create a MCRegisterInfo implementation.
259 MCRegisterInfo *createMCRegInfo() const {
260 if (!MCRegInfoCtorFn)
262 return MCRegInfoCtorFn();
265 /// createTargetMachine - Create a target specific machine implementation
266 /// for the specified \arg Triple.
268 /// \arg Triple - This argument is used to determine the target machine
269 /// feature set; it should always be provided. Generally this should be
270 /// either the target triple from the module, or the target triple of the
271 /// host if that does not exist.
272 TargetMachine *createTargetMachine(const std::string &Triple,
273 const std::string &CPU,
274 const std::string &Features) const {
275 if (!TargetMachineCtorFn)
277 return TargetMachineCtorFn(*this, Triple, CPU, Features);
280 /// createAsmBackend - Create a target specific assembly parser.
282 /// \arg Triple - The target triple string.
283 /// \arg Backend - The target independent assembler object.
284 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
285 if (!AsmBackendCtorFn)
287 return AsmBackendCtorFn(*this, Triple);
290 /// createAsmLexer - Create a target specific assembly lexer.
292 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
295 return AsmLexerCtorFn(*this, MAI);
298 /// createAsmParser - Create a target specific assembly parser.
300 /// \arg Parser - The target independent parser implementation to use for
301 /// parsing and lexing.
302 TargetAsmParser *createAsmParser(StringRef Triple, StringRef CPU,
304 MCAsmParser &Parser) const {
305 if (!AsmParserCtorFn)
307 return AsmParserCtorFn(Triple, CPU, Features, Parser);
310 /// createAsmPrinter - Create a target specific assembly printer pass. This
311 /// takes ownership of the MCStreamer object.
312 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
313 if (!AsmPrinterCtorFn)
315 return AsmPrinterCtorFn(TM, Streamer);
318 MCDisassembler *createMCDisassembler() const {
319 if (!MCDisassemblerCtorFn)
321 return MCDisassemblerCtorFn(*this);
324 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
325 const MCAsmInfo &MAI) const {
326 if (!MCInstPrinterCtorFn)
328 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
332 /// createCodeEmitter - Create a target specific code emitter.
333 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
334 if (!CodeEmitterCtorFn)
336 return CodeEmitterCtorFn(*this, TM, Ctx);
339 /// createObjectStreamer - Create a target specific MCStreamer.
341 /// \arg TT - The target triple.
342 /// \arg Ctx - The target context.
343 /// \arg TAB - The target assembler backend object. Takes ownership.
344 /// \arg _OS - The stream object.
345 /// \arg _Emitter - The target independent assembler object.Takes ownership.
346 /// \arg RelaxAll - Relax all fixups?
347 /// \arg NoExecStack - Mark file as not needing a executable stack.
348 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
349 TargetAsmBackend &TAB,
351 MCCodeEmitter *_Emitter,
353 bool NoExecStack) const {
354 if (!ObjectStreamerCtorFn)
356 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
360 /// createAsmStreamer - Create a target specific MCStreamer.
361 MCStreamer *createAsmStreamer(MCContext &Ctx,
362 formatted_raw_ostream &OS,
366 MCInstPrinter *InstPrint,
368 TargetAsmBackend *TAB,
369 bool ShowInst) const {
370 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
371 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
372 InstPrint, CE, TAB, ShowInst);
378 /// TargetRegistry - Generic interface to target specific features.
379 struct TargetRegistry {
381 const Target *Current;
382 explicit iterator(Target *T) : Current(T) {}
383 friend struct TargetRegistry;
385 iterator(const iterator &I) : Current(I.Current) {}
386 iterator() : Current(0) {}
388 bool operator==(const iterator &x) const {
389 return Current == x.Current;
391 bool operator!=(const iterator &x) const {
392 return !operator==(x);
395 // Iterator traversal: forward iteration only
396 iterator &operator++() { // Preincrement
397 assert(Current && "Cannot increment end iterator!");
398 Current = Current->getNext();
401 iterator operator++(int) { // Postincrement
402 iterator tmp = *this;
407 const Target &operator*() const {
408 assert(Current && "Cannot dereference end iterator!");
412 const Target *operator->() const {
417 /// @name Registry Access
420 static iterator begin();
422 static iterator end() { return iterator(); }
424 /// lookupTarget - Lookup a target based on a target triple.
426 /// \param Triple - The triple to use for finding a target.
427 /// \param Error - On failure, an error string describing why no target was
429 static const Target *lookupTarget(const std::string &Triple,
432 /// getClosestTargetForJIT - Pick the best target that is compatible with
433 /// the current host. If no close target can be found, this returns null
434 /// and sets the Error string to a reason.
436 /// Maintained for compatibility through 2.6.
437 static const Target *getClosestTargetForJIT(std::string &Error);
440 /// @name Target Registration
443 /// RegisterTarget - Register the given target. Attempts to register a
444 /// target which has already been registered will be ignored.
446 /// Clients are responsible for ensuring that registration doesn't occur
447 /// while another thread is attempting to access the registry. Typically
448 /// this is done by initializing all targets at program startup.
450 /// @param T - The target being registered.
451 /// @param Name - The target name. This should be a static string.
452 /// @param ShortDesc - A short target description. This should be a static
454 /// @param TQualityFn - The triple match quality computation function for
456 /// @param HasJIT - Whether the target supports JIT code
458 static void RegisterTarget(Target &T,
460 const char *ShortDesc,
461 Target::TripleMatchQualityFnTy TQualityFn,
462 bool HasJIT = false);
464 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
467 /// Clients are responsible for ensuring that registration doesn't occur
468 /// while another thread is attempting to access the registry. Typically
469 /// this is done by initializing all targets at program startup.
471 /// @param T - The target being registered.
472 /// @param Fn - A function to construct a MCAsmInfo for the target.
473 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
474 // Ignore duplicate registration.
475 if (!T.AsmInfoCtorFn)
476 T.AsmInfoCtorFn = Fn;
479 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
482 /// Clients are responsible for ensuring that registration doesn't occur
483 /// while another thread is attempting to access the registry. Typically
484 /// this is done by initializing all targets at program startup.
486 /// @param T - The target being registered.
487 /// @param Fn - A function to construct a MCInstrInfo for the target.
488 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
489 // Ignore duplicate registration.
490 if (!T.MCInstrInfoCtorFn)
491 T.MCInstrInfoCtorFn = Fn;
494 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
497 /// Clients are responsible for ensuring that registration doesn't occur
498 /// while another thread is attempting to access the registry. Typically
499 /// this is done by initializing all targets at program startup.
501 /// @param T - The target being registered.
502 /// @param Fn - A function to construct a MCRegisterInfo for the target.
503 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
504 // Ignore duplicate registration.
505 if (!T.MCRegInfoCtorFn)
506 T.MCRegInfoCtorFn = Fn;
509 /// RegisterTargetMachine - Register a TargetMachine implementation for the
512 /// Clients are responsible for ensuring that registration doesn't occur
513 /// while another thread is attempting to access the registry. Typically
514 /// this is done by initializing all targets at program startup.
516 /// @param T - The target being registered.
517 /// @param Fn - A function to construct a TargetMachine for the target.
518 static void RegisterTargetMachine(Target &T,
519 Target::TargetMachineCtorTy Fn) {
520 // Ignore duplicate registration.
521 if (!T.TargetMachineCtorFn)
522 T.TargetMachineCtorFn = Fn;
525 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
528 /// Clients are responsible for ensuring that registration doesn't occur
529 /// while another thread is attempting to access the registry. Typically
530 /// this is done by initializing all targets at program startup.
532 /// @param T - The target being registered.
533 /// @param Fn - A function to construct an AsmBackend for the target.
534 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
535 if (!T.AsmBackendCtorFn)
536 T.AsmBackendCtorFn = Fn;
539 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
542 /// Clients are responsible for ensuring that registration doesn't occur
543 /// while another thread is attempting to access the registry. Typically
544 /// this is done by initializing all targets at program startup.
546 /// @param T - The target being registered.
547 /// @param Fn - A function to construct an AsmLexer for the target.
548 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
549 if (!T.AsmLexerCtorFn)
550 T.AsmLexerCtorFn = Fn;
553 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
556 /// Clients are responsible for ensuring that registration doesn't occur
557 /// while another thread is attempting to access the registry. Typically
558 /// this is done by initializing all targets at program startup.
560 /// @param T - The target being registered.
561 /// @param Fn - A function to construct an AsmParser for the target.
562 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
563 if (!T.AsmParserCtorFn)
564 T.AsmParserCtorFn = Fn;
567 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
570 /// Clients are responsible for ensuring that registration doesn't occur
571 /// while another thread is attempting to access the registry. Typically
572 /// this is done by initializing all targets at program startup.
574 /// @param T - The target being registered.
575 /// @param Fn - A function to construct an AsmPrinter for the target.
576 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
577 // Ignore duplicate registration.
578 if (!T.AsmPrinterCtorFn)
579 T.AsmPrinterCtorFn = Fn;
582 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
583 /// the given target.
585 /// Clients are responsible for ensuring that registration doesn't occur
586 /// while another thread is attempting to access the registry. Typically
587 /// this is done by initializing all targets at program startup.
589 /// @param T - The target being registered.
590 /// @param Fn - A function to construct an MCDisassembler for the target.
591 static void RegisterMCDisassembler(Target &T,
592 Target::MCDisassemblerCtorTy Fn) {
593 if (!T.MCDisassemblerCtorFn)
594 T.MCDisassemblerCtorFn = Fn;
597 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
600 /// Clients are responsible for ensuring that registration doesn't occur
601 /// while another thread is attempting to access the registry. Typically
602 /// this is done by initializing all targets at program startup.
604 /// @param T - The target being registered.
605 /// @param Fn - A function to construct an MCInstPrinter for the target.
606 static void RegisterMCInstPrinter(Target &T,
607 Target::MCInstPrinterCtorTy Fn) {
608 if (!T.MCInstPrinterCtorFn)
609 T.MCInstPrinterCtorFn = Fn;
612 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
615 /// Clients are responsible for ensuring that registration doesn't occur
616 /// while another thread is attempting to access the registry. Typically
617 /// this is done by initializing all targets at program startup.
619 /// @param T - The target being registered.
620 /// @param Fn - A function to construct an MCCodeEmitter for the target.
621 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
622 if (!T.CodeEmitterCtorFn)
623 T.CodeEmitterCtorFn = Fn;
626 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
627 /// for the given target.
629 /// Clients are responsible for ensuring that registration doesn't occur
630 /// while another thread is attempting to access the registry. Typically
631 /// this is done by initializing all targets at program startup.
633 /// @param T - The target being registered.
634 /// @param Fn - A function to construct an MCStreamer for the target.
635 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
636 if (!T.ObjectStreamerCtorFn)
637 T.ObjectStreamerCtorFn = Fn;
640 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
641 /// for the given target.
643 /// Clients are responsible for ensuring that registration doesn't occur
644 /// while another thread is attempting to access the registry. Typically
645 /// this is done by initializing all targets at program startup.
647 /// @param T - The target being registered.
648 /// @param Fn - A function to construct an MCStreamer for the target.
649 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
650 if (T.AsmStreamerCtorFn == createAsmStreamer)
651 T.AsmStreamerCtorFn = Fn;
658 //===--------------------------------------------------------------------===//
660 /// RegisterTarget - Helper template for registering a target, for use in the
661 /// target's initialization function. Usage:
664 /// Target TheFooTarget; // The global target instance.
666 /// extern "C" void LLVMInitializeFooTargetInfo() {
667 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
669 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
671 struct RegisterTarget {
672 RegisterTarget(Target &T, const char *Name, const char *Desc) {
673 TargetRegistry::RegisterTarget(T, Name, Desc,
674 &getTripleMatchQuality,
678 static unsigned getTripleMatchQuality(const std::string &TT) {
679 if (Triple(TT).getArch() == TargetArchType)
685 /// RegisterAsmInfo - Helper template for registering a target assembly info
686 /// implementation. This invokes the static "Create" method on the class to
687 /// actually do the construction. Usage:
689 /// extern "C" void LLVMInitializeFooTarget() {
690 /// extern Target TheFooTarget;
691 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
693 template<class MCAsmInfoImpl>
694 struct RegisterAsmInfo {
695 RegisterAsmInfo(Target &T) {
696 TargetRegistry::RegisterAsmInfo(T, &Allocator);
699 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
700 return new MCAsmInfoImpl(T, TT);
705 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
706 /// implementation. This invokes the specified function to do the
707 /// construction. Usage:
709 /// extern "C" void LLVMInitializeFooTarget() {
710 /// extern Target TheFooTarget;
711 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
713 struct RegisterAsmInfoFn {
714 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
715 TargetRegistry::RegisterAsmInfo(T, Fn);
719 /// RegisterMCInstrInfo - Helper template for registering a target instruction
720 /// info implementation. This invokes the static "Create" method on the class
721 /// to actually do the construction. Usage:
723 /// extern "C" void LLVMInitializeFooTarget() {
724 /// extern Target TheFooTarget;
725 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
727 template<class MCInstrInfoImpl>
728 struct RegisterMCInstrInfo {
729 RegisterMCInstrInfo(Target &T) {
730 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
733 static MCInstrInfo *Allocator() {
734 return new MCInstrInfoImpl();
738 /// RegisterMCInstrInfoFn - Helper template for registering a target
739 /// instruction info implementation. This invokes the specified function to
740 /// do the construction. Usage:
742 /// extern "C" void LLVMInitializeFooTarget() {
743 /// extern Target TheFooTarget;
744 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
746 struct RegisterMCInstrInfoFn {
747 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
748 TargetRegistry::RegisterMCInstrInfo(T, Fn);
752 /// RegisterMCRegInfo - Helper template for registering a target register info
753 /// implementation. This invokes the static "Create" method on the class to
754 /// actually do the construction. Usage:
756 /// extern "C" void LLVMInitializeFooTarget() {
757 /// extern Target TheFooTarget;
758 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
760 template<class MCRegisterInfoImpl>
761 struct RegisterMCRegInfo {
762 RegisterMCRegInfo(Target &T) {
763 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
766 static MCRegisterInfo *Allocator() {
767 return new MCRegisterInfoImpl();
771 /// RegisterMCRegInfoFn - Helper template for registering a target register
772 /// info implementation. This invokes the specified function to do the
773 /// construction. Usage:
775 /// extern "C" void LLVMInitializeFooTarget() {
776 /// extern Target TheFooTarget;
777 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
779 struct RegisterMCRegInfoFn {
780 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
781 TargetRegistry::RegisterMCRegInfo(T, Fn);
785 /// RegisterTargetMachine - Helper template for registering a target machine
786 /// implementation, for use in the target machine initialization
789 /// extern "C" void LLVMInitializeFooTarget() {
790 /// extern Target TheFooTarget;
791 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
793 template<class TargetMachineImpl>
794 struct RegisterTargetMachine {
795 RegisterTargetMachine(Target &T) {
796 TargetRegistry::RegisterTargetMachine(T, &Allocator);
800 static TargetMachine *Allocator(const Target &T, const std::string &TT,
801 const std::string &CPU,
802 const std::string &FS) {
803 return new TargetMachineImpl(T, TT, CPU, FS);
807 /// RegisterAsmBackend - Helper template for registering a target specific
808 /// assembler backend. Usage:
810 /// extern "C" void LLVMInitializeFooAsmBackend() {
811 /// extern Target TheFooTarget;
812 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
814 template<class AsmBackendImpl>
815 struct RegisterAsmBackend {
816 RegisterAsmBackend(Target &T) {
817 TargetRegistry::RegisterAsmBackend(T, &Allocator);
821 static TargetAsmBackend *Allocator(const Target &T,
822 const std::string &Triple) {
823 return new AsmBackendImpl(T, Triple);
827 /// RegisterAsmLexer - Helper template for registering a target specific
828 /// assembly lexer, for use in the target machine initialization
831 /// extern "C" void LLVMInitializeFooAsmLexer() {
832 /// extern Target TheFooTarget;
833 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
835 template<class AsmLexerImpl>
836 struct RegisterAsmLexer {
837 RegisterAsmLexer(Target &T) {
838 TargetRegistry::RegisterAsmLexer(T, &Allocator);
842 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
843 return new AsmLexerImpl(T, MAI);
847 /// RegisterAsmParser - Helper template for registering a target specific
848 /// assembly parser, for use in the target machine initialization
851 /// extern "C" void LLVMInitializeFooAsmParser() {
852 /// extern Target TheFooTarget;
853 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
855 template<class AsmParserImpl>
856 struct RegisterAsmParser {
857 RegisterAsmParser(Target &T) {
858 TargetRegistry::RegisterAsmParser(T, &Allocator);
862 static TargetAsmParser *Allocator(StringRef TT, StringRef CPU,
863 StringRef FS, MCAsmParser &P) {
864 return new AsmParserImpl(TT, CPU, FS, P);
868 /// RegisterAsmPrinter - Helper template for registering a target specific
869 /// assembly printer, for use in the target machine initialization
872 /// extern "C" void LLVMInitializeFooAsmPrinter() {
873 /// extern Target TheFooTarget;
874 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
876 template<class AsmPrinterImpl>
877 struct RegisterAsmPrinter {
878 RegisterAsmPrinter(Target &T) {
879 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
883 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
884 return new AsmPrinterImpl(TM, Streamer);
888 /// RegisterCodeEmitter - Helper template for registering a target specific
889 /// machine code emitter, for use in the target initialization
892 /// extern "C" void LLVMInitializeFooCodeEmitter() {
893 /// extern Target TheFooTarget;
894 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
896 template<class CodeEmitterImpl>
897 struct RegisterCodeEmitter {
898 RegisterCodeEmitter(Target &T) {
899 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
903 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
905 return new CodeEmitterImpl(T, TM, Ctx);