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"
37 class TargetAsmBackend;
39 class TargetAsmParser;
42 class formatted_raw_ostream;
44 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
46 bool useLoc, bool useCFI,
47 MCInstPrinter *InstPrint,
49 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 TargetMachine *(*TargetMachineCtorTy)(const Target &T,
70 const std::string &TT,
71 const std::string &Features);
72 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
73 MCStreamer &Streamer);
74 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
75 const std::string &TT);
76 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
77 const MCAsmInfo &MAI);
78 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
80 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
81 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
83 unsigned SyntaxVariant,
84 const MCAsmInfo &MAI);
85 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
88 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
89 const std::string &TT,
91 TargetAsmBackend &TAB,
93 MCCodeEmitter *_Emitter,
96 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
97 formatted_raw_ostream &OS,
101 MCInstPrinter *InstPrint,
103 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 AsmInfoCtorFnTy AsmInfoCtorFn;
127 /// TargetMachineCtorFn - Construction function for this target's
128 /// TargetMachine, if registered.
129 TargetMachineCtorTy TargetMachineCtorFn;
131 /// AsmBackendCtorFn - Construction function for this target's
132 /// TargetAsmBackend, if registered.
133 AsmBackendCtorTy AsmBackendCtorFn;
135 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
137 AsmLexerCtorTy AsmLexerCtorFn;
139 /// AsmParserCtorFn - Construction function for this target's
140 /// TargetAsmParser, if registered.
141 AsmParserCtorTy AsmParserCtorFn;
143 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
145 AsmPrinterCtorTy AsmPrinterCtorFn;
147 /// MCDisassemblerCtorFn - Construction function for this target's
148 /// MCDisassembler, if registered.
149 MCDisassemblerCtorTy MCDisassemblerCtorFn;
151 /// MCInstPrinterCtorFn - Construction function for this target's
152 /// MCInstPrinter, if registered.
153 MCInstPrinterCtorTy MCInstPrinterCtorFn;
155 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
157 CodeEmitterCtorTy CodeEmitterCtorFn;
159 /// ObjectStreamerCtorFn - Construction function for this target's
160 /// ObjectStreamer, if registered.
161 ObjectStreamerCtorTy ObjectStreamerCtorFn;
163 /// AsmStreamerCtorFn - Construction function for this target's
164 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
165 AsmStreamerCtorTy AsmStreamerCtorFn;
168 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
170 /// @name Target Information
173 // getNext - Return the next registered target.
174 const Target *getNext() const { return Next; }
176 /// getName - Get the target name.
177 const char *getName() const { return Name; }
179 /// getShortDescription - Get a short description of the target.
180 const char *getShortDescription() const { return ShortDesc; }
183 /// @name Feature Predicates
186 /// hasJIT - Check if this targets supports the just-in-time compilation.
187 bool hasJIT() const { return HasJIT; }
189 /// hasTargetMachine - Check if this target supports code generation.
190 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
192 /// hasAsmBackend - Check if this target supports .o generation.
193 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
195 /// hasAsmLexer - Check if this target supports .s lexing.
196 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
198 /// hasAsmParser - Check if this target supports .s parsing.
199 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
201 /// hasAsmPrinter - Check if this target supports .s printing.
202 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
204 /// hasMCDisassembler - Check if this target has a disassembler.
205 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
207 /// hasMCInstPrinter - Check if this target has an instruction printer.
208 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
210 /// hasCodeEmitter - Check if this target supports instruction encoding.
211 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
213 /// hasObjectStreamer - Check if this target supports streaming to files.
214 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
216 /// hasAsmStreamer - Check if this target supports streaming to files.
217 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
220 /// @name Feature Constructors
223 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
226 /// \arg Triple - This argument is used to determine the target machine
227 /// feature set; it should always be provided. Generally this should be
228 /// either the target triple from the module, or the target triple of the
229 /// host if that does not exist.
230 MCAsmInfo *createAsmInfo(StringRef Triple) const {
233 return AsmInfoCtorFn(*this, Triple);
236 /// createTargetMachine - Create a target specific machine implementation
237 /// for the specified \arg Triple.
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 TargetMachine *createTargetMachine(const std::string &Triple,
244 const std::string &Features) const {
245 if (!TargetMachineCtorFn)
247 return TargetMachineCtorFn(*this, Triple, Features);
250 /// createAsmBackend - Create a target specific assembly parser.
252 /// \arg Triple - The target triple string.
253 /// \arg Backend - The target independent assembler object.
254 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
255 if (!AsmBackendCtorFn)
257 return AsmBackendCtorFn(*this, Triple);
260 /// createAsmLexer - Create a target specific assembly lexer.
262 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
265 return AsmLexerCtorFn(*this, MAI);
268 /// createAsmParser - Create a target specific assembly parser.
270 /// \arg Parser - The target independent parser implementation to use for
271 /// parsing and lexing.
272 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
273 TargetMachine &TM) const {
274 if (!AsmParserCtorFn)
276 return AsmParserCtorFn(*this, Parser, TM);
279 /// createAsmPrinter - Create a target specific assembly printer pass. This
280 /// takes ownership of the MCStreamer object.
281 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
282 if (!AsmPrinterCtorFn)
284 return AsmPrinterCtorFn(TM, Streamer);
287 MCDisassembler *createMCDisassembler() const {
288 if (!MCDisassemblerCtorFn)
290 return MCDisassemblerCtorFn(*this);
293 MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
294 unsigned SyntaxVariant,
295 const MCAsmInfo &MAI) const {
296 if (!MCInstPrinterCtorFn)
298 return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
302 /// createCodeEmitter - Create a target specific code emitter.
303 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
304 if (!CodeEmitterCtorFn)
306 return CodeEmitterCtorFn(*this, TM, Ctx);
309 /// createObjectStreamer - Create a target specific MCStreamer.
311 /// \arg TT - The target triple.
312 /// \arg Ctx - The target context.
313 /// \arg TAB - The target assembler backend object. Takes ownership.
314 /// \arg _OS - The stream object.
315 /// \arg _Emitter - The target independent assembler object.Takes ownership.
316 /// \arg RelaxAll - Relax all fixups?
317 /// \arg NoExecStack - Mark file as not needing a executable stack.
318 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
319 TargetAsmBackend &TAB,
321 MCCodeEmitter *_Emitter,
323 bool NoExecStack) const {
324 if (!ObjectStreamerCtorFn)
326 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
330 /// createAsmStreamer - Create a target specific MCStreamer.
331 MCStreamer *createAsmStreamer(MCContext &Ctx,
332 formatted_raw_ostream &OS,
336 MCInstPrinter *InstPrint,
338 TargetAsmBackend *TAB,
340 bool DecodeLSDA) const {
341 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
342 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
343 InstPrint, CE, TAB, ShowInst, DecodeLSDA);
349 /// TargetRegistry - Generic interface to target specific features.
350 struct TargetRegistry {
352 const Target *Current;
353 explicit iterator(Target *T) : Current(T) {}
354 friend struct TargetRegistry;
356 iterator(const iterator &I) : Current(I.Current) {}
357 iterator() : Current(0) {}
359 bool operator==(const iterator &x) const {
360 return Current == x.Current;
362 bool operator!=(const iterator &x) const {
363 return !operator==(x);
366 // Iterator traversal: forward iteration only
367 iterator &operator++() { // Preincrement
368 assert(Current && "Cannot increment end iterator!");
369 Current = Current->getNext();
372 iterator operator++(int) { // Postincrement
373 iterator tmp = *this;
378 const Target &operator*() const {
379 assert(Current && "Cannot dereference end iterator!");
383 const Target *operator->() const {
388 /// @name Registry Access
391 static iterator begin();
393 static iterator end() { return iterator(); }
395 /// lookupTarget - Lookup a target based on a target triple.
397 /// \param Triple - The triple to use for finding a target.
398 /// \param Error - On failure, an error string describing why no target was
400 static const Target *lookupTarget(const std::string &Triple,
403 /// getClosestTargetForJIT - Pick the best target that is compatible with
404 /// the current host. If no close target can be found, this returns null
405 /// and sets the Error string to a reason.
407 /// Maintained for compatibility through 2.6.
408 static const Target *getClosestTargetForJIT(std::string &Error);
411 /// @name Target Registration
414 /// RegisterTarget - Register the given target. Attempts to register a
415 /// target which has already been registered will be ignored.
417 /// Clients are responsible for ensuring that registration doesn't occur
418 /// while another thread is attempting to access the registry. Typically
419 /// this is done by initializing all targets at program startup.
421 /// @param T - The target being registered.
422 /// @param Name - The target name. This should be a static string.
423 /// @param ShortDesc - A short target description. This should be a static
425 /// @param TQualityFn - The triple match quality computation function for
427 /// @param HasJIT - Whether the target supports JIT code
429 static void RegisterTarget(Target &T,
431 const char *ShortDesc,
432 Target::TripleMatchQualityFnTy TQualityFn,
433 bool HasJIT = false);
435 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
438 /// Clients are responsible for ensuring that registration doesn't occur
439 /// while another thread is attempting to access the registry. Typically
440 /// this is done by initializing all targets at program startup.
442 /// @param T - The target being registered.
443 /// @param Fn - A function to construct a MCAsmInfo for the target.
444 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
445 // Ignore duplicate registration.
446 if (!T.AsmInfoCtorFn)
447 T.AsmInfoCtorFn = Fn;
450 /// RegisterTargetMachine - Register a TargetMachine implementation for the
453 /// Clients are responsible for ensuring that registration doesn't occur
454 /// while another thread is attempting to access the registry. Typically
455 /// this is done by initializing all targets at program startup.
457 /// @param T - The target being registered.
458 /// @param Fn - A function to construct a TargetMachine for the target.
459 static void RegisterTargetMachine(Target &T,
460 Target::TargetMachineCtorTy Fn) {
461 // Ignore duplicate registration.
462 if (!T.TargetMachineCtorFn)
463 T.TargetMachineCtorFn = Fn;
466 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
469 /// Clients are responsible for ensuring that registration doesn't occur
470 /// while another thread is attempting to access the registry. Typically
471 /// this is done by initializing all targets at program startup.
473 /// @param T - The target being registered.
474 /// @param Fn - A function to construct an AsmBackend for the target.
475 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
476 if (!T.AsmBackendCtorFn)
477 T.AsmBackendCtorFn = Fn;
480 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
483 /// Clients are responsible for ensuring that registration doesn't occur
484 /// while another thread is attempting to access the registry. Typically
485 /// this is done by initializing all targets at program startup.
487 /// @param T - The target being registered.
488 /// @param Fn - A function to construct an AsmLexer for the target.
489 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
490 if (!T.AsmLexerCtorFn)
491 T.AsmLexerCtorFn = Fn;
494 /// RegisterAsmParser - Register a TargetAsmParser 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 AsmParser for the target.
503 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
504 if (!T.AsmParserCtorFn)
505 T.AsmParserCtorFn = Fn;
508 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
517 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
518 // Ignore duplicate registration.
519 if (!T.AsmPrinterCtorFn)
520 T.AsmPrinterCtorFn = Fn;
523 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
524 /// the given target.
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 MCDisassembler for the target.
532 static void RegisterMCDisassembler(Target &T,
533 Target::MCDisassemblerCtorTy Fn) {
534 if (!T.MCDisassemblerCtorFn)
535 T.MCDisassemblerCtorFn = Fn;
538 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
541 /// Clients are responsible for ensuring that registration doesn't occur
542 /// while another thread is attempting to access the registry. Typically
543 /// this is done by initializing all targets at program startup.
545 /// @param T - The target being registered.
546 /// @param Fn - A function to construct an MCInstPrinter for the target.
547 static void RegisterMCInstPrinter(Target &T,
548 Target::MCInstPrinterCtorTy Fn) {
549 if (!T.MCInstPrinterCtorFn)
550 T.MCInstPrinterCtorFn = Fn;
553 /// RegisterCodeEmitter - Register a MCCodeEmitter 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 MCCodeEmitter for the target.
562 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
563 if (!T.CodeEmitterCtorFn)
564 T.CodeEmitterCtorFn = Fn;
567 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
568 /// for the given target.
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 MCStreamer for the target.
576 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
577 if (!T.ObjectStreamerCtorFn)
578 T.ObjectStreamerCtorFn = Fn;
581 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
582 /// for the given target.
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 MCStreamer for the target.
590 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
591 if (T.AsmStreamerCtorFn == createAsmStreamer)
592 T.AsmStreamerCtorFn = Fn;
599 //===--------------------------------------------------------------------===//
601 /// RegisterTarget - Helper template for registering a target, for use in the
602 /// target's initialization function. Usage:
605 /// Target TheFooTarget; // The global target instance.
607 /// extern "C" void LLVMInitializeFooTargetInfo() {
608 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
610 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
612 struct RegisterTarget {
613 RegisterTarget(Target &T, const char *Name, const char *Desc) {
614 TargetRegistry::RegisterTarget(T, Name, Desc,
615 &getTripleMatchQuality,
619 static unsigned getTripleMatchQuality(const std::string &TT) {
620 if (Triple(TT).getArch() == TargetArchType)
626 /// RegisterAsmInfo - Helper template for registering a target assembly info
627 /// implementation. This invokes the static "Create" method on the class to
628 /// actually do the construction. Usage:
630 /// extern "C" void LLVMInitializeFooTarget() {
631 /// extern Target TheFooTarget;
632 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
634 template<class MCAsmInfoImpl>
635 struct RegisterAsmInfo {
636 RegisterAsmInfo(Target &T) {
637 TargetRegistry::RegisterAsmInfo(T, &Allocator);
640 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
641 return new MCAsmInfoImpl(T, TT);
646 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
647 /// implementation. This invokes the specified function to do the
648 /// construction. Usage:
650 /// extern "C" void LLVMInitializeFooTarget() {
651 /// extern Target TheFooTarget;
652 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
654 struct RegisterAsmInfoFn {
655 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
656 TargetRegistry::RegisterAsmInfo(T, Fn);
661 /// RegisterTargetMachine - Helper template for registering a target machine
662 /// implementation, for use in the target machine initialization
665 /// extern "C" void LLVMInitializeFooTarget() {
666 /// extern Target TheFooTarget;
667 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
669 template<class TargetMachineImpl>
670 struct RegisterTargetMachine {
671 RegisterTargetMachine(Target &T) {
672 TargetRegistry::RegisterTargetMachine(T, &Allocator);
676 static TargetMachine *Allocator(const Target &T, const std::string &TT,
677 const std::string &FS) {
678 return new TargetMachineImpl(T, TT, FS);
682 /// RegisterAsmBackend - Helper template for registering a target specific
683 /// assembler backend. Usage:
685 /// extern "C" void LLVMInitializeFooAsmBackend() {
686 /// extern Target TheFooTarget;
687 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
689 template<class AsmBackendImpl>
690 struct RegisterAsmBackend {
691 RegisterAsmBackend(Target &T) {
692 TargetRegistry::RegisterAsmBackend(T, &Allocator);
696 static TargetAsmBackend *Allocator(const Target &T,
697 const std::string &Triple) {
698 return new AsmBackendImpl(T, Triple);
702 /// RegisterAsmLexer - Helper template for registering a target specific
703 /// assembly lexer, for use in the target machine initialization
706 /// extern "C" void LLVMInitializeFooAsmLexer() {
707 /// extern Target TheFooTarget;
708 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
710 template<class AsmLexerImpl>
711 struct RegisterAsmLexer {
712 RegisterAsmLexer(Target &T) {
713 TargetRegistry::RegisterAsmLexer(T, &Allocator);
717 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
718 return new AsmLexerImpl(T, MAI);
722 /// RegisterAsmParser - Helper template for registering a target specific
723 /// assembly parser, for use in the target machine initialization
726 /// extern "C" void LLVMInitializeFooAsmParser() {
727 /// extern Target TheFooTarget;
728 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
730 template<class AsmParserImpl>
731 struct RegisterAsmParser {
732 RegisterAsmParser(Target &T) {
733 TargetRegistry::RegisterAsmParser(T, &Allocator);
737 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
739 return new AsmParserImpl(T, P, TM);
743 /// RegisterAsmPrinter - Helper template for registering a target specific
744 /// assembly printer, for use in the target machine initialization
747 /// extern "C" void LLVMInitializeFooAsmPrinter() {
748 /// extern Target TheFooTarget;
749 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
751 template<class AsmPrinterImpl>
752 struct RegisterAsmPrinter {
753 RegisterAsmPrinter(Target &T) {
754 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
758 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
759 return new AsmPrinterImpl(TM, Streamer);
763 /// RegisterCodeEmitter - Helper template for registering a target specific
764 /// machine code emitter, for use in the target initialization
767 /// extern "C" void LLVMInitializeFooCodeEmitter() {
768 /// extern Target TheFooTarget;
769 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
771 template<class CodeEmitterImpl>
772 struct RegisterCodeEmitter {
773 RegisterCodeEmitter(Target &T) {
774 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
778 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
780 return new CodeEmitterImpl(T, TM, Ctx);