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,
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,
81 unsigned SyntaxVariant,
82 const MCAsmInfo &MAI);
83 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
86 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
87 const std::string &TT,
89 TargetAsmBackend &TAB,
91 MCCodeEmitter *_Emitter,
93 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
94 formatted_raw_ostream &OS,
97 MCInstPrinter *InstPrint,
99 TargetAsmBackend *TAB,
103 /// Next - The next registered target in the linked list, maintained by the
107 /// TripleMatchQualityFn - The target function for rating the match quality
109 TripleMatchQualityFnTy TripleMatchQualityFn;
111 /// Name - The target name.
114 /// ShortDesc - A short description of the target.
115 const char *ShortDesc;
117 /// HasJIT - Whether this target supports the JIT.
120 AsmInfoCtorFnTy AsmInfoCtorFn;
122 /// TargetMachineCtorFn - Construction function for this target's
123 /// TargetMachine, if registered.
124 TargetMachineCtorTy TargetMachineCtorFn;
126 /// AsmBackendCtorFn - Construction function for this target's
127 /// TargetAsmBackend, if registered.
128 AsmBackendCtorTy AsmBackendCtorFn;
130 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
132 AsmLexerCtorTy AsmLexerCtorFn;
134 /// AsmParserCtorFn - Construction function for this target's
135 /// TargetAsmParser, if registered.
136 AsmParserCtorTy AsmParserCtorFn;
138 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
140 AsmPrinterCtorTy AsmPrinterCtorFn;
142 /// MCDisassemblerCtorFn - Construction function for this target's
143 /// MCDisassembler, if registered.
144 MCDisassemblerCtorTy MCDisassemblerCtorFn;
146 /// MCInstPrinterCtorFn - Construction function for this target's
147 /// MCInstPrinter, if registered.
148 MCInstPrinterCtorTy MCInstPrinterCtorFn;
150 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
152 CodeEmitterCtorTy CodeEmitterCtorFn;
154 /// ObjectStreamerCtorFn - Construction function for this target's
155 /// ObjectStreamer, if registered.
156 ObjectStreamerCtorTy ObjectStreamerCtorFn;
158 /// AsmStreamerCtorFn - Construction function for this target's
159 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
160 AsmStreamerCtorTy AsmStreamerCtorFn;
163 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
165 /// @name Target Information
168 // getNext - Return the next registered target.
169 const Target *getNext() const { return Next; }
171 /// getName - Get the target name.
172 const char *getName() const { return Name; }
174 /// getShortDescription - Get a short description of the target.
175 const char *getShortDescription() const { return ShortDesc; }
178 /// @name Feature Predicates
181 /// hasJIT - Check if this targets supports the just-in-time compilation.
182 bool hasJIT() const { return HasJIT; }
184 /// hasTargetMachine - Check if this target supports code generation.
185 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
187 /// hasAsmBackend - Check if this target supports .o generation.
188 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
190 /// hasAsmLexer - Check if this target supports .s lexing.
191 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
193 /// hasAsmParser - Check if this target supports .s parsing.
194 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
196 /// hasAsmPrinter - Check if this target supports .s printing.
197 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
199 /// hasMCDisassembler - Check if this target has a disassembler.
200 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
202 /// hasMCInstPrinter - Check if this target has an instruction printer.
203 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
205 /// hasCodeEmitter - Check if this target supports instruction encoding.
206 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
208 /// hasObjectStreamer - Check if this target supports streaming to files.
209 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
211 /// hasAsmStreamer - Check if this target supports streaming to files.
212 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
215 /// @name Feature Constructors
218 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
221 /// \arg Triple - This argument is used to determine the target machine
222 /// feature set; it should always be provided. Generally this should be
223 /// either the target triple from the module, or the target triple of the
224 /// host if that does not exist.
225 MCAsmInfo *createAsmInfo(StringRef Triple) const {
228 return AsmInfoCtorFn(*this, Triple);
231 /// createTargetMachine - Create a target specific machine implementation
232 /// for the specified \arg Triple.
234 /// \arg Triple - This argument is used to determine the target machine
235 /// feature set; it should always be provided. Generally this should be
236 /// either the target triple from the module, or the target triple of the
237 /// host if that does not exist.
238 TargetMachine *createTargetMachine(const std::string &Triple,
239 const std::string &Features) const {
240 if (!TargetMachineCtorFn)
242 return TargetMachineCtorFn(*this, Triple, Features);
245 /// createAsmBackend - Create a target specific assembly parser.
247 /// \arg Triple - The target triple string.
248 /// \arg Backend - The target independent assembler object.
249 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
250 if (!AsmBackendCtorFn)
252 return AsmBackendCtorFn(*this, Triple);
255 /// createAsmLexer - Create a target specific assembly lexer.
257 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
260 return AsmLexerCtorFn(*this, MAI);
263 /// createAsmParser - Create a target specific assembly parser.
265 /// \arg Parser - The target independent parser implementation to use for
266 /// parsing and lexing.
267 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
268 TargetMachine &TM) const {
269 if (!AsmParserCtorFn)
271 return AsmParserCtorFn(*this, Parser, TM);
274 /// createAsmPrinter - Create a target specific assembly printer pass. This
275 /// takes ownership of the MCStreamer object.
276 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
277 if (!AsmPrinterCtorFn)
279 return AsmPrinterCtorFn(TM, Streamer);
282 MCDisassembler *createMCDisassembler() const {
283 if (!MCDisassemblerCtorFn)
285 return MCDisassemblerCtorFn(*this);
288 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
289 const MCAsmInfo &MAI) const {
290 if (!MCInstPrinterCtorFn)
292 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
296 /// createCodeEmitter - Create a target specific code emitter.
297 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
298 if (!CodeEmitterCtorFn)
300 return CodeEmitterCtorFn(*this, TM, Ctx);
303 /// createObjectStreamer - Create a target specific MCStreamer.
305 /// \arg TT - The target triple.
306 /// \arg Ctx - The target context.
307 /// \arg TAB - The target assembler backend object. Takes ownership.
308 /// \arg _OS - The stream object.
309 /// \arg _Emitter - The target independent assembler object.Takes ownership.
310 /// \arg RelaxAll - Relax all fixups?
311 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
312 TargetAsmBackend &TAB,
314 MCCodeEmitter *_Emitter,
315 bool RelaxAll) const {
316 if (!ObjectStreamerCtorFn)
318 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll);
321 /// createAsmStreamer - Create a target specific MCStreamer.
322 MCStreamer *createAsmStreamer(MCContext &Ctx,
323 formatted_raw_ostream &OS,
326 MCInstPrinter *InstPrint,
328 TargetAsmBackend *TAB,
329 bool ShowInst) const {
330 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
331 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc,
332 InstPrint, CE, TAB, ShowInst);
338 /// TargetRegistry - Generic interface to target specific features.
339 struct TargetRegistry {
341 const Target *Current;
342 explicit iterator(Target *T) : Current(T) {}
343 friend struct TargetRegistry;
345 iterator(const iterator &I) : Current(I.Current) {}
346 iterator() : Current(0) {}
348 bool operator==(const iterator &x) const {
349 return Current == x.Current;
351 bool operator!=(const iterator &x) const {
352 return !operator==(x);
355 // Iterator traversal: forward iteration only
356 iterator &operator++() { // Preincrement
357 assert(Current && "Cannot increment end iterator!");
358 Current = Current->getNext();
361 iterator operator++(int) { // Postincrement
362 iterator tmp = *this;
367 const Target &operator*() const {
368 assert(Current && "Cannot dereference end iterator!");
372 const Target *operator->() const {
377 /// @name Registry Access
380 static iterator begin();
382 static iterator end() { return iterator(); }
384 /// lookupTarget - Lookup a target based on a target triple.
386 /// \param Triple - The triple to use for finding a target.
387 /// \param Error - On failure, an error string describing why no target was
389 static const Target *lookupTarget(const std::string &Triple,
392 /// getClosestTargetForJIT - Pick the best target that is compatible with
393 /// the current host. If no close target can be found, this returns null
394 /// and sets the Error string to a reason.
396 /// Maintained for compatibility through 2.6.
397 static const Target *getClosestTargetForJIT(std::string &Error);
400 /// @name Target Registration
403 /// RegisterTarget - Register the given target. Attempts to register a
404 /// target which has already been registered will be ignored.
406 /// Clients are responsible for ensuring that registration doesn't occur
407 /// while another thread is attempting to access the registry. Typically
408 /// this is done by initializing all targets at program startup.
410 /// @param T - The target being registered.
411 /// @param Name - The target name. This should be a static string.
412 /// @param ShortDesc - A short target description. This should be a static
414 /// @param TQualityFn - The triple match quality computation function for
416 /// @param HasJIT - Whether the target supports JIT code
418 static void RegisterTarget(Target &T,
420 const char *ShortDesc,
421 Target::TripleMatchQualityFnTy TQualityFn,
422 bool HasJIT = false);
424 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
427 /// Clients are responsible for ensuring that registration doesn't occur
428 /// while another thread is attempting to access the registry. Typically
429 /// this is done by initializing all targets at program startup.
431 /// @param T - The target being registered.
432 /// @param Fn - A function to construct a MCAsmInfo for the target.
433 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
434 // Ignore duplicate registration.
435 if (!T.AsmInfoCtorFn)
436 T.AsmInfoCtorFn = Fn;
439 /// RegisterTargetMachine - Register a TargetMachine implementation for the
442 /// Clients are responsible for ensuring that registration doesn't occur
443 /// while another thread is attempting to access the registry. Typically
444 /// this is done by initializing all targets at program startup.
446 /// @param T - The target being registered.
447 /// @param Fn - A function to construct a TargetMachine for the target.
448 static void RegisterTargetMachine(Target &T,
449 Target::TargetMachineCtorTy Fn) {
450 // Ignore duplicate registration.
451 if (!T.TargetMachineCtorFn)
452 T.TargetMachineCtorFn = Fn;
455 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
458 /// Clients are responsible for ensuring that registration doesn't occur
459 /// while another thread is attempting to access the registry. Typically
460 /// this is done by initializing all targets at program startup.
462 /// @param T - The target being registered.
463 /// @param Fn - A function to construct an AsmBackend for the target.
464 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
465 if (!T.AsmBackendCtorFn)
466 T.AsmBackendCtorFn = Fn;
469 /// RegisterAsmLexer - Register a TargetAsmLexer 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 an AsmLexer for the target.
478 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
479 if (!T.AsmLexerCtorFn)
480 T.AsmLexerCtorFn = Fn;
483 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
486 /// Clients are responsible for ensuring that registration doesn't occur
487 /// while another thread is attempting to access the registry. Typically
488 /// this is done by initializing all targets at program startup.
490 /// @param T - The target being registered.
491 /// @param Fn - A function to construct an AsmParser for the target.
492 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
493 if (!T.AsmParserCtorFn)
494 T.AsmParserCtorFn = Fn;
497 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
500 /// Clients are responsible for ensuring that registration doesn't occur
501 /// while another thread is attempting to access the registry. Typically
502 /// this is done by initializing all targets at program startup.
504 /// @param T - The target being registered.
505 /// @param Fn - A function to construct an AsmPrinter for the target.
506 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
507 // Ignore duplicate registration.
508 if (!T.AsmPrinterCtorFn)
509 T.AsmPrinterCtorFn = Fn;
512 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
513 /// the given target.
515 /// Clients are responsible for ensuring that registration doesn't occur
516 /// while another thread is attempting to access the registry. Typically
517 /// this is done by initializing all targets at program startup.
519 /// @param T - The target being registered.
520 /// @param Fn - A function to construct an MCDisassembler for the target.
521 static void RegisterMCDisassembler(Target &T,
522 Target::MCDisassemblerCtorTy Fn) {
523 if (!T.MCDisassemblerCtorFn)
524 T.MCDisassemblerCtorFn = Fn;
527 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
530 /// Clients are responsible for ensuring that registration doesn't occur
531 /// while another thread is attempting to access the registry. Typically
532 /// this is done by initializing all targets at program startup.
534 /// @param T - The target being registered.
535 /// @param Fn - A function to construct an MCInstPrinter for the target.
536 static void RegisterMCInstPrinter(Target &T,
537 Target::MCInstPrinterCtorTy Fn) {
538 if (!T.MCInstPrinterCtorFn)
539 T.MCInstPrinterCtorFn = Fn;
542 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
551 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
552 if (!T.CodeEmitterCtorFn)
553 T.CodeEmitterCtorFn = Fn;
556 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
557 /// for the given target.
559 /// Clients are responsible for ensuring that registration doesn't occur
560 /// while another thread is attempting to access the registry. Typically
561 /// this is done by initializing all targets at program startup.
563 /// @param T - The target being registered.
564 /// @param Fn - A function to construct an MCStreamer for the target.
565 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
566 if (!T.ObjectStreamerCtorFn)
567 T.ObjectStreamerCtorFn = Fn;
570 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
571 /// for the given target.
573 /// Clients are responsible for ensuring that registration doesn't occur
574 /// while another thread is attempting to access the registry. Typically
575 /// this is done by initializing all targets at program startup.
577 /// @param T - The target being registered.
578 /// @param Fn - A function to construct an MCStreamer for the target.
579 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
580 if (T.AsmStreamerCtorFn == createAsmStreamer)
581 T.AsmStreamerCtorFn = Fn;
588 //===--------------------------------------------------------------------===//
590 /// RegisterTarget - Helper template for registering a target, for use in the
591 /// target's initialization function. Usage:
594 /// Target TheFooTarget; // The global target instance.
596 /// extern "C" void LLVMInitializeFooTargetInfo() {
597 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
599 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
601 struct RegisterTarget {
602 RegisterTarget(Target &T, const char *Name, const char *Desc) {
603 TargetRegistry::RegisterTarget(T, Name, Desc,
604 &getTripleMatchQuality,
608 static unsigned getTripleMatchQuality(const std::string &TT) {
609 if (Triple(TT).getArch() == TargetArchType)
615 /// RegisterAsmInfo - Helper template for registering a target assembly info
616 /// implementation. This invokes the static "Create" method on the class to
617 /// actually do the construction. Usage:
619 /// extern "C" void LLVMInitializeFooTarget() {
620 /// extern Target TheFooTarget;
621 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
623 template<class MCAsmInfoImpl>
624 struct RegisterAsmInfo {
625 RegisterAsmInfo(Target &T) {
626 TargetRegistry::RegisterAsmInfo(T, &Allocator);
629 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
630 return new MCAsmInfoImpl(T, TT);
635 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
636 /// implementation. This invokes the specified function to do the
637 /// construction. Usage:
639 /// extern "C" void LLVMInitializeFooTarget() {
640 /// extern Target TheFooTarget;
641 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
643 struct RegisterAsmInfoFn {
644 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
645 TargetRegistry::RegisterAsmInfo(T, Fn);
650 /// RegisterTargetMachine - Helper template for registering a target machine
651 /// implementation, for use in the target machine initialization
654 /// extern "C" void LLVMInitializeFooTarget() {
655 /// extern Target TheFooTarget;
656 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
658 template<class TargetMachineImpl>
659 struct RegisterTargetMachine {
660 RegisterTargetMachine(Target &T) {
661 TargetRegistry::RegisterTargetMachine(T, &Allocator);
665 static TargetMachine *Allocator(const Target &T, const std::string &TT,
666 const std::string &FS) {
667 return new TargetMachineImpl(T, TT, FS);
671 /// RegisterAsmBackend - Helper template for registering a target specific
672 /// assembler backend. Usage:
674 /// extern "C" void LLVMInitializeFooAsmBackend() {
675 /// extern Target TheFooTarget;
676 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
678 template<class AsmBackendImpl>
679 struct RegisterAsmBackend {
680 RegisterAsmBackend(Target &T) {
681 TargetRegistry::RegisterAsmBackend(T, &Allocator);
685 static TargetAsmBackend *Allocator(const Target &T,
686 const std::string &Triple) {
687 return new AsmBackendImpl(T, Triple);
691 /// RegisterAsmLexer - Helper template for registering a target specific
692 /// assembly lexer, for use in the target machine initialization
695 /// extern "C" void LLVMInitializeFooAsmLexer() {
696 /// extern Target TheFooTarget;
697 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
699 template<class AsmLexerImpl>
700 struct RegisterAsmLexer {
701 RegisterAsmLexer(Target &T) {
702 TargetRegistry::RegisterAsmLexer(T, &Allocator);
706 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
707 return new AsmLexerImpl(T, MAI);
711 /// RegisterAsmParser - Helper template for registering a target specific
712 /// assembly parser, for use in the target machine initialization
715 /// extern "C" void LLVMInitializeFooAsmParser() {
716 /// extern Target TheFooTarget;
717 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
719 template<class AsmParserImpl>
720 struct RegisterAsmParser {
721 RegisterAsmParser(Target &T) {
722 TargetRegistry::RegisterAsmParser(T, &Allocator);
726 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
728 return new AsmParserImpl(T, P, TM);
732 /// RegisterAsmPrinter - Helper template for registering a target specific
733 /// assembly printer, for use in the target machine initialization
736 /// extern "C" void LLVMInitializeFooAsmPrinter() {
737 /// extern Target TheFooTarget;
738 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
740 template<class AsmPrinterImpl>
741 struct RegisterAsmPrinter {
742 RegisterAsmPrinter(Target &T) {
743 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
747 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
748 return new AsmPrinterImpl(TM, Streamer);
752 /// RegisterCodeEmitter - Helper template for registering a target specific
753 /// machine code emitter, for use in the target initialization
756 /// extern "C" void LLVMInitializeFooCodeEmitter() {
757 /// extern Target TheFooTarget;
758 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
760 template<class CodeEmitterImpl>
761 struct RegisterCodeEmitter {
762 RegisterCodeEmitter(Target &T) {
763 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
767 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
769 return new CodeEmitterImpl(T, TM, Ctx);