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,
52 /// Target - Wrapper for Target specific information.
54 /// For registration purposes, this is a POD type so that targets can be
55 /// registered without the use of static constructors.
57 /// Targets should implement a single global instance of this class (which
58 /// will be zero initialized), and pass that instance to the TargetRegistry as
59 /// part of their initialization.
62 friend struct TargetRegistry;
64 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
66 typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
68 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
69 const std::string &TT,
70 const std::string &Features);
71 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
72 MCStreamer &Streamer);
73 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
74 const std::string &TT);
75 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
76 const MCAsmInfo &MAI);
77 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
79 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
80 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
82 unsigned SyntaxVariant,
83 const MCAsmInfo &MAI);
84 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
87 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
88 const std::string &TT,
90 TargetAsmBackend &TAB,
92 MCCodeEmitter *_Emitter,
95 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
96 formatted_raw_ostream &OS,
100 MCInstPrinter *InstPrint,
102 TargetAsmBackend *TAB,
106 /// Next - The next registered target in the linked list, maintained by the
110 /// TripleMatchQualityFn - The target function for rating the match quality
112 TripleMatchQualityFnTy TripleMatchQualityFn;
114 /// Name - The target name.
117 /// ShortDesc - A short description of the target.
118 const char *ShortDesc;
120 /// HasJIT - Whether this target supports the JIT.
123 AsmInfoCtorFnTy AsmInfoCtorFn;
125 /// TargetMachineCtorFn - Construction function for this target's
126 /// TargetMachine, if registered.
127 TargetMachineCtorTy TargetMachineCtorFn;
129 /// AsmBackendCtorFn - Construction function for this target's
130 /// TargetAsmBackend, if registered.
131 AsmBackendCtorTy AsmBackendCtorFn;
133 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
135 AsmLexerCtorTy AsmLexerCtorFn;
137 /// AsmParserCtorFn - Construction function for this target's
138 /// TargetAsmParser, if registered.
139 AsmParserCtorTy AsmParserCtorFn;
141 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
143 AsmPrinterCtorTy AsmPrinterCtorFn;
145 /// MCDisassemblerCtorFn - Construction function for this target's
146 /// MCDisassembler, if registered.
147 MCDisassemblerCtorTy MCDisassemblerCtorFn;
149 /// MCInstPrinterCtorFn - Construction function for this target's
150 /// MCInstPrinter, if registered.
151 MCInstPrinterCtorTy MCInstPrinterCtorFn;
153 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
155 CodeEmitterCtorTy CodeEmitterCtorFn;
157 /// ObjectStreamerCtorFn - Construction function for this target's
158 /// ObjectStreamer, if registered.
159 ObjectStreamerCtorTy ObjectStreamerCtorFn;
161 /// AsmStreamerCtorFn - Construction function for this target's
162 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
163 AsmStreamerCtorTy AsmStreamerCtorFn;
166 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
168 /// @name Target Information
171 // getNext - Return the next registered target.
172 const Target *getNext() const { return Next; }
174 /// getName - Get the target name.
175 const char *getName() const { return Name; }
177 /// getShortDescription - Get a short description of the target.
178 const char *getShortDescription() const { return ShortDesc; }
181 /// @name Feature Predicates
184 /// hasJIT - Check if this targets supports the just-in-time compilation.
185 bool hasJIT() const { return HasJIT; }
187 /// hasTargetMachine - Check if this target supports code generation.
188 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
190 /// hasAsmBackend - Check if this target supports .o generation.
191 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
193 /// hasAsmLexer - Check if this target supports .s lexing.
194 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
196 /// hasAsmParser - Check if this target supports .s parsing.
197 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
199 /// hasAsmPrinter - Check if this target supports .s printing.
200 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
202 /// hasMCDisassembler - Check if this target has a disassembler.
203 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
205 /// hasMCInstPrinter - Check if this target has an instruction printer.
206 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
208 /// hasCodeEmitter - Check if this target supports instruction encoding.
209 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
211 /// hasObjectStreamer - Check if this target supports streaming to files.
212 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
214 /// hasAsmStreamer - Check if this target supports streaming to files.
215 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
218 /// @name Feature Constructors
221 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
224 /// \arg Triple - This argument is used to determine the target machine
225 /// feature set; it should always be provided. Generally this should be
226 /// either the target triple from the module, or the target triple of the
227 /// host if that does not exist.
228 MCAsmInfo *createAsmInfo(StringRef Triple) const {
231 return AsmInfoCtorFn(*this, Triple);
234 /// createTargetMachine - Create a target specific machine implementation
235 /// for the specified \arg Triple.
237 /// \arg Triple - This argument is used to determine the target machine
238 /// feature set; it should always be provided. Generally this should be
239 /// either the target triple from the module, or the target triple of the
240 /// host if that does not exist.
241 TargetMachine *createTargetMachine(const std::string &Triple,
242 const std::string &Features) const {
243 if (!TargetMachineCtorFn)
245 return TargetMachineCtorFn(*this, Triple, Features);
248 /// createAsmBackend - Create a target specific assembly parser.
250 /// \arg Triple - The target triple string.
251 /// \arg Backend - The target independent assembler object.
252 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
253 if (!AsmBackendCtorFn)
255 return AsmBackendCtorFn(*this, Triple);
258 /// createAsmLexer - Create a target specific assembly lexer.
260 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
263 return AsmLexerCtorFn(*this, MAI);
266 /// createAsmParser - Create a target specific assembly parser.
268 /// \arg Parser - The target independent parser implementation to use for
269 /// parsing and lexing.
270 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
271 TargetMachine &TM) const {
272 if (!AsmParserCtorFn)
274 return AsmParserCtorFn(*this, Parser, TM);
277 /// createAsmPrinter - Create a target specific assembly printer pass. This
278 /// takes ownership of the MCStreamer object.
279 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
280 if (!AsmPrinterCtorFn)
282 return AsmPrinterCtorFn(TM, Streamer);
285 MCDisassembler *createMCDisassembler() const {
286 if (!MCDisassemblerCtorFn)
288 return MCDisassemblerCtorFn(*this);
291 MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
292 unsigned SyntaxVariant,
293 const MCAsmInfo &MAI) const {
294 if (!MCInstPrinterCtorFn)
296 return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
300 /// createCodeEmitter - Create a target specific code emitter.
301 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
302 if (!CodeEmitterCtorFn)
304 return CodeEmitterCtorFn(*this, TM, Ctx);
307 /// createObjectStreamer - Create a target specific MCStreamer.
309 /// \arg TT - The target triple.
310 /// \arg Ctx - The target context.
311 /// \arg TAB - The target assembler backend object. Takes ownership.
312 /// \arg _OS - The stream object.
313 /// \arg _Emitter - The target independent assembler object.Takes ownership.
314 /// \arg RelaxAll - Relax all fixups?
315 /// \arg NoExecStack - Mark file as not needing a executable stack.
316 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
317 TargetAsmBackend &TAB,
319 MCCodeEmitter *_Emitter,
321 bool NoExecStack) const {
322 if (!ObjectStreamerCtorFn)
324 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
328 /// createAsmStreamer - Create a target specific MCStreamer.
329 MCStreamer *createAsmStreamer(MCContext &Ctx,
330 formatted_raw_ostream &OS,
334 MCInstPrinter *InstPrint,
336 TargetAsmBackend *TAB,
337 bool ShowInst) const {
338 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
339 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
340 InstPrint, CE, TAB, ShowInst);
346 /// TargetRegistry - Generic interface to target specific features.
347 struct TargetRegistry {
349 const Target *Current;
350 explicit iterator(Target *T) : Current(T) {}
351 friend struct TargetRegistry;
353 iterator(const iterator &I) : Current(I.Current) {}
354 iterator() : Current(0) {}
356 bool operator==(const iterator &x) const {
357 return Current == x.Current;
359 bool operator!=(const iterator &x) const {
360 return !operator==(x);
363 // Iterator traversal: forward iteration only
364 iterator &operator++() { // Preincrement
365 assert(Current && "Cannot increment end iterator!");
366 Current = Current->getNext();
369 iterator operator++(int) { // Postincrement
370 iterator tmp = *this;
375 const Target &operator*() const {
376 assert(Current && "Cannot dereference end iterator!");
380 const Target *operator->() const {
385 /// @name Registry Access
388 static iterator begin();
390 static iterator end() { return iterator(); }
392 /// lookupTarget - Lookup a target based on a target triple.
394 /// \param Triple - The triple to use for finding a target.
395 /// \param Error - On failure, an error string describing why no target was
397 static const Target *lookupTarget(const std::string &Triple,
400 /// getClosestTargetForJIT - Pick the best target that is compatible with
401 /// the current host. If no close target can be found, this returns null
402 /// and sets the Error string to a reason.
404 /// Maintained for compatibility through 2.6.
405 static const Target *getClosestTargetForJIT(std::string &Error);
408 /// @name Target Registration
411 /// RegisterTarget - Register the given target. Attempts to register a
412 /// target which has already been registered will be ignored.
414 /// Clients are responsible for ensuring that registration doesn't occur
415 /// while another thread is attempting to access the registry. Typically
416 /// this is done by initializing all targets at program startup.
418 /// @param T - The target being registered.
419 /// @param Name - The target name. This should be a static string.
420 /// @param ShortDesc - A short target description. This should be a static
422 /// @param TQualityFn - The triple match quality computation function for
424 /// @param HasJIT - Whether the target supports JIT code
426 static void RegisterTarget(Target &T,
428 const char *ShortDesc,
429 Target::TripleMatchQualityFnTy TQualityFn,
430 bool HasJIT = false);
432 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
435 /// Clients are responsible for ensuring that registration doesn't occur
436 /// while another thread is attempting to access the registry. Typically
437 /// this is done by initializing all targets at program startup.
439 /// @param T - The target being registered.
440 /// @param Fn - A function to construct a MCAsmInfo for the target.
441 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
442 // Ignore duplicate registration.
443 if (!T.AsmInfoCtorFn)
444 T.AsmInfoCtorFn = Fn;
447 /// RegisterTargetMachine - Register a TargetMachine implementation for the
450 /// Clients are responsible for ensuring that registration doesn't occur
451 /// while another thread is attempting to access the registry. Typically
452 /// this is done by initializing all targets at program startup.
454 /// @param T - The target being registered.
455 /// @param Fn - A function to construct a TargetMachine for the target.
456 static void RegisterTargetMachine(Target &T,
457 Target::TargetMachineCtorTy Fn) {
458 // Ignore duplicate registration.
459 if (!T.TargetMachineCtorFn)
460 T.TargetMachineCtorFn = Fn;
463 /// RegisterAsmBackend - Register a TargetAsmBackend 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 an AsmBackend for the target.
472 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
473 if (!T.AsmBackendCtorFn)
474 T.AsmBackendCtorFn = Fn;
477 /// RegisterAsmLexer - Register a TargetAsmLexer 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 an AsmLexer for the target.
486 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
487 if (!T.AsmLexerCtorFn)
488 T.AsmLexerCtorFn = Fn;
491 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
494 /// Clients are responsible for ensuring that registration doesn't occur
495 /// while another thread is attempting to access the registry. Typically
496 /// this is done by initializing all targets at program startup.
498 /// @param T - The target being registered.
499 /// @param Fn - A function to construct an AsmParser for the target.
500 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
501 if (!T.AsmParserCtorFn)
502 T.AsmParserCtorFn = Fn;
505 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
508 /// Clients are responsible for ensuring that registration doesn't occur
509 /// while another thread is attempting to access the registry. Typically
510 /// this is done by initializing all targets at program startup.
512 /// @param T - The target being registered.
513 /// @param Fn - A function to construct an AsmPrinter for the target.
514 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
515 // Ignore duplicate registration.
516 if (!T.AsmPrinterCtorFn)
517 T.AsmPrinterCtorFn = Fn;
520 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
521 /// the given target.
523 /// Clients are responsible for ensuring that registration doesn't occur
524 /// while another thread is attempting to access the registry. Typically
525 /// this is done by initializing all targets at program startup.
527 /// @param T - The target being registered.
528 /// @param Fn - A function to construct an MCDisassembler for the target.
529 static void RegisterMCDisassembler(Target &T,
530 Target::MCDisassemblerCtorTy Fn) {
531 if (!T.MCDisassemblerCtorFn)
532 T.MCDisassemblerCtorFn = Fn;
535 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
538 /// Clients are responsible for ensuring that registration doesn't occur
539 /// while another thread is attempting to access the registry. Typically
540 /// this is done by initializing all targets at program startup.
542 /// @param T - The target being registered.
543 /// @param Fn - A function to construct an MCInstPrinter for the target.
544 static void RegisterMCInstPrinter(Target &T,
545 Target::MCInstPrinterCtorTy Fn) {
546 if (!T.MCInstPrinterCtorFn)
547 T.MCInstPrinterCtorFn = Fn;
550 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
553 /// Clients are responsible for ensuring that registration doesn't occur
554 /// while another thread is attempting to access the registry. Typically
555 /// this is done by initializing all targets at program startup.
557 /// @param T - The target being registered.
558 /// @param Fn - A function to construct an MCCodeEmitter for the target.
559 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
560 if (!T.CodeEmitterCtorFn)
561 T.CodeEmitterCtorFn = Fn;
564 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
565 /// for the given target.
567 /// Clients are responsible for ensuring that registration doesn't occur
568 /// while another thread is attempting to access the registry. Typically
569 /// this is done by initializing all targets at program startup.
571 /// @param T - The target being registered.
572 /// @param Fn - A function to construct an MCStreamer for the target.
573 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
574 if (!T.ObjectStreamerCtorFn)
575 T.ObjectStreamerCtorFn = Fn;
578 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
579 /// for the given target.
581 /// Clients are responsible for ensuring that registration doesn't occur
582 /// while another thread is attempting to access the registry. Typically
583 /// this is done by initializing all targets at program startup.
585 /// @param T - The target being registered.
586 /// @param Fn - A function to construct an MCStreamer for the target.
587 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
588 if (T.AsmStreamerCtorFn == createAsmStreamer)
589 T.AsmStreamerCtorFn = Fn;
596 //===--------------------------------------------------------------------===//
598 /// RegisterTarget - Helper template for registering a target, for use in the
599 /// target's initialization function. Usage:
602 /// Target TheFooTarget; // The global target instance.
604 /// extern "C" void LLVMInitializeFooTargetInfo() {
605 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
607 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
609 struct RegisterTarget {
610 RegisterTarget(Target &T, const char *Name, const char *Desc) {
611 TargetRegistry::RegisterTarget(T, Name, Desc,
612 &getTripleMatchQuality,
616 static unsigned getTripleMatchQuality(const std::string &TT) {
617 if (Triple(TT).getArch() == TargetArchType)
623 /// RegisterAsmInfo - Helper template for registering a target assembly info
624 /// implementation. This invokes the static "Create" method on the class to
625 /// actually do the construction. Usage:
627 /// extern "C" void LLVMInitializeFooTarget() {
628 /// extern Target TheFooTarget;
629 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
631 template<class MCAsmInfoImpl>
632 struct RegisterAsmInfo {
633 RegisterAsmInfo(Target &T) {
634 TargetRegistry::RegisterAsmInfo(T, &Allocator);
637 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
638 return new MCAsmInfoImpl(T, TT);
643 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
644 /// implementation. This invokes the specified function to do the
645 /// construction. Usage:
647 /// extern "C" void LLVMInitializeFooTarget() {
648 /// extern Target TheFooTarget;
649 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
651 struct RegisterAsmInfoFn {
652 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
653 TargetRegistry::RegisterAsmInfo(T, Fn);
658 /// RegisterTargetMachine - Helper template for registering a target machine
659 /// implementation, for use in the target machine initialization
662 /// extern "C" void LLVMInitializeFooTarget() {
663 /// extern Target TheFooTarget;
664 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
666 template<class TargetMachineImpl>
667 struct RegisterTargetMachine {
668 RegisterTargetMachine(Target &T) {
669 TargetRegistry::RegisterTargetMachine(T, &Allocator);
673 static TargetMachine *Allocator(const Target &T, const std::string &TT,
674 const std::string &FS) {
675 return new TargetMachineImpl(T, TT, FS);
679 /// RegisterAsmBackend - Helper template for registering a target specific
680 /// assembler backend. Usage:
682 /// extern "C" void LLVMInitializeFooAsmBackend() {
683 /// extern Target TheFooTarget;
684 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
686 template<class AsmBackendImpl>
687 struct RegisterAsmBackend {
688 RegisterAsmBackend(Target &T) {
689 TargetRegistry::RegisterAsmBackend(T, &Allocator);
693 static TargetAsmBackend *Allocator(const Target &T,
694 const std::string &Triple) {
695 return new AsmBackendImpl(T, Triple);
699 /// RegisterAsmLexer - Helper template for registering a target specific
700 /// assembly lexer, for use in the target machine initialization
703 /// extern "C" void LLVMInitializeFooAsmLexer() {
704 /// extern Target TheFooTarget;
705 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
707 template<class AsmLexerImpl>
708 struct RegisterAsmLexer {
709 RegisterAsmLexer(Target &T) {
710 TargetRegistry::RegisterAsmLexer(T, &Allocator);
714 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
715 return new AsmLexerImpl(T, MAI);
719 /// RegisterAsmParser - Helper template for registering a target specific
720 /// assembly parser, for use in the target machine initialization
723 /// extern "C" void LLVMInitializeFooAsmParser() {
724 /// extern Target TheFooTarget;
725 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
727 template<class AsmParserImpl>
728 struct RegisterAsmParser {
729 RegisterAsmParser(Target &T) {
730 TargetRegistry::RegisterAsmParser(T, &Allocator);
734 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
736 return new AsmParserImpl(T, P, TM);
740 /// RegisterAsmPrinter - Helper template for registering a target specific
741 /// assembly printer, for use in the target machine initialization
744 /// extern "C" void LLVMInitializeFooAsmPrinter() {
745 /// extern Target TheFooTarget;
746 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
748 template<class AsmPrinterImpl>
749 struct RegisterAsmPrinter {
750 RegisterAsmPrinter(Target &T) {
751 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
755 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
756 return new AsmPrinterImpl(TM, Streamer);
760 /// RegisterCodeEmitter - Helper template for registering a target specific
761 /// machine code emitter, for use in the target initialization
764 /// extern "C" void LLVMInitializeFooCodeEmitter() {
765 /// extern Target TheFooTarget;
766 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
768 template<class CodeEmitterImpl>
769 struct RegisterCodeEmitter {
770 RegisterCodeEmitter(Target &T) {
771 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
775 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
777 return new CodeEmitterImpl(T, TM, Ctx);