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"
38 class TargetAsmBackend;
40 class TargetAsmParser;
43 class formatted_raw_ostream;
45 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
47 bool useLoc, bool useCFI,
48 MCInstPrinter *InstPrint,
50 TargetAsmBackend *TAB,
53 /// Target - Wrapper for Target specific information.
55 /// For registration purposes, this is a POD type so that targets can be
56 /// registered without the use of static constructors.
58 /// Targets should implement a single global instance of this class (which
59 /// will be zero initialized), and pass that instance to the TargetRegistry as
60 /// part of their initialization.
63 friend struct TargetRegistry;
65 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
67 typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
69 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(void);
70 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
71 const std::string &TT,
72 const std::string &Features);
73 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
74 MCStreamer &Streamer);
75 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
76 const std::string &TT);
77 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
78 const MCAsmInfo &MAI);
79 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
81 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
82 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
84 unsigned SyntaxVariant,
85 const MCAsmInfo &MAI);
86 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
89 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
90 const std::string &TT,
92 TargetAsmBackend &TAB,
94 MCCodeEmitter *_Emitter,
97 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
98 formatted_raw_ostream &OS,
102 MCInstPrinter *InstPrint,
104 TargetAsmBackend *TAB,
108 /// Next - The next registered target in the linked list, maintained by the
112 /// TripleMatchQualityFn - The target function for rating the match quality
114 TripleMatchQualityFnTy TripleMatchQualityFn;
116 /// Name - The target name.
119 /// ShortDesc - A short description of the target.
120 const char *ShortDesc;
122 /// HasJIT - Whether this target supports the JIT.
125 /// AsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
127 AsmInfoCtorFnTy AsmInfoCtorFn;
129 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
131 MCRegInfoCtorFnTy MCRegInfoCtorFn;
133 /// TargetMachineCtorFn - Construction function for this target's
134 /// TargetMachine, if registered.
135 TargetMachineCtorTy TargetMachineCtorFn;
137 /// AsmBackendCtorFn - Construction function for this target's
138 /// TargetAsmBackend, if registered.
139 AsmBackendCtorTy AsmBackendCtorFn;
141 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
143 AsmLexerCtorTy AsmLexerCtorFn;
145 /// AsmParserCtorFn - Construction function for this target's
146 /// TargetAsmParser, if registered.
147 AsmParserCtorTy AsmParserCtorFn;
149 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
151 AsmPrinterCtorTy AsmPrinterCtorFn;
153 /// MCDisassemblerCtorFn - Construction function for this target's
154 /// MCDisassembler, if registered.
155 MCDisassemblerCtorTy MCDisassemblerCtorFn;
157 /// MCInstPrinterCtorFn - Construction function for this target's
158 /// MCInstPrinter, if registered.
159 MCInstPrinterCtorTy MCInstPrinterCtorFn;
161 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
163 CodeEmitterCtorTy CodeEmitterCtorFn;
165 /// ObjectStreamerCtorFn - Construction function for this target's
166 /// ObjectStreamer, if registered.
167 ObjectStreamerCtorTy ObjectStreamerCtorFn;
169 /// AsmStreamerCtorFn - Construction function for this target's
170 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
171 AsmStreamerCtorTy AsmStreamerCtorFn;
174 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
176 /// @name Target Information
179 // getNext - Return the next registered target.
180 const Target *getNext() const { return Next; }
182 /// getName - Get the target name.
183 const char *getName() const { return Name; }
185 /// getShortDescription - Get a short description of the target.
186 const char *getShortDescription() const { return ShortDesc; }
189 /// @name Feature Predicates
192 /// hasJIT - Check if this targets supports the just-in-time compilation.
193 bool hasJIT() const { return HasJIT; }
195 /// hasTargetMachine - Check if this target supports code generation.
196 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
198 /// hasAsmBackend - Check if this target supports .o generation.
199 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
201 /// hasAsmLexer - Check if this target supports .s lexing.
202 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
204 /// hasAsmParser - Check if this target supports .s parsing.
205 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
207 /// hasAsmPrinter - Check if this target supports .s printing.
208 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
210 /// hasMCDisassembler - Check if this target has a disassembler.
211 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
213 /// hasMCInstPrinter - Check if this target has an instruction printer.
214 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
216 /// hasCodeEmitter - Check if this target supports instruction encoding.
217 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
219 /// hasObjectStreamer - Check if this target supports streaming to files.
220 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
222 /// hasAsmStreamer - Check if this target supports streaming to files.
223 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
226 /// @name Feature Constructors
229 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
232 /// \arg Triple - This argument is used to determine the target machine
233 /// feature set; it should always be provided. Generally this should be
234 /// either the target triple from the module, or the target triple of the
235 /// host if that does not exist.
236 MCAsmInfo *createAsmInfo(StringRef Triple) const {
239 return AsmInfoCtorFn(*this, Triple);
242 /// createMCRegInfo - Create a MCRegisterInfo implementation.
244 MCRegisterInfo *createMCRegInfo() const {
245 if (!MCRegInfoCtorFn)
247 return MCRegInfoCtorFn();
250 /// createTargetMachine - Create a target specific machine implementation
251 /// for the specified \arg Triple.
253 /// \arg Triple - This argument is used to determine the target machine
254 /// feature set; it should always be provided. Generally this should be
255 /// either the target triple from the module, or the target triple of the
256 /// host if that does not exist.
257 TargetMachine *createTargetMachine(const std::string &Triple,
258 const std::string &Features) const {
259 if (!TargetMachineCtorFn)
261 return TargetMachineCtorFn(*this, Triple, Features);
264 /// createAsmBackend - Create a target specific assembly parser.
266 /// \arg Triple - The target triple string.
267 /// \arg Backend - The target independent assembler object.
268 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
269 if (!AsmBackendCtorFn)
271 return AsmBackendCtorFn(*this, Triple);
274 /// createAsmLexer - Create a target specific assembly lexer.
276 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
279 return AsmLexerCtorFn(*this, MAI);
282 /// createAsmParser - Create a target specific assembly parser.
284 /// \arg Parser - The target independent parser implementation to use for
285 /// parsing and lexing.
286 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
287 TargetMachine &TM) const {
288 if (!AsmParserCtorFn)
290 return AsmParserCtorFn(*this, Parser, TM);
293 /// createAsmPrinter - Create a target specific assembly printer pass. This
294 /// takes ownership of the MCStreamer object.
295 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
296 if (!AsmPrinterCtorFn)
298 return AsmPrinterCtorFn(TM, Streamer);
301 MCDisassembler *createMCDisassembler() const {
302 if (!MCDisassemblerCtorFn)
304 return MCDisassemblerCtorFn(*this);
307 MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
308 unsigned SyntaxVariant,
309 const MCAsmInfo &MAI) const {
310 if (!MCInstPrinterCtorFn)
312 return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
316 /// createCodeEmitter - Create a target specific code emitter.
317 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
318 if (!CodeEmitterCtorFn)
320 return CodeEmitterCtorFn(*this, TM, Ctx);
323 /// createObjectStreamer - Create a target specific MCStreamer.
325 /// \arg TT - The target triple.
326 /// \arg Ctx - The target context.
327 /// \arg TAB - The target assembler backend object. Takes ownership.
328 /// \arg _OS - The stream object.
329 /// \arg _Emitter - The target independent assembler object.Takes ownership.
330 /// \arg RelaxAll - Relax all fixups?
331 /// \arg NoExecStack - Mark file as not needing a executable stack.
332 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
333 TargetAsmBackend &TAB,
335 MCCodeEmitter *_Emitter,
337 bool NoExecStack) const {
338 if (!ObjectStreamerCtorFn)
340 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
344 /// createAsmStreamer - Create a target specific MCStreamer.
345 MCStreamer *createAsmStreamer(MCContext &Ctx,
346 formatted_raw_ostream &OS,
350 MCInstPrinter *InstPrint,
352 TargetAsmBackend *TAB,
353 bool ShowInst) const {
354 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
355 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
356 InstPrint, CE, TAB, ShowInst);
362 /// TargetRegistry - Generic interface to target specific features.
363 struct TargetRegistry {
365 const Target *Current;
366 explicit iterator(Target *T) : Current(T) {}
367 friend struct TargetRegistry;
369 iterator(const iterator &I) : Current(I.Current) {}
370 iterator() : Current(0) {}
372 bool operator==(const iterator &x) const {
373 return Current == x.Current;
375 bool operator!=(const iterator &x) const {
376 return !operator==(x);
379 // Iterator traversal: forward iteration only
380 iterator &operator++() { // Preincrement
381 assert(Current && "Cannot increment end iterator!");
382 Current = Current->getNext();
385 iterator operator++(int) { // Postincrement
386 iterator tmp = *this;
391 const Target &operator*() const {
392 assert(Current && "Cannot dereference end iterator!");
396 const Target *operator->() const {
401 /// @name Registry Access
404 static iterator begin();
406 static iterator end() { return iterator(); }
408 /// lookupTarget - Lookup a target based on a target triple.
410 /// \param Triple - The triple to use for finding a target.
411 /// \param Error - On failure, an error string describing why no target was
413 static const Target *lookupTarget(const std::string &Triple,
416 /// getClosestTargetForJIT - Pick the best target that is compatible with
417 /// the current host. If no close target can be found, this returns null
418 /// and sets the Error string to a reason.
420 /// Maintained for compatibility through 2.6.
421 static const Target *getClosestTargetForJIT(std::string &Error);
424 /// @name Target Registration
427 /// RegisterTarget - Register the given target. Attempts to register a
428 /// target which has already been registered will be ignored.
430 /// Clients are responsible for ensuring that registration doesn't occur
431 /// while another thread is attempting to access the registry. Typically
432 /// this is done by initializing all targets at program startup.
434 /// @param T - The target being registered.
435 /// @param Name - The target name. This should be a static string.
436 /// @param ShortDesc - A short target description. This should be a static
438 /// @param TQualityFn - The triple match quality computation function for
440 /// @param HasJIT - Whether the target supports JIT code
442 static void RegisterTarget(Target &T,
444 const char *ShortDesc,
445 Target::TripleMatchQualityFnTy TQualityFn,
446 bool HasJIT = false);
448 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
451 /// Clients are responsible for ensuring that registration doesn't occur
452 /// while another thread is attempting to access the registry. Typically
453 /// this is done by initializing all targets at program startup.
455 /// @param T - The target being registered.
456 /// @param Fn - A function to construct a MCAsmInfo for the target.
457 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
458 // Ignore duplicate registration.
459 if (!T.AsmInfoCtorFn)
460 T.AsmInfoCtorFn = Fn;
463 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
466 /// Clients are responsible for ensuring that registration doesn't occur
467 /// while another thread is attempting to access the registry. Typically
468 /// this is done by initializing all targets at program startup.
470 /// @param T - The target being registered.
471 /// @param Fn - A function to construct a MCRegisterInfo for the target.
472 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
473 // Ignore duplicate registration.
474 if (!T.MCRegInfoCtorFn)
475 T.MCRegInfoCtorFn = Fn;
478 /// RegisterTargetMachine - Register a TargetMachine implementation for the
481 /// Clients are responsible for ensuring that registration doesn't occur
482 /// while another thread is attempting to access the registry. Typically
483 /// this is done by initializing all targets at program startup.
485 /// @param T - The target being registered.
486 /// @param Fn - A function to construct a TargetMachine for the target.
487 static void RegisterTargetMachine(Target &T,
488 Target::TargetMachineCtorTy Fn) {
489 // Ignore duplicate registration.
490 if (!T.TargetMachineCtorFn)
491 T.TargetMachineCtorFn = Fn;
494 /// RegisterAsmBackend - Register a TargetAsmBackend 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 an AsmBackend for the target.
503 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
504 if (!T.AsmBackendCtorFn)
505 T.AsmBackendCtorFn = Fn;
508 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
511 /// Clients are responsible for ensuring that registration doesn't occur
512 /// while another thread is attempting to access the registry. Typically
513 /// this is done by initializing all targets at program startup.
515 /// @param T - The target being registered.
516 /// @param Fn - A function to construct an AsmLexer for the target.
517 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
518 if (!T.AsmLexerCtorFn)
519 T.AsmLexerCtorFn = Fn;
522 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
525 /// Clients are responsible for ensuring that registration doesn't occur
526 /// while another thread is attempting to access the registry. Typically
527 /// this is done by initializing all targets at program startup.
529 /// @param T - The target being registered.
530 /// @param Fn - A function to construct an AsmParser for the target.
531 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
532 if (!T.AsmParserCtorFn)
533 T.AsmParserCtorFn = Fn;
536 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
539 /// Clients are responsible for ensuring that registration doesn't occur
540 /// while another thread is attempting to access the registry. Typically
541 /// this is done by initializing all targets at program startup.
543 /// @param T - The target being registered.
544 /// @param Fn - A function to construct an AsmPrinter for the target.
545 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
546 // Ignore duplicate registration.
547 if (!T.AsmPrinterCtorFn)
548 T.AsmPrinterCtorFn = Fn;
551 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
552 /// the given target.
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 MCDisassembler for the target.
560 static void RegisterMCDisassembler(Target &T,
561 Target::MCDisassemblerCtorTy Fn) {
562 if (!T.MCDisassemblerCtorFn)
563 T.MCDisassemblerCtorFn = Fn;
566 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
569 /// Clients are responsible for ensuring that registration doesn't occur
570 /// while another thread is attempting to access the registry. Typically
571 /// this is done by initializing all targets at program startup.
573 /// @param T - The target being registered.
574 /// @param Fn - A function to construct an MCInstPrinter for the target.
575 static void RegisterMCInstPrinter(Target &T,
576 Target::MCInstPrinterCtorTy Fn) {
577 if (!T.MCInstPrinterCtorFn)
578 T.MCInstPrinterCtorFn = Fn;
581 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
584 /// Clients are responsible for ensuring that registration doesn't occur
585 /// while another thread is attempting to access the registry. Typically
586 /// this is done by initializing all targets at program startup.
588 /// @param T - The target being registered.
589 /// @param Fn - A function to construct an MCCodeEmitter for the target.
590 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
591 if (!T.CodeEmitterCtorFn)
592 T.CodeEmitterCtorFn = Fn;
595 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
596 /// for the given target.
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 MCStreamer for the target.
604 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
605 if (!T.ObjectStreamerCtorFn)
606 T.ObjectStreamerCtorFn = Fn;
609 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
610 /// for the given target.
612 /// Clients are responsible for ensuring that registration doesn't occur
613 /// while another thread is attempting to access the registry. Typically
614 /// this is done by initializing all targets at program startup.
616 /// @param T - The target being registered.
617 /// @param Fn - A function to construct an MCStreamer for the target.
618 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
619 if (T.AsmStreamerCtorFn == createAsmStreamer)
620 T.AsmStreamerCtorFn = Fn;
627 //===--------------------------------------------------------------------===//
629 /// RegisterTarget - Helper template for registering a target, for use in the
630 /// target's initialization function. Usage:
633 /// Target TheFooTarget; // The global target instance.
635 /// extern "C" void LLVMInitializeFooTargetInfo() {
636 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
638 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
640 struct RegisterTarget {
641 RegisterTarget(Target &T, const char *Name, const char *Desc) {
642 TargetRegistry::RegisterTarget(T, Name, Desc,
643 &getTripleMatchQuality,
647 static unsigned getTripleMatchQuality(const std::string &TT) {
648 if (Triple(TT).getArch() == TargetArchType)
654 /// RegisterAsmInfo - Helper template for registering a target assembly info
655 /// implementation. This invokes the static "Create" method on the class to
656 /// actually do the construction. Usage:
658 /// extern "C" void LLVMInitializeFooTarget() {
659 /// extern Target TheFooTarget;
660 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
662 template<class MCAsmInfoImpl>
663 struct RegisterAsmInfo {
664 RegisterAsmInfo(Target &T) {
665 TargetRegistry::RegisterAsmInfo(T, &Allocator);
668 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
669 return new MCAsmInfoImpl(T, TT);
674 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
675 /// implementation. This invokes the specified function to do the
676 /// construction. Usage:
678 /// extern "C" void LLVMInitializeFooTarget() {
679 /// extern Target TheFooTarget;
680 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
682 struct RegisterAsmInfoFn {
683 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
684 TargetRegistry::RegisterAsmInfo(T, Fn);
688 /// RegisterMCRegInfo - Helper template for registering a target register info
689 /// implementation. This invokes the static "Create" method on the class to
690 /// actually do the construction. Usage:
692 /// extern "C" void LLVMInitializeFooTarget() {
693 /// extern Target TheFooTarget;
694 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
696 template<class MCRegisterInfoImpl>
697 struct RegisterMCRegInfo {
698 RegisterMCRegInfo(Target &T) {
699 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
702 static MCRegisterInfo *Allocator() {
703 return new MCRegisterInfoImpl();
707 /// RegisterMCRegInfoFn - Helper template for registering a target register
708 /// info implementation. This invokes the specified function to do the
709 /// construction. Usage:
711 /// extern "C" void LLVMInitializeFooTarget() {
712 /// extern Target TheFooTarget;
713 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
715 struct RegisterMCRegInfoFn {
716 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
717 TargetRegistry::RegisterMCRegInfo(T, Fn);
721 /// RegisterTargetMachine - Helper template for registering a target machine
722 /// implementation, for use in the target machine initialization
725 /// extern "C" void LLVMInitializeFooTarget() {
726 /// extern Target TheFooTarget;
727 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
729 template<class TargetMachineImpl>
730 struct RegisterTargetMachine {
731 RegisterTargetMachine(Target &T) {
732 TargetRegistry::RegisterTargetMachine(T, &Allocator);
736 static TargetMachine *Allocator(const Target &T, const std::string &TT,
737 const std::string &FS) {
738 return new TargetMachineImpl(T, TT, FS);
742 /// RegisterAsmBackend - Helper template for registering a target specific
743 /// assembler backend. Usage:
745 /// extern "C" void LLVMInitializeFooAsmBackend() {
746 /// extern Target TheFooTarget;
747 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
749 template<class AsmBackendImpl>
750 struct RegisterAsmBackend {
751 RegisterAsmBackend(Target &T) {
752 TargetRegistry::RegisterAsmBackend(T, &Allocator);
756 static TargetAsmBackend *Allocator(const Target &T,
757 const std::string &Triple) {
758 return new AsmBackendImpl(T, Triple);
762 /// RegisterAsmLexer - Helper template for registering a target specific
763 /// assembly lexer, for use in the target machine initialization
766 /// extern "C" void LLVMInitializeFooAsmLexer() {
767 /// extern Target TheFooTarget;
768 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
770 template<class AsmLexerImpl>
771 struct RegisterAsmLexer {
772 RegisterAsmLexer(Target &T) {
773 TargetRegistry::RegisterAsmLexer(T, &Allocator);
777 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
778 return new AsmLexerImpl(T, MAI);
782 /// RegisterAsmParser - Helper template for registering a target specific
783 /// assembly parser, for use in the target machine initialization
786 /// extern "C" void LLVMInitializeFooAsmParser() {
787 /// extern Target TheFooTarget;
788 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
790 template<class AsmParserImpl>
791 struct RegisterAsmParser {
792 RegisterAsmParser(Target &T) {
793 TargetRegistry::RegisterAsmParser(T, &Allocator);
797 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
799 return new AsmParserImpl(T, P, TM);
803 /// RegisterAsmPrinter - Helper template for registering a target specific
804 /// assembly printer, for use in the target machine initialization
807 /// extern "C" void LLVMInitializeFooAsmPrinter() {
808 /// extern Target TheFooTarget;
809 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
811 template<class AsmPrinterImpl>
812 struct RegisterAsmPrinter {
813 RegisterAsmPrinter(Target &T) {
814 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
818 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
819 return new AsmPrinterImpl(TM, Streamer);
823 /// RegisterCodeEmitter - Helper template for registering a target specific
824 /// machine code emitter, for use in the target initialization
827 /// extern "C" void LLVMInitializeFooCodeEmitter() {
828 /// extern Target TheFooTarget;
829 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
831 template<class CodeEmitterImpl>
832 struct RegisterCodeEmitter {
833 RegisterCodeEmitter(Target &T) {
834 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
838 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
840 return new CodeEmitterImpl(T, TM, Ctx);