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 *(*RegInfoCtorFnTy)(const Target &T,
71 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
72 const std::string &TT,
73 const std::string &Features);
74 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
75 MCStreamer &Streamer);
76 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
77 const std::string &TT);
78 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
79 const MCAsmInfo &MAI);
80 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
82 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
83 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
85 unsigned SyntaxVariant,
86 const MCAsmInfo &MAI);
87 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
90 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
91 const std::string &TT,
93 TargetAsmBackend &TAB,
95 MCCodeEmitter *_Emitter,
98 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
99 formatted_raw_ostream &OS,
103 MCInstPrinter *InstPrint,
105 TargetAsmBackend *TAB,
109 /// Next - The next registered target in the linked list, maintained by the
113 /// TripleMatchQualityFn - The target function for rating the match quality
115 TripleMatchQualityFnTy TripleMatchQualityFn;
117 /// Name - The target name.
120 /// ShortDesc - A short description of the target.
121 const char *ShortDesc;
123 /// HasJIT - Whether this target supports the JIT.
126 /// AsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
128 AsmInfoCtorFnTy AsmInfoCtorFn;
130 /// RegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
132 RegInfoCtorFnTy RegInfoCtorFn;
134 /// TargetMachineCtorFn - Construction function for this target's
135 /// TargetMachine, if registered.
136 TargetMachineCtorTy TargetMachineCtorFn;
138 /// AsmBackendCtorFn - Construction function for this target's
139 /// TargetAsmBackend, if registered.
140 AsmBackendCtorTy AsmBackendCtorFn;
142 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
144 AsmLexerCtorTy AsmLexerCtorFn;
146 /// AsmParserCtorFn - Construction function for this target's
147 /// TargetAsmParser, if registered.
148 AsmParserCtorTy AsmParserCtorFn;
150 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
152 AsmPrinterCtorTy AsmPrinterCtorFn;
154 /// MCDisassemblerCtorFn - Construction function for this target's
155 /// MCDisassembler, if registered.
156 MCDisassemblerCtorTy MCDisassemblerCtorFn;
158 /// MCInstPrinterCtorFn - Construction function for this target's
159 /// MCInstPrinter, if registered.
160 MCInstPrinterCtorTy MCInstPrinterCtorFn;
162 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
164 CodeEmitterCtorTy CodeEmitterCtorFn;
166 /// ObjectStreamerCtorFn - Construction function for this target's
167 /// ObjectStreamer, if registered.
168 ObjectStreamerCtorTy ObjectStreamerCtorFn;
170 /// AsmStreamerCtorFn - Construction function for this target's
171 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
172 AsmStreamerCtorTy AsmStreamerCtorFn;
175 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
177 /// @name Target Information
180 // getNext - Return the next registered target.
181 const Target *getNext() const { return Next; }
183 /// getName - Get the target name.
184 const char *getName() const { return Name; }
186 /// getShortDescription - Get a short description of the target.
187 const char *getShortDescription() const { return ShortDesc; }
190 /// @name Feature Predicates
193 /// hasJIT - Check if this targets supports the just-in-time compilation.
194 bool hasJIT() const { return HasJIT; }
196 /// hasTargetMachine - Check if this target supports code generation.
197 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
199 /// hasAsmBackend - Check if this target supports .o generation.
200 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
202 /// hasAsmLexer - Check if this target supports .s lexing.
203 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
205 /// hasAsmParser - Check if this target supports .s parsing.
206 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
208 /// hasAsmPrinter - Check if this target supports .s printing.
209 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
211 /// hasMCDisassembler - Check if this target has a disassembler.
212 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
214 /// hasMCInstPrinter - Check if this target has an instruction printer.
215 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
217 /// hasCodeEmitter - Check if this target supports instruction encoding.
218 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
220 /// hasObjectStreamer - Check if this target supports streaming to files.
221 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
223 /// hasAsmStreamer - Check if this target supports streaming to files.
224 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
227 /// @name Feature Constructors
230 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
233 /// \arg Triple - This argument is used to determine the target machine
234 /// feature set; it should always be provided. Generally this should be
235 /// either the target triple from the module, or the target triple of the
236 /// host if that does not exist.
237 MCAsmInfo *createAsmInfo(StringRef Triple) const {
240 return AsmInfoCtorFn(*this, Triple);
243 /// createRegInfo - Create a MCRegisterInfo implementation for the specified
246 /// \arg Triple - This argument is used to determine the target machine
247 /// feature set; it should always be provided. Generally this should be
248 /// either the target triple from the module, or the target triple of the
249 /// host if that does not exist.
250 MCRegisterInfo *createRegInfo(StringRef Triple) const {
253 return RegInfoCtorFn(*this, Triple);
256 /// createTargetMachine - Create a target specific machine implementation
257 /// for the specified \arg Triple.
259 /// \arg Triple - This argument is used to determine the target machine
260 /// feature set; it should always be provided. Generally this should be
261 /// either the target triple from the module, or the target triple of the
262 /// host if that does not exist.
263 TargetMachine *createTargetMachine(const std::string &Triple,
264 const std::string &Features) const {
265 if (!TargetMachineCtorFn)
267 return TargetMachineCtorFn(*this, Triple, Features);
270 /// createAsmBackend - Create a target specific assembly parser.
272 /// \arg Triple - The target triple string.
273 /// \arg Backend - The target independent assembler object.
274 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
275 if (!AsmBackendCtorFn)
277 return AsmBackendCtorFn(*this, Triple);
280 /// createAsmLexer - Create a target specific assembly lexer.
282 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
285 return AsmLexerCtorFn(*this, MAI);
288 /// createAsmParser - Create a target specific assembly parser.
290 /// \arg Parser - The target independent parser implementation to use for
291 /// parsing and lexing.
292 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
293 TargetMachine &TM) const {
294 if (!AsmParserCtorFn)
296 return AsmParserCtorFn(*this, Parser, TM);
299 /// createAsmPrinter - Create a target specific assembly printer pass. This
300 /// takes ownership of the MCStreamer object.
301 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
302 if (!AsmPrinterCtorFn)
304 return AsmPrinterCtorFn(TM, Streamer);
307 MCDisassembler *createMCDisassembler() const {
308 if (!MCDisassemblerCtorFn)
310 return MCDisassemblerCtorFn(*this);
313 MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
314 unsigned SyntaxVariant,
315 const MCAsmInfo &MAI) const {
316 if (!MCInstPrinterCtorFn)
318 return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
322 /// createCodeEmitter - Create a target specific code emitter.
323 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
324 if (!CodeEmitterCtorFn)
326 return CodeEmitterCtorFn(*this, TM, Ctx);
329 /// createObjectStreamer - Create a target specific MCStreamer.
331 /// \arg TT - The target triple.
332 /// \arg Ctx - The target context.
333 /// \arg TAB - The target assembler backend object. Takes ownership.
334 /// \arg _OS - The stream object.
335 /// \arg _Emitter - The target independent assembler object.Takes ownership.
336 /// \arg RelaxAll - Relax all fixups?
337 /// \arg NoExecStack - Mark file as not needing a executable stack.
338 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
339 TargetAsmBackend &TAB,
341 MCCodeEmitter *_Emitter,
343 bool NoExecStack) const {
344 if (!ObjectStreamerCtorFn)
346 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
350 /// createAsmStreamer - Create a target specific MCStreamer.
351 MCStreamer *createAsmStreamer(MCContext &Ctx,
352 formatted_raw_ostream &OS,
356 MCInstPrinter *InstPrint,
358 TargetAsmBackend *TAB,
359 bool ShowInst) const {
360 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
361 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
362 InstPrint, CE, TAB, ShowInst);
368 /// TargetRegistry - Generic interface to target specific features.
369 struct TargetRegistry {
371 const Target *Current;
372 explicit iterator(Target *T) : Current(T) {}
373 friend struct TargetRegistry;
375 iterator(const iterator &I) : Current(I.Current) {}
376 iterator() : Current(0) {}
378 bool operator==(const iterator &x) const {
379 return Current == x.Current;
381 bool operator!=(const iterator &x) const {
382 return !operator==(x);
385 // Iterator traversal: forward iteration only
386 iterator &operator++() { // Preincrement
387 assert(Current && "Cannot increment end iterator!");
388 Current = Current->getNext();
391 iterator operator++(int) { // Postincrement
392 iterator tmp = *this;
397 const Target &operator*() const {
398 assert(Current && "Cannot dereference end iterator!");
402 const Target *operator->() const {
407 /// @name Registry Access
410 static iterator begin();
412 static iterator end() { return iterator(); }
414 /// lookupTarget - Lookup a target based on a target triple.
416 /// \param Triple - The triple to use for finding a target.
417 /// \param Error - On failure, an error string describing why no target was
419 static const Target *lookupTarget(const std::string &Triple,
422 /// getClosestTargetForJIT - Pick the best target that is compatible with
423 /// the current host. If no close target can be found, this returns null
424 /// and sets the Error string to a reason.
426 /// Maintained for compatibility through 2.6.
427 static const Target *getClosestTargetForJIT(std::string &Error);
430 /// @name Target Registration
433 /// RegisterTarget - Register the given target. Attempts to register a
434 /// target which has already been registered will be ignored.
436 /// Clients are responsible for ensuring that registration doesn't occur
437 /// while another thread is attempting to access the registry. Typically
438 /// this is done by initializing all targets at program startup.
440 /// @param T - The target being registered.
441 /// @param Name - The target name. This should be a static string.
442 /// @param ShortDesc - A short target description. This should be a static
444 /// @param TQualityFn - The triple match quality computation function for
446 /// @param HasJIT - Whether the target supports JIT code
448 static void RegisterTarget(Target &T,
450 const char *ShortDesc,
451 Target::TripleMatchQualityFnTy TQualityFn,
452 bool HasJIT = false);
454 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
457 /// Clients are responsible for ensuring that registration doesn't occur
458 /// while another thread is attempting to access the registry. Typically
459 /// this is done by initializing all targets at program startup.
461 /// @param T - The target being registered.
462 /// @param Fn - A function to construct a MCAsmInfo for the target.
463 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
464 // Ignore duplicate registration.
465 if (!T.AsmInfoCtorFn)
466 T.AsmInfoCtorFn = Fn;
469 /// RegisterRegInfo - Register a MCRegisterInfo implementation for the
472 /// Clients are responsible for ensuring that registration doesn't occur
473 /// while another thread is attempting to access the registry. Typically
474 /// this is done by initializing all targets at program startup.
476 /// @param T - The target being registered.
477 /// @param Fn - A function to construct a MCRegisterInfo for the target.
478 static void RegisterRegInfo(Target &T, Target::RegInfoCtorFnTy Fn) {
479 // Ignore duplicate registration.
480 if (!T.RegInfoCtorFn)
481 T.RegInfoCtorFn = Fn;
484 /// RegisterTargetMachine - Register a TargetMachine implementation for the
487 /// Clients are responsible for ensuring that registration doesn't occur
488 /// while another thread is attempting to access the registry. Typically
489 /// this is done by initializing all targets at program startup.
491 /// @param T - The target being registered.
492 /// @param Fn - A function to construct a TargetMachine for the target.
493 static void RegisterTargetMachine(Target &T,
494 Target::TargetMachineCtorTy Fn) {
495 // Ignore duplicate registration.
496 if (!T.TargetMachineCtorFn)
497 T.TargetMachineCtorFn = Fn;
500 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
503 /// Clients are responsible for ensuring that registration doesn't occur
504 /// while another thread is attempting to access the registry. Typically
505 /// this is done by initializing all targets at program startup.
507 /// @param T - The target being registered.
508 /// @param Fn - A function to construct an AsmBackend for the target.
509 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
510 if (!T.AsmBackendCtorFn)
511 T.AsmBackendCtorFn = Fn;
514 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
517 /// Clients are responsible for ensuring that registration doesn't occur
518 /// while another thread is attempting to access the registry. Typically
519 /// this is done by initializing all targets at program startup.
521 /// @param T - The target being registered.
522 /// @param Fn - A function to construct an AsmLexer for the target.
523 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
524 if (!T.AsmLexerCtorFn)
525 T.AsmLexerCtorFn = Fn;
528 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
531 /// Clients are responsible for ensuring that registration doesn't occur
532 /// while another thread is attempting to access the registry. Typically
533 /// this is done by initializing all targets at program startup.
535 /// @param T - The target being registered.
536 /// @param Fn - A function to construct an AsmParser for the target.
537 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
538 if (!T.AsmParserCtorFn)
539 T.AsmParserCtorFn = Fn;
542 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
545 /// Clients are responsible for ensuring that registration doesn't occur
546 /// while another thread is attempting to access the registry. Typically
547 /// this is done by initializing all targets at program startup.
549 /// @param T - The target being registered.
550 /// @param Fn - A function to construct an AsmPrinter for the target.
551 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
552 // Ignore duplicate registration.
553 if (!T.AsmPrinterCtorFn)
554 T.AsmPrinterCtorFn = Fn;
557 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
558 /// the given target.
560 /// Clients are responsible for ensuring that registration doesn't occur
561 /// while another thread is attempting to access the registry. Typically
562 /// this is done by initializing all targets at program startup.
564 /// @param T - The target being registered.
565 /// @param Fn - A function to construct an MCDisassembler for the target.
566 static void RegisterMCDisassembler(Target &T,
567 Target::MCDisassemblerCtorTy Fn) {
568 if (!T.MCDisassemblerCtorFn)
569 T.MCDisassemblerCtorFn = Fn;
572 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
575 /// Clients are responsible for ensuring that registration doesn't occur
576 /// while another thread is attempting to access the registry. Typically
577 /// this is done by initializing all targets at program startup.
579 /// @param T - The target being registered.
580 /// @param Fn - A function to construct an MCInstPrinter for the target.
581 static void RegisterMCInstPrinter(Target &T,
582 Target::MCInstPrinterCtorTy Fn) {
583 if (!T.MCInstPrinterCtorFn)
584 T.MCInstPrinterCtorFn = Fn;
587 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
590 /// Clients are responsible for ensuring that registration doesn't occur
591 /// while another thread is attempting to access the registry. Typically
592 /// this is done by initializing all targets at program startup.
594 /// @param T - The target being registered.
595 /// @param Fn - A function to construct an MCCodeEmitter for the target.
596 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
597 if (!T.CodeEmitterCtorFn)
598 T.CodeEmitterCtorFn = Fn;
601 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
602 /// for the given target.
604 /// Clients are responsible for ensuring that registration doesn't occur
605 /// while another thread is attempting to access the registry. Typically
606 /// this is done by initializing all targets at program startup.
608 /// @param T - The target being registered.
609 /// @param Fn - A function to construct an MCStreamer for the target.
610 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
611 if (!T.ObjectStreamerCtorFn)
612 T.ObjectStreamerCtorFn = Fn;
615 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
616 /// for the given target.
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Fn - A function to construct an MCStreamer for the target.
624 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
625 if (T.AsmStreamerCtorFn == createAsmStreamer)
626 T.AsmStreamerCtorFn = Fn;
633 //===--------------------------------------------------------------------===//
635 /// RegisterTarget - Helper template for registering a target, for use in the
636 /// target's initialization function. Usage:
639 /// Target TheFooTarget; // The global target instance.
641 /// extern "C" void LLVMInitializeFooTargetInfo() {
642 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
644 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
646 struct RegisterTarget {
647 RegisterTarget(Target &T, const char *Name, const char *Desc) {
648 TargetRegistry::RegisterTarget(T, Name, Desc,
649 &getTripleMatchQuality,
653 static unsigned getTripleMatchQuality(const std::string &TT) {
654 if (Triple(TT).getArch() == TargetArchType)
660 /// RegisterAsmInfo - Helper template for registering a target assembly info
661 /// implementation. This invokes the static "Create" method on the class to
662 /// actually do the construction. Usage:
664 /// extern "C" void LLVMInitializeFooTarget() {
665 /// extern Target TheFooTarget;
666 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
668 template<class MCAsmInfoImpl>
669 struct RegisterAsmInfo {
670 RegisterAsmInfo(Target &T) {
671 TargetRegistry::RegisterAsmInfo(T, &Allocator);
674 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
675 return new MCAsmInfoImpl(T, TT);
680 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
681 /// implementation. This invokes the specified function to do the
682 /// construction. Usage:
684 /// extern "C" void LLVMInitializeFooTarget() {
685 /// extern Target TheFooTarget;
686 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
688 struct RegisterAsmInfoFn {
689 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
690 TargetRegistry::RegisterAsmInfo(T, Fn);
695 /// RegisterTargetMachine - Helper template for registering a target machine
696 /// implementation, for use in the target machine initialization
699 /// extern "C" void LLVMInitializeFooTarget() {
700 /// extern Target TheFooTarget;
701 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
703 template<class TargetMachineImpl>
704 struct RegisterTargetMachine {
705 RegisterTargetMachine(Target &T) {
706 TargetRegistry::RegisterTargetMachine(T, &Allocator);
710 static TargetMachine *Allocator(const Target &T, const std::string &TT,
711 const std::string &FS) {
712 return new TargetMachineImpl(T, TT, FS);
716 /// RegisterAsmBackend - Helper template for registering a target specific
717 /// assembler backend. Usage:
719 /// extern "C" void LLVMInitializeFooAsmBackend() {
720 /// extern Target TheFooTarget;
721 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
723 template<class AsmBackendImpl>
724 struct RegisterAsmBackend {
725 RegisterAsmBackend(Target &T) {
726 TargetRegistry::RegisterAsmBackend(T, &Allocator);
730 static TargetAsmBackend *Allocator(const Target &T,
731 const std::string &Triple) {
732 return new AsmBackendImpl(T, Triple);
736 /// RegisterAsmLexer - Helper template for registering a target specific
737 /// assembly lexer, for use in the target machine initialization
740 /// extern "C" void LLVMInitializeFooAsmLexer() {
741 /// extern Target TheFooTarget;
742 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
744 template<class AsmLexerImpl>
745 struct RegisterAsmLexer {
746 RegisterAsmLexer(Target &T) {
747 TargetRegistry::RegisterAsmLexer(T, &Allocator);
751 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
752 return new AsmLexerImpl(T, MAI);
756 /// RegisterAsmParser - Helper template for registering a target specific
757 /// assembly parser, for use in the target machine initialization
760 /// extern "C" void LLVMInitializeFooAsmParser() {
761 /// extern Target TheFooTarget;
762 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
764 template<class AsmParserImpl>
765 struct RegisterAsmParser {
766 RegisterAsmParser(Target &T) {
767 TargetRegistry::RegisterAsmParser(T, &Allocator);
771 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
773 return new AsmParserImpl(T, P, TM);
777 /// RegisterAsmPrinter - Helper template for registering a target specific
778 /// assembly printer, for use in the target machine initialization
781 /// extern "C" void LLVMInitializeFooAsmPrinter() {
782 /// extern Target TheFooTarget;
783 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
785 template<class AsmPrinterImpl>
786 struct RegisterAsmPrinter {
787 RegisterAsmPrinter(Target &T) {
788 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
792 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
793 return new AsmPrinterImpl(TM, Streamer);
797 /// RegisterCodeEmitter - Helper template for registering a target specific
798 /// machine code emitter, for use in the target initialization
801 /// extern "C" void LLVMInitializeFooCodeEmitter() {
802 /// extern Target TheFooTarget;
803 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
805 template<class CodeEmitterImpl>
806 struct RegisterCodeEmitter {
807 RegisterCodeEmitter(Target &T) {
808 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
812 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
814 return new CodeEmitterImpl(T, TM, Ctx);