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