MC/Matcher: Add support for over-riding the default MatchInstruction function
[oota-llvm.git] / include / llvm / Target / TargetRegistry.h
1 //===-- Target/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_TARGET_TARGETREGISTRY_H
20 #define LLVM_TARGET_TARGETREGISTRY_H
21
22 #include "llvm/ADT/Triple.h"
23 #include <string>
24 #include <cassert>
25
26 namespace llvm {
27   class AsmPrinter;
28   class Module;
29   class MCAssembler;
30   class MCAsmInfo;
31   class MCAsmParser;
32   class MCCodeEmitter;
33   class MCContext;
34   class MCDisassembler;
35   class MCInstPrinter;
36   class MCStreamer;
37   class TargetAsmBackend;
38   class TargetAsmLexer;
39   class TargetAsmParser;
40   class TargetMachine;
41   class raw_ostream;
42
43   /// Target - Wrapper for Target specific information.
44   ///
45   /// For registration purposes, this is a POD type so that targets can be
46   /// registered without the use of static constructors.
47   ///
48   /// Targets should implement a single global instance of this class (which
49   /// will be zero initialized), and pass that instance to the TargetRegistry as
50   /// part of their initialization.
51   class Target {
52   public:
53     friend struct TargetRegistry;
54
55     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
56
57     typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
58                                                 StringRef TT);
59     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
60                                                   const std::string &TT,
61                                                   const std::string &Features);
62     typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
63                                             MCStreamer &Streamer);
64     typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
65                                                   const std::string &TT);
66     typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
67                                               const MCAsmInfo &MAI);
68     typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P);
69     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
70     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
71                                                   unsigned SyntaxVariant,
72                                                   const MCAsmInfo &MAI);
73     typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
74                                                 TargetMachine &TM,
75                                                 MCContext &Ctx);
76
77   private:
78     /// Next - The next registered target in the linked list, maintained by the
79     /// TargetRegistry.
80     Target *Next;
81
82     /// TripleMatchQualityFn - The target function for rating the match quality
83     /// of a triple.
84     TripleMatchQualityFnTy TripleMatchQualityFn;
85
86     /// Name - The target name.
87     const char *Name;
88
89     /// ShortDesc - A short description of the target.
90     const char *ShortDesc;
91
92     /// HasJIT - Whether this target supports the JIT.
93     bool HasJIT;
94
95     AsmInfoCtorFnTy AsmInfoCtorFn;
96
97     /// TargetMachineCtorFn - Construction function for this target's
98     /// TargetMachine, if registered.
99     TargetMachineCtorTy TargetMachineCtorFn;
100
101     /// AsmBackendCtorFn - Construction function for this target's
102     /// TargetAsmBackend, if registered.
103     AsmBackendCtorTy AsmBackendCtorFn;
104
105     /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
106     /// if registered.
107     AsmLexerCtorTy AsmLexerCtorFn;
108
109     /// AsmParserCtorFn - Construction function for this target's
110     /// TargetAsmParser, if registered.
111     AsmParserCtorTy AsmParserCtorFn;
112
113     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
114     /// if registered.
115     AsmPrinterCtorTy AsmPrinterCtorFn;
116
117     /// MCDisassemblerCtorFn - Construction function for this target's
118     /// MCDisassembler, if registered.
119     MCDisassemblerCtorTy MCDisassemblerCtorFn;
120
121     /// MCInstPrinterCtorFn - Construction function for this target's
122     /// MCInstPrinter, if registered.
123     MCInstPrinterCtorTy MCInstPrinterCtorFn;
124
125     /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
126     /// if registered.
127     CodeEmitterCtorTy CodeEmitterCtorFn;
128
129   public:
130     /// @name Target Information
131     /// @{
132
133     // getNext - Return the next registered target.
134     const Target *getNext() const { return Next; }
135
136     /// getName - Get the target name.
137     const char *getName() const { return Name; }
138
139     /// getShortDescription - Get a short description of the target.
140     const char *getShortDescription() const { return ShortDesc; }
141
142     /// @}
143     /// @name Feature Predicates
144     /// @{
145
146     /// hasJIT - Check if this targets supports the just-in-time compilation.
147     bool hasJIT() const { return HasJIT; }
148
149     /// hasTargetMachine - Check if this target supports code generation.
150     bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
151
152     /// hasAsmBackend - Check if this target supports .o generation.
153     bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
154
155     /// hasAsmLexer - Check if this target supports .s lexing.
156     bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
157
158     /// hasAsmParser - Check if this target supports .s parsing.
159     bool hasAsmParser() const { return AsmParserCtorFn != 0; }
160
161     /// hasAsmPrinter - Check if this target supports .s printing.
162     bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
163
164     /// hasMCDisassembler - Check if this target has a disassembler.
165     bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
166
167     /// hasMCInstPrinter - Check if this target has an instruction printer.
168     bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
169
170     /// hasCodeEmitter - Check if this target supports instruction encoding.
171     bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
172
173     /// @}
174     /// @name Feature Constructors
175     /// @{
176
177     /// createAsmInfo - Create a MCAsmInfo implementation for the specified
178     /// target triple.
179     ///
180     /// \arg Triple - This argument is used to determine the target machine
181     /// feature set; it should always be provided. Generally this should be
182     /// either the target triple from the module, or the target triple of the
183     /// host if that does not exist.
184     MCAsmInfo *createAsmInfo(StringRef Triple) const {
185       if (!AsmInfoCtorFn)
186         return 0;
187       return AsmInfoCtorFn(*this, Triple);
188     }
189
190     /// createTargetMachine - Create a target specific machine implementation
191     /// for the specified \arg Triple.
192     ///
193     /// \arg Triple - This argument is used to determine the target machine
194     /// feature set; it should always be provided. Generally this should be
195     /// either the target triple from the module, or the target triple of the
196     /// host if that does not exist.
197     TargetMachine *createTargetMachine(const std::string &Triple,
198                                        const std::string &Features) const {
199       if (!TargetMachineCtorFn)
200         return 0;
201       return TargetMachineCtorFn(*this, Triple, Features);
202     }
203
204     /// createAsmBackend - Create a target specific assembly parser.
205     ///
206     /// \arg Triple - The target triple string.
207     /// \arg Backend - The target independent assembler object.
208     TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
209       if (!AsmBackendCtorFn)
210         return 0;
211       return AsmBackendCtorFn(*this, Triple);
212     }
213
214     /// createAsmLexer - Create a target specific assembly lexer.
215     ///
216     TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
217       if (!AsmLexerCtorFn)
218         return 0;
219       return AsmLexerCtorFn(*this, MAI);
220     }
221
222     /// createAsmParser - Create a target specific assembly parser.
223     ///
224     /// \arg Parser - The target independent parser implementation to use for
225     /// parsing and lexing.
226     TargetAsmParser *createAsmParser(MCAsmParser &Parser) const {
227       if (!AsmParserCtorFn)
228         return 0;
229       return AsmParserCtorFn(*this, Parser);
230     }
231
232     /// createAsmPrinter - Create a target specific assembly printer pass.  This
233     /// takes ownership of the MCStreamer object.
234     AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
235       if (!AsmPrinterCtorFn)
236         return 0;
237       return AsmPrinterCtorFn(TM, Streamer);
238     }
239
240     MCDisassembler *createMCDisassembler() const {
241       if (!MCDisassemblerCtorFn)
242         return 0;
243       return MCDisassemblerCtorFn(*this);
244     }
245
246     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
247                                        const MCAsmInfo &MAI) const {
248       if (!MCInstPrinterCtorFn)
249         return 0;
250       return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
251     }
252
253
254     /// createCodeEmitter - Create a target specific code emitter.
255     MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
256       if (!CodeEmitterCtorFn)
257         return 0;
258       return CodeEmitterCtorFn(*this, TM, Ctx);
259     }
260
261     /// @}
262   };
263
264   /// TargetRegistry - Generic interface to target specific features.
265   struct TargetRegistry {
266     class iterator {
267       const Target *Current;
268       explicit iterator(Target *T) : Current(T) {}
269       friend struct TargetRegistry;
270     public:
271       iterator(const iterator &I) : Current(I.Current) {}
272       iterator() : Current(0) {}
273
274       bool operator==(const iterator &x) const {
275         return Current == x.Current;
276       }
277       bool operator!=(const iterator &x) const {
278         return !operator==(x);
279       }
280
281       // Iterator traversal: forward iteration only
282       iterator &operator++() {          // Preincrement
283         assert(Current && "Cannot increment end iterator!");
284         Current = Current->getNext();
285         return *this;
286       }
287       iterator operator++(int) {        // Postincrement
288         iterator tmp = *this;
289         ++*this;
290         return tmp;
291       }
292
293       const Target &operator*() const {
294         assert(Current && "Cannot dereference end iterator!");
295         return *Current;
296       }
297
298       const Target *operator->() const {
299         return &operator*();
300       }
301     };
302
303     /// @name Registry Access
304     /// @{
305
306     static iterator begin();
307
308     static iterator end() { return iterator(); }
309
310     /// lookupTarget - Lookup a target based on a target triple.
311     ///
312     /// \param Triple - The triple to use for finding a target.
313     /// \param Error - On failure, an error string describing why no target was
314     /// found.
315     static const Target *lookupTarget(const std::string &Triple,
316                                       std::string &Error);
317
318     /// getClosestTargetForJIT - Pick the best target that is compatible with
319     /// the current host.  If no close target can be found, this returns null
320     /// and sets the Error string to a reason.
321     ///
322     /// Maintained for compatibility through 2.6.
323     static const Target *getClosestTargetForJIT(std::string &Error);
324
325     /// @}
326     /// @name Target Registration
327     /// @{
328
329     /// RegisterTarget - Register the given target. Attempts to register a
330     /// target which has already been registered will be ignored.
331     ///
332     /// Clients are responsible for ensuring that registration doesn't occur
333     /// while another thread is attempting to access the registry. Typically
334     /// this is done by initializing all targets at program startup.
335     ///
336     /// @param T - The target being registered.
337     /// @param Name - The target name. This should be a static string.
338     /// @param ShortDesc - A short target description. This should be a static
339     /// string.
340     /// @param TQualityFn - The triple match quality computation function for
341     /// this target.
342     /// @param HasJIT - Whether the target supports JIT code
343     /// generation.
344     static void RegisterTarget(Target &T,
345                                const char *Name,
346                                const char *ShortDesc,
347                                Target::TripleMatchQualityFnTy TQualityFn,
348                                bool HasJIT = false);
349
350     /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
351     /// given target.
352     ///
353     /// Clients are responsible for ensuring that registration doesn't occur
354     /// while another thread is attempting to access the registry. Typically
355     /// this is done by initializing all targets at program startup.
356     ///
357     /// @param T - The target being registered.
358     /// @param Fn - A function to construct a MCAsmInfo for the target.
359     static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
360       // Ignore duplicate registration.
361       if (!T.AsmInfoCtorFn)
362         T.AsmInfoCtorFn = Fn;
363     }
364
365     /// RegisterTargetMachine - Register a TargetMachine implementation for the
366     /// given target.
367     ///
368     /// Clients are responsible for ensuring that registration doesn't occur
369     /// while another thread is attempting to access the registry. Typically
370     /// this is done by initializing all targets at program startup.
371     ///
372     /// @param T - The target being registered.
373     /// @param Fn - A function to construct a TargetMachine for the target.
374     static void RegisterTargetMachine(Target &T,
375                                       Target::TargetMachineCtorTy Fn) {
376       // Ignore duplicate registration.
377       if (!T.TargetMachineCtorFn)
378         T.TargetMachineCtorFn = Fn;
379     }
380
381     /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
382     /// given target.
383     ///
384     /// Clients are responsible for ensuring that registration doesn't occur
385     /// while another thread is attempting to access the registry. Typically
386     /// this is done by initializing all targets at program startup.
387     ///
388     /// @param T - The target being registered.
389     /// @param Fn - A function to construct an AsmBackend for the target.
390     static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
391       if (!T.AsmBackendCtorFn)
392         T.AsmBackendCtorFn = Fn;
393     }
394
395     /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
396     /// given target.
397     ///
398     /// Clients are responsible for ensuring that registration doesn't occur
399     /// while another thread is attempting to access the registry. Typically
400     /// this is done by initializing all targets at program startup.
401     ///
402     /// @param T - The target being registered.
403     /// @param Fn - A function to construct an AsmLexer for the target.
404     static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
405       if (!T.AsmLexerCtorFn)
406         T.AsmLexerCtorFn = Fn;
407     }
408
409     /// RegisterAsmParser - Register a TargetAsmParser implementation for the
410     /// given target.
411     ///
412     /// Clients are responsible for ensuring that registration doesn't occur
413     /// while another thread is attempting to access the registry. Typically
414     /// this is done by initializing all targets at program startup.
415     ///
416     /// @param T - The target being registered.
417     /// @param Fn - A function to construct an AsmParser for the target.
418     static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
419       if (!T.AsmParserCtorFn)
420         T.AsmParserCtorFn = Fn;
421     }
422
423     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
424     /// target.
425     ///
426     /// Clients are responsible for ensuring that registration doesn't occur
427     /// while another thread is attempting to access the registry. Typically
428     /// this is done by initializing all targets at program startup.
429     ///
430     /// @param T - The target being registered.
431     /// @param Fn - A function to construct an AsmPrinter for the target.
432     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
433       // Ignore duplicate registration.
434       if (!T.AsmPrinterCtorFn)
435         T.AsmPrinterCtorFn = Fn;
436     }
437
438     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
439     /// the given target.
440     ///
441     /// Clients are responsible for ensuring that registration doesn't occur
442     /// while another thread is attempting to access the registry. Typically
443     /// this is done by initializing all targets at program startup.
444     ///
445     /// @param T - The target being registered.
446     /// @param Fn - A function to construct an MCDisassembler for the target.
447     static void RegisterMCDisassembler(Target &T,
448                                        Target::MCDisassemblerCtorTy Fn) {
449       if (!T.MCDisassemblerCtorFn)
450         T.MCDisassemblerCtorFn = Fn;
451     }
452
453     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
454     /// given target.
455     ///
456     /// Clients are responsible for ensuring that registration doesn't occur
457     /// while another thread is attempting to access the registry. Typically
458     /// this is done by initializing all targets at program startup.
459     ///
460     /// @param T - The target being registered.
461     /// @param Fn - A function to construct an MCInstPrinter for the target.
462     static void RegisterMCInstPrinter(Target &T,
463                                       Target::MCInstPrinterCtorTy Fn) {
464       if (!T.MCInstPrinterCtorFn)
465         T.MCInstPrinterCtorFn = Fn;
466     }
467
468     /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
469     /// given target.
470     ///
471     /// Clients are responsible for ensuring that registration doesn't occur
472     /// while another thread is attempting to access the registry. Typically
473     /// this is done by initializing all targets at program startup.
474     ///
475     /// @param T - The target being registered.
476     /// @param Fn - A function to construct an MCCodeEmitter for the target.
477     static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
478       if (!T.CodeEmitterCtorFn)
479         T.CodeEmitterCtorFn = Fn;
480     }
481
482     /// @}
483   };
484
485
486   //===--------------------------------------------------------------------===//
487
488   /// RegisterTarget - Helper template for registering a target, for use in the
489   /// target's initialization function. Usage:
490   ///
491   ///
492   /// Target TheFooTarget; // The global target instance.
493   ///
494   /// extern "C" void LLVMInitializeFooTargetInfo() {
495   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
496   /// }
497   template<Triple::ArchType TargetArchType = Triple::InvalidArch,
498            bool HasJIT = false>
499   struct RegisterTarget {
500     RegisterTarget(Target &T, const char *Name, const char *Desc) {
501       TargetRegistry::RegisterTarget(T, Name, Desc,
502                                      &getTripleMatchQuality,
503                                      HasJIT);
504     }
505
506     static unsigned getTripleMatchQuality(const std::string &TT) {
507       if (Triple(TT).getArch() == TargetArchType)
508         return 20;
509       return 0;
510     }
511   };
512
513   /// RegisterAsmInfo - Helper template for registering a target assembly info
514   /// implementation.  This invokes the static "Create" method on the class to
515   /// actually do the construction.  Usage:
516   ///
517   /// extern "C" void LLVMInitializeFooTarget() {
518   ///   extern Target TheFooTarget;
519   ///   RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
520   /// }
521   template<class MCAsmInfoImpl>
522   struct RegisterAsmInfo {
523     RegisterAsmInfo(Target &T) {
524       TargetRegistry::RegisterAsmInfo(T, &Allocator);
525     }
526   private:
527     static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
528       return new MCAsmInfoImpl(T, TT);
529     }
530
531   };
532
533   /// RegisterAsmInfoFn - Helper template for registering a target assembly info
534   /// implementation.  This invokes the specified function to do the
535   /// construction.  Usage:
536   ///
537   /// extern "C" void LLVMInitializeFooTarget() {
538   ///   extern Target TheFooTarget;
539   ///   RegisterAsmInfoFn X(TheFooTarget, TheFunction);
540   /// }
541   struct RegisterAsmInfoFn {
542     RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
543       TargetRegistry::RegisterAsmInfo(T, Fn);
544     }
545   };
546
547
548   /// RegisterTargetMachine - Helper template for registering a target machine
549   /// implementation, for use in the target machine initialization
550   /// function. Usage:
551   ///
552   /// extern "C" void LLVMInitializeFooTarget() {
553   ///   extern Target TheFooTarget;
554   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
555   /// }
556   template<class TargetMachineImpl>
557   struct RegisterTargetMachine {
558     RegisterTargetMachine(Target &T) {
559       TargetRegistry::RegisterTargetMachine(T, &Allocator);
560     }
561
562   private:
563     static TargetMachine *Allocator(const Target &T, const std::string &TT,
564                                     const std::string &FS) {
565       return new TargetMachineImpl(T, TT, FS);
566     }
567   };
568
569   /// RegisterAsmBackend - Helper template for registering a target specific
570   /// assembler backend. Usage:
571   ///
572   /// extern "C" void LLVMInitializeFooAsmBackend() {
573   ///   extern Target TheFooTarget;
574   ///   RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
575   /// }
576   template<class AsmBackendImpl>
577   struct RegisterAsmBackend {
578     RegisterAsmBackend(Target &T) {
579       TargetRegistry::RegisterAsmBackend(T, &Allocator);
580     }
581
582   private:
583     static TargetAsmBackend *Allocator(const Target &T,
584                                        const std::string &Triple) {
585       return new AsmBackendImpl(T, Triple);
586     }
587   };
588
589   /// RegisterAsmLexer - Helper template for registering a target specific
590   /// assembly lexer, for use in the target machine initialization
591   /// function. Usage:
592   ///
593   /// extern "C" void LLVMInitializeFooAsmLexer() {
594   ///   extern Target TheFooTarget;
595   ///   RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
596   /// }
597   template<class AsmLexerImpl>
598   struct RegisterAsmLexer {
599     RegisterAsmLexer(Target &T) {
600       TargetRegistry::RegisterAsmLexer(T, &Allocator);
601     }
602
603   private:
604     static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
605       return new AsmLexerImpl(T, MAI);
606     }
607   };
608
609   /// RegisterAsmParser - Helper template for registering a target specific
610   /// assembly parser, for use in the target machine initialization
611   /// function. Usage:
612   ///
613   /// extern "C" void LLVMInitializeFooAsmParser() {
614   ///   extern Target TheFooTarget;
615   ///   RegisterAsmParser<FooAsmParser> X(TheFooTarget);
616   /// }
617   template<class AsmParserImpl>
618   struct RegisterAsmParser {
619     RegisterAsmParser(Target &T) {
620       TargetRegistry::RegisterAsmParser(T, &Allocator);
621     }
622
623   private:
624     static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P) {
625       return new AsmParserImpl(T, P);
626     }
627   };
628
629   /// RegisterAsmPrinter - Helper template for registering a target specific
630   /// assembly printer, for use in the target machine initialization
631   /// function. Usage:
632   ///
633   /// extern "C" void LLVMInitializeFooAsmPrinter() {
634   ///   extern Target TheFooTarget;
635   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
636   /// }
637   template<class AsmPrinterImpl>
638   struct RegisterAsmPrinter {
639     RegisterAsmPrinter(Target &T) {
640       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
641     }
642
643   private:
644     static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
645       return new AsmPrinterImpl(TM, Streamer);
646     }
647   };
648
649   /// RegisterCodeEmitter - Helper template for registering a target specific
650   /// machine code emitter, for use in the target initialization
651   /// function. Usage:
652   ///
653   /// extern "C" void LLVMInitializeFooCodeEmitter() {
654   ///   extern Target TheFooTarget;
655   ///   RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
656   /// }
657   template<class CodeEmitterImpl>
658   struct RegisterCodeEmitter {
659     RegisterCodeEmitter(Target &T) {
660       TargetRegistry::RegisterCodeEmitter(T, &Allocator);
661     }
662
663   private:
664     static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
665                                     MCContext &Ctx) {
666       return new CodeEmitterImpl(T, TM, Ctx);
667     }
668   };
669
670 }
671
672 #endif