Missing files for the BlockFrequency analysis added.
[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   class formatted_raw_ostream;
43
44   MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
45                                 bool isVerboseAsm,
46                                 bool useLoc, bool useCFI,
47                                 MCInstPrinter *InstPrint,
48                                 MCCodeEmitter *CE,
49                                 TargetAsmBackend *TAB,
50                                 bool ShowInst);
51
52   /// Target - Wrapper for Target specific information.
53   ///
54   /// For registration purposes, this is a POD type so that targets can be
55   /// registered without the use of static constructors.
56   ///
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.
60   class Target {
61   public:
62     friend struct TargetRegistry;
63
64     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
65
66     typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
67                                                 StringRef TT);
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,
78                                                 TargetMachine &TM);
79     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
80     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
81                                                   TargetMachine &TM,
82                                                   unsigned SyntaxVariant,
83                                                   const MCAsmInfo &MAI);
84     typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
85                                                 TargetMachine &TM,
86                                                 MCContext &Ctx);
87     typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
88                                                 const std::string &TT,
89                                                 MCContext &Ctx,
90                                                 TargetAsmBackend &TAB,
91                                                 raw_ostream &_OS,
92                                                 MCCodeEmitter *_Emitter,
93                                                 bool RelaxAll,
94                                                 bool NoExecStack);
95     typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
96                                              formatted_raw_ostream &OS,
97                                              bool isVerboseAsm,
98                                              bool useLoc,
99                                              bool useCFI,
100                                              MCInstPrinter *InstPrint,
101                                              MCCodeEmitter *CE,
102                                              TargetAsmBackend *TAB,
103                                              bool ShowInst);
104
105   private:
106     /// Next - The next registered target in the linked list, maintained by the
107     /// TargetRegistry.
108     Target *Next;
109
110     /// TripleMatchQualityFn - The target function for rating the match quality
111     /// of a triple.
112     TripleMatchQualityFnTy TripleMatchQualityFn;
113
114     /// Name - The target name.
115     const char *Name;
116
117     /// ShortDesc - A short description of the target.
118     const char *ShortDesc;
119
120     /// HasJIT - Whether this target supports the JIT.
121     bool HasJIT;
122
123     AsmInfoCtorFnTy AsmInfoCtorFn;
124
125     /// TargetMachineCtorFn - Construction function for this target's
126     /// TargetMachine, if registered.
127     TargetMachineCtorTy TargetMachineCtorFn;
128
129     /// AsmBackendCtorFn - Construction function for this target's
130     /// TargetAsmBackend, if registered.
131     AsmBackendCtorTy AsmBackendCtorFn;
132
133     /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
134     /// if registered.
135     AsmLexerCtorTy AsmLexerCtorFn;
136
137     /// AsmParserCtorFn - Construction function for this target's
138     /// TargetAsmParser, if registered.
139     AsmParserCtorTy AsmParserCtorFn;
140
141     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
142     /// if registered.
143     AsmPrinterCtorTy AsmPrinterCtorFn;
144
145     /// MCDisassemblerCtorFn - Construction function for this target's
146     /// MCDisassembler, if registered.
147     MCDisassemblerCtorTy MCDisassemblerCtorFn;
148
149     /// MCInstPrinterCtorFn - Construction function for this target's
150     /// MCInstPrinter, if registered.
151     MCInstPrinterCtorTy MCInstPrinterCtorFn;
152
153     /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
154     /// if registered.
155     CodeEmitterCtorTy CodeEmitterCtorFn;
156
157     /// ObjectStreamerCtorFn - Construction function for this target's
158     /// ObjectStreamer, if registered.
159     ObjectStreamerCtorTy ObjectStreamerCtorFn;
160
161     /// AsmStreamerCtorFn - Construction function for this target's
162     /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
163     AsmStreamerCtorTy AsmStreamerCtorFn;
164
165   public:
166     Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
167
168     /// @name Target Information
169     /// @{
170
171     // getNext - Return the next registered target.
172     const Target *getNext() const { return Next; }
173
174     /// getName - Get the target name.
175     const char *getName() const { return Name; }
176
177     /// getShortDescription - Get a short description of the target.
178     const char *getShortDescription() const { return ShortDesc; }
179
180     /// @}
181     /// @name Feature Predicates
182     /// @{
183
184     /// hasJIT - Check if this targets supports the just-in-time compilation.
185     bool hasJIT() const { return HasJIT; }
186
187     /// hasTargetMachine - Check if this target supports code generation.
188     bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
189
190     /// hasAsmBackend - Check if this target supports .o generation.
191     bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
192
193     /// hasAsmLexer - Check if this target supports .s lexing.
194     bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
195
196     /// hasAsmParser - Check if this target supports .s parsing.
197     bool hasAsmParser() const { return AsmParserCtorFn != 0; }
198
199     /// hasAsmPrinter - Check if this target supports .s printing.
200     bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
201
202     /// hasMCDisassembler - Check if this target has a disassembler.
203     bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
204
205     /// hasMCInstPrinter - Check if this target has an instruction printer.
206     bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
207
208     /// hasCodeEmitter - Check if this target supports instruction encoding.
209     bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
210
211     /// hasObjectStreamer - Check if this target supports streaming to files.
212     bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
213
214     /// hasAsmStreamer - Check if this target supports streaming to files.
215     bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
216
217     /// @}
218     /// @name Feature Constructors
219     /// @{
220
221     /// createAsmInfo - Create a MCAsmInfo implementation for the specified
222     /// target triple.
223     ///
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 {
229       if (!AsmInfoCtorFn)
230         return 0;
231       return AsmInfoCtorFn(*this, Triple);
232     }
233
234     /// createTargetMachine - Create a target specific machine implementation
235     /// for the specified \arg Triple.
236     ///
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)
244         return 0;
245       return TargetMachineCtorFn(*this, Triple, Features);
246     }
247
248     /// createAsmBackend - Create a target specific assembly parser.
249     ///
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)
254         return 0;
255       return AsmBackendCtorFn(*this, Triple);
256     }
257
258     /// createAsmLexer - Create a target specific assembly lexer.
259     ///
260     TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
261       if (!AsmLexerCtorFn)
262         return 0;
263       return AsmLexerCtorFn(*this, MAI);
264     }
265
266     /// createAsmParser - Create a target specific assembly parser.
267     ///
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)
273         return 0;
274       return AsmParserCtorFn(*this, Parser, TM);
275     }
276
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)
281         return 0;
282       return AsmPrinterCtorFn(TM, Streamer);
283     }
284
285     MCDisassembler *createMCDisassembler() const {
286       if (!MCDisassemblerCtorFn)
287         return 0;
288       return MCDisassemblerCtorFn(*this);
289     }
290
291     MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
292                                        unsigned SyntaxVariant,
293                                        const MCAsmInfo &MAI) const {
294       if (!MCInstPrinterCtorFn)
295         return 0;
296       return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
297     }
298
299
300     /// createCodeEmitter - Create a target specific code emitter.
301     MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
302       if (!CodeEmitterCtorFn)
303         return 0;
304       return CodeEmitterCtorFn(*this, TM, Ctx);
305     }
306
307     /// createObjectStreamer - Create a target specific MCStreamer.
308     ///
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,
318                                      raw_ostream &_OS,
319                                      MCCodeEmitter *_Emitter,
320                                      bool RelaxAll,
321                                      bool NoExecStack) const {
322       if (!ObjectStreamerCtorFn)
323         return 0;
324       return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
325                                   NoExecStack);
326     }
327
328     /// createAsmStreamer - Create a target specific MCStreamer.
329     MCStreamer *createAsmStreamer(MCContext &Ctx,
330                                   formatted_raw_ostream &OS,
331                                   bool isVerboseAsm,
332                                   bool useLoc,
333                                   bool useCFI,
334                                   MCInstPrinter *InstPrint,
335                                   MCCodeEmitter *CE,
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);
341     }
342
343     /// @}
344   };
345
346   /// TargetRegistry - Generic interface to target specific features.
347   struct TargetRegistry {
348     class iterator {
349       const Target *Current;
350       explicit iterator(Target *T) : Current(T) {}
351       friend struct TargetRegistry;
352     public:
353       iterator(const iterator &I) : Current(I.Current) {}
354       iterator() : Current(0) {}
355
356       bool operator==(const iterator &x) const {
357         return Current == x.Current;
358       }
359       bool operator!=(const iterator &x) const {
360         return !operator==(x);
361       }
362
363       // Iterator traversal: forward iteration only
364       iterator &operator++() {          // Preincrement
365         assert(Current && "Cannot increment end iterator!");
366         Current = Current->getNext();
367         return *this;
368       }
369       iterator operator++(int) {        // Postincrement
370         iterator tmp = *this;
371         ++*this;
372         return tmp;
373       }
374
375       const Target &operator*() const {
376         assert(Current && "Cannot dereference end iterator!");
377         return *Current;
378       }
379
380       const Target *operator->() const {
381         return &operator*();
382       }
383     };
384
385     /// @name Registry Access
386     /// @{
387
388     static iterator begin();
389
390     static iterator end() { return iterator(); }
391
392     /// lookupTarget - Lookup a target based on a target triple.
393     ///
394     /// \param Triple - The triple to use for finding a target.
395     /// \param Error - On failure, an error string describing why no target was
396     /// found.
397     static const Target *lookupTarget(const std::string &Triple,
398                                       std::string &Error);
399
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.
403     ///
404     /// Maintained for compatibility through 2.6.
405     static const Target *getClosestTargetForJIT(std::string &Error);
406
407     /// @}
408     /// @name Target Registration
409     /// @{
410
411     /// RegisterTarget - Register the given target. Attempts to register a
412     /// target which has already been registered will be ignored.
413     ///
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.
417     ///
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
421     /// string.
422     /// @param TQualityFn - The triple match quality computation function for
423     /// this target.
424     /// @param HasJIT - Whether the target supports JIT code
425     /// generation.
426     static void RegisterTarget(Target &T,
427                                const char *Name,
428                                const char *ShortDesc,
429                                Target::TripleMatchQualityFnTy TQualityFn,
430                                bool HasJIT = false);
431
432     /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
433     /// given target.
434     ///
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.
438     ///
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;
445     }
446
447     /// RegisterTargetMachine - Register a TargetMachine implementation for the
448     /// given target.
449     ///
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.
453     ///
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;
461     }
462
463     /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
464     /// given target.
465     ///
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.
469     ///
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;
475     }
476
477     /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
478     /// given target.
479     ///
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.
483     ///
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;
489     }
490
491     /// RegisterAsmParser - Register a TargetAsmParser implementation for the
492     /// given target.
493     ///
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.
497     ///
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;
503     }
504
505     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
506     /// target.
507     ///
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.
511     ///
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;
518     }
519
520     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
521     /// the given target.
522     ///
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.
526     ///
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;
533     }
534
535     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
536     /// given target.
537     ///
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.
541     ///
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;
548     }
549
550     /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
551     /// given target.
552     ///
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.
556     ///
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;
562     }
563
564     /// RegisterObjectStreamer - Register a object code MCStreamer implementation
565     /// for the given target.
566     ///
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.
570     ///
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;
576     }
577
578     /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
579     /// for the given target.
580     ///
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.
584     ///
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;
590     }
591
592     /// @}
593   };
594
595
596   //===--------------------------------------------------------------------===//
597
598   /// RegisterTarget - Helper template for registering a target, for use in the
599   /// target's initialization function. Usage:
600   ///
601   ///
602   /// Target TheFooTarget; // The global target instance.
603   ///
604   /// extern "C" void LLVMInitializeFooTargetInfo() {
605   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
606   /// }
607   template<Triple::ArchType TargetArchType = Triple::InvalidArch,
608            bool HasJIT = false>
609   struct RegisterTarget {
610     RegisterTarget(Target &T, const char *Name, const char *Desc) {
611       TargetRegistry::RegisterTarget(T, Name, Desc,
612                                      &getTripleMatchQuality,
613                                      HasJIT);
614     }
615
616     static unsigned getTripleMatchQuality(const std::string &TT) {
617       if (Triple(TT).getArch() == TargetArchType)
618         return 20;
619       return 0;
620     }
621   };
622
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:
626   ///
627   /// extern "C" void LLVMInitializeFooTarget() {
628   ///   extern Target TheFooTarget;
629   ///   RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
630   /// }
631   template<class MCAsmInfoImpl>
632   struct RegisterAsmInfo {
633     RegisterAsmInfo(Target &T) {
634       TargetRegistry::RegisterAsmInfo(T, &Allocator);
635     }
636   private:
637     static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
638       return new MCAsmInfoImpl(T, TT);
639     }
640
641   };
642
643   /// RegisterAsmInfoFn - Helper template for registering a target assembly info
644   /// implementation.  This invokes the specified function to do the
645   /// construction.  Usage:
646   ///
647   /// extern "C" void LLVMInitializeFooTarget() {
648   ///   extern Target TheFooTarget;
649   ///   RegisterAsmInfoFn X(TheFooTarget, TheFunction);
650   /// }
651   struct RegisterAsmInfoFn {
652     RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
653       TargetRegistry::RegisterAsmInfo(T, Fn);
654     }
655   };
656
657
658   /// RegisterTargetMachine - Helper template for registering a target machine
659   /// implementation, for use in the target machine initialization
660   /// function. Usage:
661   ///
662   /// extern "C" void LLVMInitializeFooTarget() {
663   ///   extern Target TheFooTarget;
664   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
665   /// }
666   template<class TargetMachineImpl>
667   struct RegisterTargetMachine {
668     RegisterTargetMachine(Target &T) {
669       TargetRegistry::RegisterTargetMachine(T, &Allocator);
670     }
671
672   private:
673     static TargetMachine *Allocator(const Target &T, const std::string &TT,
674                                     const std::string &FS) {
675       return new TargetMachineImpl(T, TT, FS);
676     }
677   };
678
679   /// RegisterAsmBackend - Helper template for registering a target specific
680   /// assembler backend. Usage:
681   ///
682   /// extern "C" void LLVMInitializeFooAsmBackend() {
683   ///   extern Target TheFooTarget;
684   ///   RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
685   /// }
686   template<class AsmBackendImpl>
687   struct RegisterAsmBackend {
688     RegisterAsmBackend(Target &T) {
689       TargetRegistry::RegisterAsmBackend(T, &Allocator);
690     }
691
692   private:
693     static TargetAsmBackend *Allocator(const Target &T,
694                                        const std::string &Triple) {
695       return new AsmBackendImpl(T, Triple);
696     }
697   };
698
699   /// RegisterAsmLexer - Helper template for registering a target specific
700   /// assembly lexer, for use in the target machine initialization
701   /// function. Usage:
702   ///
703   /// extern "C" void LLVMInitializeFooAsmLexer() {
704   ///   extern Target TheFooTarget;
705   ///   RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
706   /// }
707   template<class AsmLexerImpl>
708   struct RegisterAsmLexer {
709     RegisterAsmLexer(Target &T) {
710       TargetRegistry::RegisterAsmLexer(T, &Allocator);
711     }
712
713   private:
714     static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
715       return new AsmLexerImpl(T, MAI);
716     }
717   };
718
719   /// RegisterAsmParser - Helper template for registering a target specific
720   /// assembly parser, for use in the target machine initialization
721   /// function. Usage:
722   ///
723   /// extern "C" void LLVMInitializeFooAsmParser() {
724   ///   extern Target TheFooTarget;
725   ///   RegisterAsmParser<FooAsmParser> X(TheFooTarget);
726   /// }
727   template<class AsmParserImpl>
728   struct RegisterAsmParser {
729     RegisterAsmParser(Target &T) {
730       TargetRegistry::RegisterAsmParser(T, &Allocator);
731     }
732
733   private:
734     static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
735                                       TargetMachine &TM) {
736       return new AsmParserImpl(T, P, TM);
737     }
738   };
739
740   /// RegisterAsmPrinter - Helper template for registering a target specific
741   /// assembly printer, for use in the target machine initialization
742   /// function. Usage:
743   ///
744   /// extern "C" void LLVMInitializeFooAsmPrinter() {
745   ///   extern Target TheFooTarget;
746   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
747   /// }
748   template<class AsmPrinterImpl>
749   struct RegisterAsmPrinter {
750     RegisterAsmPrinter(Target &T) {
751       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
752     }
753
754   private:
755     static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
756       return new AsmPrinterImpl(TM, Streamer);
757     }
758   };
759
760   /// RegisterCodeEmitter - Helper template for registering a target specific
761   /// machine code emitter, for use in the target initialization
762   /// function. Usage:
763   ///
764   /// extern "C" void LLVMInitializeFooCodeEmitter() {
765   ///   extern Target TheFooTarget;
766   ///   RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
767   /// }
768   template<class CodeEmitterImpl>
769   struct RegisterCodeEmitter {
770     RegisterCodeEmitter(Target &T) {
771       TargetRegistry::RegisterCodeEmitter(T, &Allocator);
772     }
773
774   private:
775     static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
776                                     MCContext &Ctx) {
777       return new CodeEmitterImpl(T, TM, Ctx);
778     }
779   };
780
781 }
782
783 #endif