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 &Features);
75 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
76 MCStreamer &Streamer);
77 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
78 const std::string &TT);
79 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
80 const MCAsmInfo &MAI);
81 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
83 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
84 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
86 unsigned SyntaxVariant,
87 const MCAsmInfo &MAI);
88 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
91 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
92 const std::string &TT,
94 TargetAsmBackend &TAB,
96 MCCodeEmitter *_Emitter,
99 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
100 formatted_raw_ostream &OS,
104 MCInstPrinter *InstPrint,
106 TargetAsmBackend *TAB,
110 /// Next - The next registered target in the linked list, maintained by the
114 /// TripleMatchQualityFn - The target function for rating the match quality
116 TripleMatchQualityFnTy TripleMatchQualityFn;
118 /// Name - The target name.
121 /// ShortDesc - A short description of the target.
122 const char *ShortDesc;
124 /// HasJIT - Whether this target supports the JIT.
127 /// AsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
129 AsmInfoCtorFnTy AsmInfoCtorFn;
131 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
133 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
135 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
137 MCRegInfoCtorFnTy MCRegInfoCtorFn;
139 /// TargetMachineCtorFn - Construction function for this target's
140 /// TargetMachine, if registered.
141 TargetMachineCtorTy TargetMachineCtorFn;
143 /// AsmBackendCtorFn - Construction function for this target's
144 /// TargetAsmBackend, if registered.
145 AsmBackendCtorTy AsmBackendCtorFn;
147 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
149 AsmLexerCtorTy AsmLexerCtorFn;
151 /// AsmParserCtorFn - Construction function for this target's
152 /// TargetAsmParser, if registered.
153 AsmParserCtorTy AsmParserCtorFn;
155 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
157 AsmPrinterCtorTy AsmPrinterCtorFn;
159 /// MCDisassemblerCtorFn - Construction function for this target's
160 /// MCDisassembler, if registered.
161 MCDisassemblerCtorTy MCDisassemblerCtorFn;
163 /// MCInstPrinterCtorFn - Construction function for this target's
164 /// MCInstPrinter, if registered.
165 MCInstPrinterCtorTy MCInstPrinterCtorFn;
167 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
169 CodeEmitterCtorTy CodeEmitterCtorFn;
171 /// ObjectStreamerCtorFn - Construction function for this target's
172 /// ObjectStreamer, if registered.
173 ObjectStreamerCtorTy ObjectStreamerCtorFn;
175 /// AsmStreamerCtorFn - Construction function for this target's
176 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
177 AsmStreamerCtorTy AsmStreamerCtorFn;
180 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
182 /// @name Target Information
185 // getNext - Return the next registered target.
186 const Target *getNext() const { return Next; }
188 /// getName - Get the target name.
189 const char *getName() const { return Name; }
191 /// getShortDescription - Get a short description of the target.
192 const char *getShortDescription() const { return ShortDesc; }
195 /// @name Feature Predicates
198 /// hasJIT - Check if this targets supports the just-in-time compilation.
199 bool hasJIT() const { return HasJIT; }
201 /// hasTargetMachine - Check if this target supports code generation.
202 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
204 /// hasAsmBackend - Check if this target supports .o generation.
205 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
207 /// hasAsmLexer - Check if this target supports .s lexing.
208 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
210 /// hasAsmParser - Check if this target supports .s parsing.
211 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
213 /// hasAsmPrinter - Check if this target supports .s printing.
214 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
216 /// hasMCDisassembler - Check if this target has a disassembler.
217 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
219 /// hasMCInstPrinter - Check if this target has an instruction printer.
220 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
222 /// hasCodeEmitter - Check if this target supports instruction encoding.
223 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
225 /// hasObjectStreamer - Check if this target supports streaming to files.
226 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
228 /// hasAsmStreamer - Check if this target supports streaming to files.
229 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
232 /// @name Feature Constructors
235 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
238 /// \arg Triple - This argument is used to determine the target machine
239 /// feature set; it should always be provided. Generally this should be
240 /// either the target triple from the module, or the target triple of the
241 /// host if that does not exist.
242 MCAsmInfo *createAsmInfo(StringRef Triple) const {
245 return AsmInfoCtorFn(*this, Triple);
248 /// createMCInstrInfo - Create a MCInstrInfo implementation.
250 MCInstrInfo *createMCInstrInfo() const {
251 if (!MCInstrInfoCtorFn)
253 return MCInstrInfoCtorFn();
256 /// createMCRegInfo - Create a MCRegisterInfo implementation.
258 MCRegisterInfo *createMCRegInfo() const {
259 if (!MCRegInfoCtorFn)
261 return MCRegInfoCtorFn();
264 /// createTargetMachine - Create a target specific machine implementation
265 /// for the specified \arg Triple.
267 /// \arg Triple - This argument is used to determine the target machine
268 /// feature set; it should always be provided. Generally this should be
269 /// either the target triple from the module, or the target triple of the
270 /// host if that does not exist.
271 TargetMachine *createTargetMachine(const std::string &Triple,
272 const std::string &Features) const {
273 if (!TargetMachineCtorFn)
275 return TargetMachineCtorFn(*this, Triple, Features);
278 /// createAsmBackend - Create a target specific assembly parser.
280 /// \arg Triple - The target triple string.
281 /// \arg Backend - The target independent assembler object.
282 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
283 if (!AsmBackendCtorFn)
285 return AsmBackendCtorFn(*this, Triple);
288 /// createAsmLexer - Create a target specific assembly lexer.
290 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
293 return AsmLexerCtorFn(*this, MAI);
296 /// createAsmParser - Create a target specific assembly parser.
298 /// \arg Parser - The target independent parser implementation to use for
299 /// parsing and lexing.
300 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
301 TargetMachine &TM) const {
302 if (!AsmParserCtorFn)
304 return AsmParserCtorFn(*this, Parser, TM);
307 /// createAsmPrinter - Create a target specific assembly printer pass. This
308 /// takes ownership of the MCStreamer object.
309 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
310 if (!AsmPrinterCtorFn)
312 return AsmPrinterCtorFn(TM, Streamer);
315 MCDisassembler *createMCDisassembler() const {
316 if (!MCDisassemblerCtorFn)
318 return MCDisassemblerCtorFn(*this);
321 MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
322 unsigned SyntaxVariant,
323 const MCAsmInfo &MAI) const {
324 if (!MCInstPrinterCtorFn)
326 return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
330 /// createCodeEmitter - Create a target specific code emitter.
331 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
332 if (!CodeEmitterCtorFn)
334 return CodeEmitterCtorFn(*this, TM, Ctx);
337 /// createObjectStreamer - Create a target specific MCStreamer.
339 /// \arg TT - The target triple.
340 /// \arg Ctx - The target context.
341 /// \arg TAB - The target assembler backend object. Takes ownership.
342 /// \arg _OS - The stream object.
343 /// \arg _Emitter - The target independent assembler object.Takes ownership.
344 /// \arg RelaxAll - Relax all fixups?
345 /// \arg NoExecStack - Mark file as not needing a executable stack.
346 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
347 TargetAsmBackend &TAB,
349 MCCodeEmitter *_Emitter,
351 bool NoExecStack) const {
352 if (!ObjectStreamerCtorFn)
354 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
358 /// createAsmStreamer - Create a target specific MCStreamer.
359 MCStreamer *createAsmStreamer(MCContext &Ctx,
360 formatted_raw_ostream &OS,
364 MCInstPrinter *InstPrint,
366 TargetAsmBackend *TAB,
367 bool ShowInst) const {
368 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
369 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
370 InstPrint, CE, TAB, ShowInst);
376 /// TargetRegistry - Generic interface to target specific features.
377 struct TargetRegistry {
379 const Target *Current;
380 explicit iterator(Target *T) : Current(T) {}
381 friend struct TargetRegistry;
383 iterator(const iterator &I) : Current(I.Current) {}
384 iterator() : Current(0) {}
386 bool operator==(const iterator &x) const {
387 return Current == x.Current;
389 bool operator!=(const iterator &x) const {
390 return !operator==(x);
393 // Iterator traversal: forward iteration only
394 iterator &operator++() { // Preincrement
395 assert(Current && "Cannot increment end iterator!");
396 Current = Current->getNext();
399 iterator operator++(int) { // Postincrement
400 iterator tmp = *this;
405 const Target &operator*() const {
406 assert(Current && "Cannot dereference end iterator!");
410 const Target *operator->() const {
415 /// @name Registry Access
418 static iterator begin();
420 static iterator end() { return iterator(); }
422 /// lookupTarget - Lookup a target based on a target triple.
424 /// \param Triple - The triple to use for finding a target.
425 /// \param Error - On failure, an error string describing why no target was
427 static const Target *lookupTarget(const std::string &Triple,
430 /// getClosestTargetForJIT - Pick the best target that is compatible with
431 /// the current host. If no close target can be found, this returns null
432 /// and sets the Error string to a reason.
434 /// Maintained for compatibility through 2.6.
435 static const Target *getClosestTargetForJIT(std::string &Error);
438 /// @name Target Registration
441 /// RegisterTarget - Register the given target. Attempts to register a
442 /// target which has already been registered will be ignored.
444 /// Clients are responsible for ensuring that registration doesn't occur
445 /// while another thread is attempting to access the registry. Typically
446 /// this is done by initializing all targets at program startup.
448 /// @param T - The target being registered.
449 /// @param Name - The target name. This should be a static string.
450 /// @param ShortDesc - A short target description. This should be a static
452 /// @param TQualityFn - The triple match quality computation function for
454 /// @param HasJIT - Whether the target supports JIT code
456 static void RegisterTarget(Target &T,
458 const char *ShortDesc,
459 Target::TripleMatchQualityFnTy TQualityFn,
460 bool HasJIT = false);
462 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
465 /// Clients are responsible for ensuring that registration doesn't occur
466 /// while another thread is attempting to access the registry. Typically
467 /// this is done by initializing all targets at program startup.
469 /// @param T - The target being registered.
470 /// @param Fn - A function to construct a MCAsmInfo for the target.
471 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
472 // Ignore duplicate registration.
473 if (!T.AsmInfoCtorFn)
474 T.AsmInfoCtorFn = Fn;
477 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
480 /// Clients are responsible for ensuring that registration doesn't occur
481 /// while another thread is attempting to access the registry. Typically
482 /// this is done by initializing all targets at program startup.
484 /// @param T - The target being registered.
485 /// @param Fn - A function to construct a MCInstrInfo for the target.
486 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
487 // Ignore duplicate registration.
488 if (!T.MCInstrInfoCtorFn)
489 T.MCInstrInfoCtorFn = Fn;
492 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
495 /// Clients are responsible for ensuring that registration doesn't occur
496 /// while another thread is attempting to access the registry. Typically
497 /// this is done by initializing all targets at program startup.
499 /// @param T - The target being registered.
500 /// @param Fn - A function to construct a MCRegisterInfo for the target.
501 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
502 // Ignore duplicate registration.
503 if (!T.MCRegInfoCtorFn)
504 T.MCRegInfoCtorFn = Fn;
507 /// RegisterTargetMachine - Register a TargetMachine implementation for the
510 /// Clients are responsible for ensuring that registration doesn't occur
511 /// while another thread is attempting to access the registry. Typically
512 /// this is done by initializing all targets at program startup.
514 /// @param T - The target being registered.
515 /// @param Fn - A function to construct a TargetMachine for the target.
516 static void RegisterTargetMachine(Target &T,
517 Target::TargetMachineCtorTy Fn) {
518 // Ignore duplicate registration.
519 if (!T.TargetMachineCtorFn)
520 T.TargetMachineCtorFn = Fn;
523 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
526 /// Clients are responsible for ensuring that registration doesn't occur
527 /// while another thread is attempting to access the registry. Typically
528 /// this is done by initializing all targets at program startup.
530 /// @param T - The target being registered.
531 /// @param Fn - A function to construct an AsmBackend for the target.
532 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
533 if (!T.AsmBackendCtorFn)
534 T.AsmBackendCtorFn = Fn;
537 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
540 /// Clients are responsible for ensuring that registration doesn't occur
541 /// while another thread is attempting to access the registry. Typically
542 /// this is done by initializing all targets at program startup.
544 /// @param T - The target being registered.
545 /// @param Fn - A function to construct an AsmLexer for the target.
546 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
547 if (!T.AsmLexerCtorFn)
548 T.AsmLexerCtorFn = Fn;
551 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
554 /// Clients are responsible for ensuring that registration doesn't occur
555 /// while another thread is attempting to access the registry. Typically
556 /// this is done by initializing all targets at program startup.
558 /// @param T - The target being registered.
559 /// @param Fn - A function to construct an AsmParser for the target.
560 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
561 if (!T.AsmParserCtorFn)
562 T.AsmParserCtorFn = Fn;
565 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
568 /// Clients are responsible for ensuring that registration doesn't occur
569 /// while another thread is attempting to access the registry. Typically
570 /// this is done by initializing all targets at program startup.
572 /// @param T - The target being registered.
573 /// @param Fn - A function to construct an AsmPrinter for the target.
574 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
575 // Ignore duplicate registration.
576 if (!T.AsmPrinterCtorFn)
577 T.AsmPrinterCtorFn = Fn;
580 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
581 /// the given target.
583 /// Clients are responsible for ensuring that registration doesn't occur
584 /// while another thread is attempting to access the registry. Typically
585 /// this is done by initializing all targets at program startup.
587 /// @param T - The target being registered.
588 /// @param Fn - A function to construct an MCDisassembler for the target.
589 static void RegisterMCDisassembler(Target &T,
590 Target::MCDisassemblerCtorTy Fn) {
591 if (!T.MCDisassemblerCtorFn)
592 T.MCDisassemblerCtorFn = Fn;
595 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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.
602 /// @param T - The target being registered.
603 /// @param Fn - A function to construct an MCInstPrinter for the target.
604 static void RegisterMCInstPrinter(Target &T,
605 Target::MCInstPrinterCtorTy Fn) {
606 if (!T.MCInstPrinterCtorFn)
607 T.MCInstPrinterCtorFn = Fn;
610 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
613 /// Clients are responsible for ensuring that registration doesn't occur
614 /// while another thread is attempting to access the registry. Typically
615 /// this is done by initializing all targets at program startup.
617 /// @param T - The target being registered.
618 /// @param Fn - A function to construct an MCCodeEmitter for the target.
619 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
620 if (!T.CodeEmitterCtorFn)
621 T.CodeEmitterCtorFn = Fn;
624 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
625 /// for the given target.
627 /// Clients are responsible for ensuring that registration doesn't occur
628 /// while another thread is attempting to access the registry. Typically
629 /// this is done by initializing all targets at program startup.
631 /// @param T - The target being registered.
632 /// @param Fn - A function to construct an MCStreamer for the target.
633 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
634 if (!T.ObjectStreamerCtorFn)
635 T.ObjectStreamerCtorFn = Fn;
638 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
639 /// for the given target.
641 /// Clients are responsible for ensuring that registration doesn't occur
642 /// while another thread is attempting to access the registry. Typically
643 /// this is done by initializing all targets at program startup.
645 /// @param T - The target being registered.
646 /// @param Fn - A function to construct an MCStreamer for the target.
647 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
648 if (T.AsmStreamerCtorFn == createAsmStreamer)
649 T.AsmStreamerCtorFn = Fn;
656 //===--------------------------------------------------------------------===//
658 /// RegisterTarget - Helper template for registering a target, for use in the
659 /// target's initialization function. Usage:
662 /// Target TheFooTarget; // The global target instance.
664 /// extern "C" void LLVMInitializeFooTargetInfo() {
665 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
667 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
669 struct RegisterTarget {
670 RegisterTarget(Target &T, const char *Name, const char *Desc) {
671 TargetRegistry::RegisterTarget(T, Name, Desc,
672 &getTripleMatchQuality,
676 static unsigned getTripleMatchQuality(const std::string &TT) {
677 if (Triple(TT).getArch() == TargetArchType)
683 /// RegisterAsmInfo - Helper template for registering a target assembly info
684 /// implementation. This invokes the static "Create" method on the class to
685 /// actually do the construction. Usage:
687 /// extern "C" void LLVMInitializeFooTarget() {
688 /// extern Target TheFooTarget;
689 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
691 template<class MCAsmInfoImpl>
692 struct RegisterAsmInfo {
693 RegisterAsmInfo(Target &T) {
694 TargetRegistry::RegisterAsmInfo(T, &Allocator);
697 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
698 return new MCAsmInfoImpl(T, TT);
703 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
704 /// implementation. This invokes the specified function to do the
705 /// construction. Usage:
707 /// extern "C" void LLVMInitializeFooTarget() {
708 /// extern Target TheFooTarget;
709 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
711 struct RegisterAsmInfoFn {
712 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
713 TargetRegistry::RegisterAsmInfo(T, Fn);
717 /// RegisterMCInstrInfo - Helper template for registering a target instruction
718 /// info implementation. This invokes the static "Create" method on the class
719 /// to actually do the construction. Usage:
721 /// extern "C" void LLVMInitializeFooTarget() {
722 /// extern Target TheFooTarget;
723 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
725 template<class MCInstrInfoImpl>
726 struct RegisterMCInstrInfo {
727 RegisterMCInstrInfo(Target &T) {
728 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
731 static MCInstrInfo *Allocator() {
732 return new MCInstrInfoImpl();
736 /// RegisterMCInstrInfoFn - Helper template for registering a target
737 /// instruction info implementation. This invokes the specified function to
738 /// do the construction. Usage:
740 /// extern "C" void LLVMInitializeFooTarget() {
741 /// extern Target TheFooTarget;
742 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
744 struct RegisterMCInstrInfoFn {
745 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
746 TargetRegistry::RegisterMCInstrInfo(T, Fn);
750 /// RegisterMCRegInfo - Helper template for registering a target register info
751 /// implementation. This invokes the static "Create" method on the class to
752 /// actually do the construction. Usage:
754 /// extern "C" void LLVMInitializeFooTarget() {
755 /// extern Target TheFooTarget;
756 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
758 template<class MCRegisterInfoImpl>
759 struct RegisterMCRegInfo {
760 RegisterMCRegInfo(Target &T) {
761 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
764 static MCRegisterInfo *Allocator() {
765 return new MCRegisterInfoImpl();
769 /// RegisterMCRegInfoFn - Helper template for registering a target register
770 /// info implementation. This invokes the specified function to do the
771 /// construction. Usage:
773 /// extern "C" void LLVMInitializeFooTarget() {
774 /// extern Target TheFooTarget;
775 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
777 struct RegisterMCRegInfoFn {
778 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
779 TargetRegistry::RegisterMCRegInfo(T, Fn);
783 /// RegisterTargetMachine - Helper template for registering a target machine
784 /// implementation, for use in the target machine initialization
787 /// extern "C" void LLVMInitializeFooTarget() {
788 /// extern Target TheFooTarget;
789 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
791 template<class TargetMachineImpl>
792 struct RegisterTargetMachine {
793 RegisterTargetMachine(Target &T) {
794 TargetRegistry::RegisterTargetMachine(T, &Allocator);
798 static TargetMachine *Allocator(const Target &T, const std::string &TT,
799 const std::string &FS) {
800 return new TargetMachineImpl(T, TT, FS);
804 /// RegisterAsmBackend - Helper template for registering a target specific
805 /// assembler backend. Usage:
807 /// extern "C" void LLVMInitializeFooAsmBackend() {
808 /// extern Target TheFooTarget;
809 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
811 template<class AsmBackendImpl>
812 struct RegisterAsmBackend {
813 RegisterAsmBackend(Target &T) {
814 TargetRegistry::RegisterAsmBackend(T, &Allocator);
818 static TargetAsmBackend *Allocator(const Target &T,
819 const std::string &Triple) {
820 return new AsmBackendImpl(T, Triple);
824 /// RegisterAsmLexer - Helper template for registering a target specific
825 /// assembly lexer, for use in the target machine initialization
828 /// extern "C" void LLVMInitializeFooAsmLexer() {
829 /// extern Target TheFooTarget;
830 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
832 template<class AsmLexerImpl>
833 struct RegisterAsmLexer {
834 RegisterAsmLexer(Target &T) {
835 TargetRegistry::RegisterAsmLexer(T, &Allocator);
839 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
840 return new AsmLexerImpl(T, MAI);
844 /// RegisterAsmParser - Helper template for registering a target specific
845 /// assembly parser, for use in the target machine initialization
848 /// extern "C" void LLVMInitializeFooAsmParser() {
849 /// extern Target TheFooTarget;
850 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
852 template<class AsmParserImpl>
853 struct RegisterAsmParser {
854 RegisterAsmParser(Target &T) {
855 TargetRegistry::RegisterAsmParser(T, &Allocator);
859 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
861 return new AsmParserImpl(T, P, TM);
865 /// RegisterAsmPrinter - Helper template for registering a target specific
866 /// assembly printer, for use in the target machine initialization
869 /// extern "C" void LLVMInitializeFooAsmPrinter() {
870 /// extern Target TheFooTarget;
871 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
873 template<class AsmPrinterImpl>
874 struct RegisterAsmPrinter {
875 RegisterAsmPrinter(Target &T) {
876 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
880 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
881 return new AsmPrinterImpl(TM, Streamer);
885 /// RegisterCodeEmitter - Helper template for registering a target specific
886 /// machine code emitter, for use in the target initialization
889 /// extern "C" void LLVMInitializeFooCodeEmitter() {
890 /// extern Target TheFooTarget;
891 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
893 template<class CodeEmitterImpl>
894 struct RegisterCodeEmitter {
895 RegisterCodeEmitter(Target &T) {
896 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
900 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
902 return new CodeEmitterImpl(T, TM, Ctx);