OSDN Git Service

Generate compact unwind encoding from CFI directives.
[android-x86/external-llvm.git] / include / llvm / Support / TargetRegistry.h
1 //===-- Support/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_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
21
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/CodeGen.h"
24 #include "llvm-c/Disassembler.h"
25 #include <cassert>
26 #include <string>
27
28 namespace llvm {
29   class AsmPrinter;
30   class Module;
31   class MCAssembler;
32   class MCAsmBackend;
33   class MCAsmInfo;
34   class MCAsmParser;
35   class MCCodeEmitter;
36   class MCCodeGenInfo;
37   class MCContext;
38   class MCDisassembler;
39   class MCInstrAnalysis;
40   class MCInstPrinter;
41   class MCInstrInfo;
42   class MCRegisterInfo;
43   class MCStreamer;
44   class MCSubtargetInfo;
45   class MCSymbolizer;
46   class MCRelocationInfo;
47   class MCTargetAsmParser;
48   class TargetMachine;
49   class TargetOptions;
50   class raw_ostream;
51   class formatted_raw_ostream;
52
53   MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
54                                 bool isVerboseAsm,
55                                 bool useLoc, bool useCFI,
56                                 bool useDwarfDirectory,
57                                 MCInstPrinter *InstPrint,
58                                 MCCodeEmitter *CE,
59                                 MCAsmBackend *TAB,
60                                 bool ShowInst);
61
62   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
63
64   MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
65                                    LLVMSymbolLookupCallback SymbolLookUp,
66                                    void *DisInfo,
67                                    MCContext *Ctx,
68                                    MCRelocationInfo *RelInfo);
69
70   /// Target - Wrapper for Target specific information.
71   ///
72   /// For registration purposes, this is a POD type so that targets can be
73   /// registered without the use of static constructors.
74   ///
75   /// Targets should implement a single global instance of this class (which
76   /// will be zero initialized), and pass that instance to the TargetRegistry as
77   /// part of their initialization.
78   class Target {
79   public:
80     friend struct TargetRegistry;
81
82     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
83
84     typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
85                                             StringRef TT);
86     typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
87                                                     Reloc::Model RM,
88                                                     CodeModel::Model CM,
89                                                     CodeGenOpt::Level OL);
90     typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
91     typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
92     typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
93     typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
94                                                         StringRef CPU,
95                                                         StringRef Features);
96     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
97                                                   StringRef TT,
98                                                   StringRef CPU,
99                                                   StringRef Features,
100                                                   const TargetOptions &Options,
101                                                   Reloc::Model RM,
102                                                   CodeModel::Model CM,
103                                                   CodeGenOpt::Level OL);
104     typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
105                                             MCStreamer &Streamer);
106     typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
107                                                 const MCRegisterInfo &MRI,
108                                                 StringRef TT,
109                                                 StringRef CPU);
110     typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
111                                                     MCAsmParser &P);
112     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
113                                                     const MCSubtargetInfo &STI);
114     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
115                                                   unsigned SyntaxVariant,
116                                                   const MCAsmInfo &MAI,
117                                                   const MCInstrInfo &MII,
118                                                   const MCRegisterInfo &MRI,
119                                                   const MCSubtargetInfo &STI);
120     typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
121                                                   const MCRegisterInfo &MRI,
122                                                   const MCSubtargetInfo &STI,
123                                                   MCContext &Ctx);
124     typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
125                                                   StringRef TT,
126                                                   MCContext &Ctx,
127                                                   MCAsmBackend &TAB,
128                                                   raw_ostream &_OS,
129                                                   MCCodeEmitter *_Emitter,
130                                                   bool RelaxAll,
131                                                   bool NoExecStack);
132     typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
133                                              formatted_raw_ostream &OS,
134                                              bool isVerboseAsm,
135                                              bool useLoc,
136                                              bool useCFI,
137                                              bool useDwarfDirectory,
138                                              MCInstPrinter *InstPrint,
139                                              MCCodeEmitter *CE,
140                                              MCAsmBackend *TAB,
141                                              bool ShowInst);
142     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
143                                                         MCContext &Ctx);
144     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
145                                    LLVMOpInfoCallback GetOpInfo,
146                                    LLVMSymbolLookupCallback SymbolLookUp,
147                                    void *DisInfo,
148                                    MCContext *Ctx,
149                                    MCRelocationInfo *RelInfo);
150
151   private:
152     /// Next - The next registered target in the linked list, maintained by the
153     /// TargetRegistry.
154     Target *Next;
155
156     /// TripleMatchQualityFn - The target function for rating the match quality
157     /// of a triple.
158     TripleMatchQualityFnTy TripleMatchQualityFn;
159
160     /// Name - The target name.
161     const char *Name;
162
163     /// ShortDesc - A short description of the target.
164     const char *ShortDesc;
165
166     /// HasJIT - Whether this target supports the JIT.
167     bool HasJIT;
168
169     /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
170     /// registered.
171     MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
172
173     /// MCCodeGenInfoCtorFn - Constructor function for this target's
174     /// MCCodeGenInfo, if registered.
175     MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
176
177     /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
178     /// if registered.
179     MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
180
181     /// MCInstrAnalysisCtorFn - Constructor function for this target's
182     /// MCInstrAnalysis, if registered.
183     MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
184
185     /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
186     /// if registered.
187     MCRegInfoCtorFnTy MCRegInfoCtorFn;
188
189     /// MCSubtargetInfoCtorFn - Constructor function for this target's
190     /// MCSubtargetInfo, if registered.
191     MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
192
193     /// TargetMachineCtorFn - Construction function for this target's
194     /// TargetMachine, if registered.
195     TargetMachineCtorTy TargetMachineCtorFn;
196
197     /// MCAsmBackendCtorFn - Construction function for this target's
198     /// MCAsmBackend, if registered.
199     MCAsmBackendCtorTy MCAsmBackendCtorFn;
200
201     /// MCAsmParserCtorFn - Construction function for this target's
202     /// MCTargetAsmParser, if registered.
203     MCAsmParserCtorTy MCAsmParserCtorFn;
204
205     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
206     /// if registered.
207     AsmPrinterCtorTy AsmPrinterCtorFn;
208
209     /// MCDisassemblerCtorFn - Construction function for this target's
210     /// MCDisassembler, if registered.
211     MCDisassemblerCtorTy MCDisassemblerCtorFn;
212
213     /// MCInstPrinterCtorFn - Construction function for this target's
214     /// MCInstPrinter, if registered.
215     MCInstPrinterCtorTy MCInstPrinterCtorFn;
216
217     /// MCCodeEmitterCtorFn - Construction function for this target's
218     /// CodeEmitter, if registered.
219     MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
220
221     /// MCObjectStreamerCtorFn - Construction function for this target's
222     /// MCObjectStreamer, if registered.
223     MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
224
225     /// AsmStreamerCtorFn - Construction function for this target's
226     /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
227     AsmStreamerCtorTy AsmStreamerCtorFn;
228
229     /// MCRelocationInfoCtorFn - Construction function for this target's
230     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
231     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
232
233     /// MCSymbolizerCtorFn - Construction function for this target's
234     /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
235     MCSymbolizerCtorTy MCSymbolizerCtorFn;
236
237   public:
238     Target() : AsmStreamerCtorFn(llvm::createAsmStreamer),
239                MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
240                MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
241
242     /// @name Target Information
243     /// @{
244
245     // getNext - Return the next registered target.
246     const Target *getNext() const { return Next; }
247
248     /// getName - Get the target name.
249     const char *getName() const { return Name; }
250
251     /// getShortDescription - Get a short description of the target.
252     const char *getShortDescription() const { return ShortDesc; }
253
254     /// @}
255     /// @name Feature Predicates
256     /// @{
257
258     /// hasJIT - Check if this targets supports the just-in-time compilation.
259     bool hasJIT() const { return HasJIT; }
260
261     /// hasTargetMachine - Check if this target supports code generation.
262     bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
263
264     /// hasMCAsmBackend - Check if this target supports .o generation.
265     bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
266
267     /// hasAsmParser - Check if this target supports .s parsing.
268     bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
269
270     /// hasAsmPrinter - Check if this target supports .s printing.
271     bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
272
273     /// hasMCDisassembler - Check if this target has a disassembler.
274     bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
275
276     /// hasMCInstPrinter - Check if this target has an instruction printer.
277     bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
278
279     /// hasMCCodeEmitter - Check if this target supports instruction encoding.
280     bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
281
282     /// hasMCObjectStreamer - Check if this target supports streaming to files.
283     bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
284
285     /// hasAsmStreamer - Check if this target supports streaming to files.
286     bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
287
288     /// @}
289     /// @name Feature Constructors
290     /// @{
291
292     /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
293     /// target triple.
294     ///
295     /// \param Triple This argument is used to determine the target machine
296     /// feature set; it should always be provided. Generally this should be
297     /// either the target triple from the module, or the target triple of the
298     /// host if that does not exist.
299     MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
300                                StringRef Triple) const {
301       if (!MCAsmInfoCtorFn)
302         return 0;
303       return MCAsmInfoCtorFn(MRI, Triple);
304     }
305
306     /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
307     ///
308     MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
309                                        CodeModel::Model CM,
310                                        CodeGenOpt::Level OL) const {
311       if (!MCCodeGenInfoCtorFn)
312         return 0;
313       return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
314     }
315
316     /// createMCInstrInfo - Create a MCInstrInfo implementation.
317     ///
318     MCInstrInfo *createMCInstrInfo() const {
319       if (!MCInstrInfoCtorFn)
320         return 0;
321       return MCInstrInfoCtorFn();
322     }
323
324     /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
325     ///
326     MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
327       if (!MCInstrAnalysisCtorFn)
328         return 0;
329       return MCInstrAnalysisCtorFn(Info);
330     }
331
332     /// createMCRegInfo - Create a MCRegisterInfo implementation.
333     ///
334     MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
335       if (!MCRegInfoCtorFn)
336         return 0;
337       return MCRegInfoCtorFn(Triple);
338     }
339
340     /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
341     ///
342     /// \param Triple This argument is used to determine the target machine
343     /// feature set; it should always be provided. Generally this should be
344     /// either the target triple from the module, or the target triple of the
345     /// host if that does not exist.
346     /// \param CPU This specifies the name of the target CPU.
347     /// \param Features This specifies the string representation of the
348     /// additional target features.
349     MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
350                                            StringRef Features) const {
351       if (!MCSubtargetInfoCtorFn)
352         return 0;
353       return MCSubtargetInfoCtorFn(Triple, CPU, Features);
354     }
355
356     /// createTargetMachine - Create a target specific machine implementation
357     /// for the specified \p Triple.
358     ///
359     /// \param Triple This argument is used to determine the target machine
360     /// feature set; it should always be provided. Generally this should be
361     /// either the target triple from the module, or the target triple of the
362     /// host if that does not exist.
363     TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
364                              StringRef Features, const TargetOptions &Options,
365                              Reloc::Model RM = Reloc::Default,
366                              CodeModel::Model CM = CodeModel::Default,
367                              CodeGenOpt::Level OL = CodeGenOpt::Default) const {
368       if (!TargetMachineCtorFn)
369         return 0;
370       return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
371                                  RM, CM, OL);
372     }
373
374     /// createMCAsmBackend - Create a target specific assembly parser.
375     ///
376     /// \param Triple The target triple string.
377     MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
378                                      StringRef Triple, StringRef CPU) const {
379       if (!MCAsmBackendCtorFn)
380         return 0;
381       return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
382     }
383
384     /// createMCAsmParser - Create a target specific assembly parser.
385     ///
386     /// \param Parser The target independent parser implementation to use for
387     /// parsing and lexing.
388     MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
389                                          MCAsmParser &Parser) const {
390       if (!MCAsmParserCtorFn)
391         return 0;
392       return MCAsmParserCtorFn(STI, Parser);
393     }
394
395     /// createAsmPrinter - Create a target specific assembly printer pass.  This
396     /// takes ownership of the MCStreamer object.
397     AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
398       if (!AsmPrinterCtorFn)
399         return 0;
400       return AsmPrinterCtorFn(TM, Streamer);
401     }
402
403     MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
404       if (!MCDisassemblerCtorFn)
405         return 0;
406       return MCDisassemblerCtorFn(*this, STI);
407     }
408
409     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
410                                        const MCAsmInfo &MAI,
411                                        const MCInstrInfo &MII,
412                                        const MCRegisterInfo &MRI,
413                                        const MCSubtargetInfo &STI) const {
414       if (!MCInstPrinterCtorFn)
415         return 0;
416       return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
417     }
418
419
420     /// createMCCodeEmitter - Create a target specific code emitter.
421     MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
422                                        const MCRegisterInfo &MRI,
423                                        const MCSubtargetInfo &STI,
424                                        MCContext &Ctx) const {
425       if (!MCCodeEmitterCtorFn)
426         return 0;
427       return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
428     }
429
430     /// createMCObjectStreamer - Create a target specific MCStreamer.
431     ///
432     /// \param TT The target triple.
433     /// \param Ctx The target context.
434     /// \param TAB The target assembler backend object. Takes ownership.
435     /// \param _OS The stream object.
436     /// \param _Emitter The target independent assembler object.Takes ownership.
437     /// \param RelaxAll Relax all fixups?
438     /// \param NoExecStack Mark file as not needing a executable stack.
439     MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
440                                        MCAsmBackend &TAB,
441                                        raw_ostream &_OS,
442                                        MCCodeEmitter *_Emitter,
443                                        bool RelaxAll,
444                                        bool NoExecStack) const {
445       if (!MCObjectStreamerCtorFn)
446         return 0;
447       return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
448                                     RelaxAll, NoExecStack);
449     }
450
451     /// createAsmStreamer - Create a target specific MCStreamer.
452     MCStreamer *createAsmStreamer(MCContext &Ctx,
453                                   formatted_raw_ostream &OS,
454                                   bool isVerboseAsm,
455                                   bool useLoc,
456                                   bool useCFI,
457                                   bool useDwarfDirectory,
458                                   MCInstPrinter *InstPrint,
459                                   MCCodeEmitter *CE,
460                                   MCAsmBackend *TAB,
461                                   bool ShowInst) const {
462       // AsmStreamerCtorFn is default to llvm::createAsmStreamer
463       return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
464                                useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
465     }
466
467     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
468     ///
469     /// \param TT The target triple.
470     /// \param Ctx The target context.
471     MCRelocationInfo *
472       createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
473       return MCRelocationInfoCtorFn(TT, Ctx);
474     }
475
476     /// createMCSymbolizer - Create a target specific MCSymbolizer.
477     ///
478     /// \param TT The target triple.
479     /// \param GetOpInfo The function to get the symbolic information for operands.
480     /// \param SymbolLookUp The function to lookup a symbol name.
481     /// \param DisInfo The pointer to the block of symbolic information for above call
482     /// back.
483     /// \param Ctx The target context.
484     /// \param RelInfo The relocation information for this target. Takes ownership.
485     MCSymbolizer *
486     createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
487                        LLVMSymbolLookupCallback SymbolLookUp,
488                        void *DisInfo,
489                        MCContext *Ctx, MCRelocationInfo *RelInfo) const {
490       return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
491                                 Ctx, RelInfo);
492     }
493
494     /// @}
495   };
496
497   /// TargetRegistry - Generic interface to target specific features.
498   struct TargetRegistry {
499     class iterator {
500       const Target *Current;
501       explicit iterator(Target *T) : Current(T) {}
502       friend struct TargetRegistry;
503     public:
504       iterator(const iterator &I) : Current(I.Current) {}
505       iterator() : Current(0) {}
506
507       bool operator==(const iterator &x) const {
508         return Current == x.Current;
509       }
510       bool operator!=(const iterator &x) const {
511         return !operator==(x);
512       }
513
514       // Iterator traversal: forward iteration only
515       iterator &operator++() {          // Preincrement
516         assert(Current && "Cannot increment end iterator!");
517         Current = Current->getNext();
518         return *this;
519       }
520       iterator operator++(int) {        // Postincrement
521         iterator tmp = *this;
522         ++*this;
523         return tmp;
524       }
525
526       const Target &operator*() const {
527         assert(Current && "Cannot dereference end iterator!");
528         return *Current;
529       }
530
531       const Target *operator->() const {
532         return &operator*();
533       }
534     };
535
536     /// printRegisteredTargetsForVersion - Print the registered targets
537     /// appropriately for inclusion in a tool's version output.
538     static void printRegisteredTargetsForVersion();
539
540     /// @name Registry Access
541     /// @{
542
543     static iterator begin();
544
545     static iterator end() { return iterator(); }
546
547     /// lookupTarget - Lookup a target based on a target triple.
548     ///
549     /// \param Triple - The triple to use for finding a target.
550     /// \param Error - On failure, an error string describing why no target was
551     /// found.
552     static const Target *lookupTarget(const std::string &Triple,
553                                       std::string &Error);
554
555     /// lookupTarget - Lookup a target based on an architecture name
556     /// and a target triple.  If the architecture name is non-empty,
557     /// then the lookup is done by architecture.  Otherwise, the target
558     /// triple is used.
559     ///
560     /// \param ArchName - The architecture to use for finding a target.
561     /// \param TheTriple - The triple to use for finding a target.  The
562     /// triple is updated with canonical architecture name if a lookup
563     /// by architecture is done.
564     /// \param Error - On failure, an error string describing why no target was
565     /// found.
566     static const Target *lookupTarget(const std::string &ArchName,
567                                       Triple &TheTriple,
568                                       std::string &Error);
569
570     /// getClosestTargetForJIT - Pick the best target that is compatible with
571     /// the current host.  If no close target can be found, this returns null
572     /// and sets the Error string to a reason.
573     ///
574     /// Maintained for compatibility through 2.6.
575     static const Target *getClosestTargetForJIT(std::string &Error);
576
577     /// @}
578     /// @name Target Registration
579     /// @{
580
581     /// RegisterTarget - Register the given target. Attempts to register a
582     /// target which has already been registered will be ignored.
583     ///
584     /// Clients are responsible for ensuring that registration doesn't occur
585     /// while another thread is attempting to access the registry. Typically
586     /// this is done by initializing all targets at program startup.
587     ///
588     /// @param T - The target being registered.
589     /// @param Name - The target name. This should be a static string.
590     /// @param ShortDesc - A short target description. This should be a static
591     /// string.
592     /// @param TQualityFn - The triple match quality computation function for
593     /// this target.
594     /// @param HasJIT - Whether the target supports JIT code
595     /// generation.
596     static void RegisterTarget(Target &T,
597                                const char *Name,
598                                const char *ShortDesc,
599                                Target::TripleMatchQualityFnTy TQualityFn,
600                                bool HasJIT = false);
601
602     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
603     /// given target.
604     ///
605     /// Clients are responsible for ensuring that registration doesn't occur
606     /// while another thread is attempting to access the registry. Typically
607     /// this is done by initializing all targets at program startup.
608     ///
609     /// @param T - The target being registered.
610     /// @param Fn - A function to construct a MCAsmInfo for the target.
611     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
612       // Ignore duplicate registration.
613       if (!T.MCAsmInfoCtorFn)
614         T.MCAsmInfoCtorFn = Fn;
615     }
616
617     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
618     /// given target.
619     ///
620     /// Clients are responsible for ensuring that registration doesn't occur
621     /// while another thread is attempting to access the registry. Typically
622     /// this is done by initializing all targets at program startup.
623     ///
624     /// @param T - The target being registered.
625     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
626     static void RegisterMCCodeGenInfo(Target &T,
627                                      Target::MCCodeGenInfoCtorFnTy Fn) {
628       // Ignore duplicate registration.
629       if (!T.MCCodeGenInfoCtorFn)
630         T.MCCodeGenInfoCtorFn = Fn;
631     }
632
633     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
634     /// given target.
635     ///
636     /// Clients are responsible for ensuring that registration doesn't occur
637     /// while another thread is attempting to access the registry. Typically
638     /// this is done by initializing all targets at program startup.
639     ///
640     /// @param T - The target being registered.
641     /// @param Fn - A function to construct a MCInstrInfo for the target.
642     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
643       // Ignore duplicate registration.
644       if (!T.MCInstrInfoCtorFn)
645         T.MCInstrInfoCtorFn = Fn;
646     }
647
648     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
649     /// the given target.
650     static void RegisterMCInstrAnalysis(Target &T,
651                                         Target::MCInstrAnalysisCtorFnTy Fn) {
652       // Ignore duplicate registration.
653       if (!T.MCInstrAnalysisCtorFn)
654         T.MCInstrAnalysisCtorFn = Fn;
655     }
656
657     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
658     /// given target.
659     ///
660     /// Clients are responsible for ensuring that registration doesn't occur
661     /// while another thread is attempting to access the registry. Typically
662     /// this is done by initializing all targets at program startup.
663     ///
664     /// @param T - The target being registered.
665     /// @param Fn - A function to construct a MCRegisterInfo for the target.
666     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
667       // Ignore duplicate registration.
668       if (!T.MCRegInfoCtorFn)
669         T.MCRegInfoCtorFn = Fn;
670     }
671
672     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
673     /// the given target.
674     ///
675     /// Clients are responsible for ensuring that registration doesn't occur
676     /// while another thread is attempting to access the registry. Typically
677     /// this is done by initializing all targets at program startup.
678     ///
679     /// @param T - The target being registered.
680     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
681     static void RegisterMCSubtargetInfo(Target &T,
682                                         Target::MCSubtargetInfoCtorFnTy Fn) {
683       // Ignore duplicate registration.
684       if (!T.MCSubtargetInfoCtorFn)
685         T.MCSubtargetInfoCtorFn = Fn;
686     }
687
688     /// RegisterTargetMachine - Register a TargetMachine implementation for the
689     /// given target.
690     ///
691     /// Clients are responsible for ensuring that registration doesn't occur
692     /// while another thread is attempting to access the registry. Typically
693     /// this is done by initializing all targets at program startup.
694     ///
695     /// @param T - The target being registered.
696     /// @param Fn - A function to construct a TargetMachine for the target.
697     static void RegisterTargetMachine(Target &T,
698                                       Target::TargetMachineCtorTy Fn) {
699       // Ignore duplicate registration.
700       if (!T.TargetMachineCtorFn)
701         T.TargetMachineCtorFn = Fn;
702     }
703
704     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
705     /// given target.
706     ///
707     /// Clients are responsible for ensuring that registration doesn't occur
708     /// while another thread is attempting to access the registry. Typically
709     /// this is done by initializing all targets at program startup.
710     ///
711     /// @param T - The target being registered.
712     /// @param Fn - A function to construct an AsmBackend for the target.
713     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
714       if (!T.MCAsmBackendCtorFn)
715         T.MCAsmBackendCtorFn = Fn;
716     }
717
718     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
719     /// the given target.
720     ///
721     /// Clients are responsible for ensuring that registration doesn't occur
722     /// while another thread is attempting to access the registry. Typically
723     /// this is done by initializing all targets at program startup.
724     ///
725     /// @param T - The target being registered.
726     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
727     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
728       if (!T.MCAsmParserCtorFn)
729         T.MCAsmParserCtorFn = Fn;
730     }
731
732     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
733     /// target.
734     ///
735     /// Clients are responsible for ensuring that registration doesn't occur
736     /// while another thread is attempting to access the registry. Typically
737     /// this is done by initializing all targets at program startup.
738     ///
739     /// @param T - The target being registered.
740     /// @param Fn - A function to construct an AsmPrinter for the target.
741     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
742       // Ignore duplicate registration.
743       if (!T.AsmPrinterCtorFn)
744         T.AsmPrinterCtorFn = Fn;
745     }
746
747     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
748     /// the given target.
749     ///
750     /// Clients are responsible for ensuring that registration doesn't occur
751     /// while another thread is attempting to access the registry. Typically
752     /// this is done by initializing all targets at program startup.
753     ///
754     /// @param T - The target being registered.
755     /// @param Fn - A function to construct an MCDisassembler for the target.
756     static void RegisterMCDisassembler(Target &T,
757                                        Target::MCDisassemblerCtorTy Fn) {
758       if (!T.MCDisassemblerCtorFn)
759         T.MCDisassemblerCtorFn = Fn;
760     }
761
762     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
763     /// given target.
764     ///
765     /// Clients are responsible for ensuring that registration doesn't occur
766     /// while another thread is attempting to access the registry. Typically
767     /// this is done by initializing all targets at program startup.
768     ///
769     /// @param T - The target being registered.
770     /// @param Fn - A function to construct an MCInstPrinter for the target.
771     static void RegisterMCInstPrinter(Target &T,
772                                       Target::MCInstPrinterCtorTy Fn) {
773       if (!T.MCInstPrinterCtorFn)
774         T.MCInstPrinterCtorFn = Fn;
775     }
776
777     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
778     /// given target.
779     ///
780     /// Clients are responsible for ensuring that registration doesn't occur
781     /// while another thread is attempting to access the registry. Typically
782     /// this is done by initializing all targets at program startup.
783     ///
784     /// @param T - The target being registered.
785     /// @param Fn - A function to construct an MCCodeEmitter for the target.
786     static void RegisterMCCodeEmitter(Target &T,
787                                       Target::MCCodeEmitterCtorTy Fn) {
788       if (!T.MCCodeEmitterCtorFn)
789         T.MCCodeEmitterCtorFn = Fn;
790     }
791
792     /// RegisterMCObjectStreamer - Register a object code MCStreamer
793     /// implementation for the given target.
794     ///
795     /// Clients are responsible for ensuring that registration doesn't occur
796     /// while another thread is attempting to access the registry. Typically
797     /// this is done by initializing all targets at program startup.
798     ///
799     /// @param T - The target being registered.
800     /// @param Fn - A function to construct an MCStreamer for the target.
801     static void RegisterMCObjectStreamer(Target &T,
802                                          Target::MCObjectStreamerCtorTy Fn) {
803       if (!T.MCObjectStreamerCtorFn)
804         T.MCObjectStreamerCtorFn = Fn;
805     }
806
807     /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
808     /// for the given target.
809     ///
810     /// Clients are responsible for ensuring that registration doesn't occur
811     /// while another thread is attempting to access the registry. Typically
812     /// this is done by initializing all targets at program startup.
813     ///
814     /// @param T - The target being registered.
815     /// @param Fn - A function to construct an MCStreamer for the target.
816     static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
817       if (T.AsmStreamerCtorFn == createAsmStreamer)
818         T.AsmStreamerCtorFn = Fn;
819     }
820
821     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
822     /// implementation for the given target.
823     ///
824     /// Clients are responsible for ensuring that registration doesn't occur
825     /// while another thread is attempting to access the registry. Typically
826     /// this is done by initializing all targets at program startup.
827     ///
828     /// @param T - The target being registered.
829     /// @param Fn - A function to construct an MCRelocationInfo for the target.
830     static void RegisterMCRelocationInfo(Target &T,
831                                          Target::MCRelocationInfoCtorTy Fn) {
832       if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
833         T.MCRelocationInfoCtorFn = Fn;
834     }
835
836     /// RegisterMCSymbolizer - Register an MCSymbolizer
837     /// implementation for the given target.
838     ///
839     /// Clients are responsible for ensuring that registration doesn't occur
840     /// while another thread is attempting to access the registry. Typically
841     /// this is done by initializing all targets at program startup.
842     ///
843     /// @param T - The target being registered.
844     /// @param Fn - A function to construct an MCSymbolizer for the target.
845     static void RegisterMCSymbolizer(Target &T,
846                                      Target::MCSymbolizerCtorTy Fn) {
847       if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
848         T.MCSymbolizerCtorFn = Fn;
849     }
850
851     /// @}
852   };
853
854
855   //===--------------------------------------------------------------------===//
856
857   /// RegisterTarget - Helper template for registering a target, for use in the
858   /// target's initialization function. Usage:
859   ///
860   ///
861   /// Target TheFooTarget; // The global target instance.
862   ///
863   /// extern "C" void LLVMInitializeFooTargetInfo() {
864   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
865   /// }
866   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
867            bool HasJIT = false>
868   struct RegisterTarget {
869     RegisterTarget(Target &T, const char *Name, const char *Desc) {
870       TargetRegistry::RegisterTarget(T, Name, Desc,
871                                      &getTripleMatchQuality,
872                                      HasJIT);
873     }
874
875     static unsigned getTripleMatchQuality(const std::string &TT) {
876       if (Triple(TT).getArch() == TargetArchType)
877         return 20;
878       return 0;
879     }
880   };
881
882   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
883   /// implementation.  This invokes the static "Create" method on the class to
884   /// actually do the construction.  Usage:
885   ///
886   /// extern "C" void LLVMInitializeFooTarget() {
887   ///   extern Target TheFooTarget;
888   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
889   /// }
890   template<class MCAsmInfoImpl>
891   struct RegisterMCAsmInfo {
892     RegisterMCAsmInfo(Target &T) {
893       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
894     }
895   private:
896     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
897       return new MCAsmInfoImpl(TT);
898     }
899
900   };
901
902   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
903   /// implementation.  This invokes the specified function to do the
904   /// construction.  Usage:
905   ///
906   /// extern "C" void LLVMInitializeFooTarget() {
907   ///   extern Target TheFooTarget;
908   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
909   /// }
910   struct RegisterMCAsmInfoFn {
911     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
912       TargetRegistry::RegisterMCAsmInfo(T, Fn);
913     }
914   };
915
916   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
917   /// implementation.  This invokes the static "Create" method on the class
918   /// to actually do the construction.  Usage:
919   ///
920   /// extern "C" void LLVMInitializeFooTarget() {
921   ///   extern Target TheFooTarget;
922   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
923   /// }
924   template<class MCCodeGenInfoImpl>
925   struct RegisterMCCodeGenInfo {
926     RegisterMCCodeGenInfo(Target &T) {
927       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
928     }
929   private:
930     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
931                                     CodeModel::Model /*CM*/,
932                                     CodeGenOpt::Level /*OL*/) {
933       return new MCCodeGenInfoImpl();
934     }
935   };
936
937   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
938   /// info implementation.  This invokes the specified function to do the
939   /// construction.  Usage:
940   ///
941   /// extern "C" void LLVMInitializeFooTarget() {
942   ///   extern Target TheFooTarget;
943   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
944   /// }
945   struct RegisterMCCodeGenInfoFn {
946     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
947       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
948     }
949   };
950
951   /// RegisterMCInstrInfo - Helper template for registering a target instruction
952   /// info implementation.  This invokes the static "Create" method on the class
953   /// to actually do the construction.  Usage:
954   ///
955   /// extern "C" void LLVMInitializeFooTarget() {
956   ///   extern Target TheFooTarget;
957   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
958   /// }
959   template<class MCInstrInfoImpl>
960   struct RegisterMCInstrInfo {
961     RegisterMCInstrInfo(Target &T) {
962       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
963     }
964   private:
965     static MCInstrInfo *Allocator() {
966       return new MCInstrInfoImpl();
967     }
968   };
969
970   /// RegisterMCInstrInfoFn - Helper template for registering a target
971   /// instruction info implementation.  This invokes the specified function to
972   /// do the construction.  Usage:
973   ///
974   /// extern "C" void LLVMInitializeFooTarget() {
975   ///   extern Target TheFooTarget;
976   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
977   /// }
978   struct RegisterMCInstrInfoFn {
979     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
980       TargetRegistry::RegisterMCInstrInfo(T, Fn);
981     }
982   };
983
984   /// RegisterMCInstrAnalysis - Helper template for registering a target
985   /// instruction analyzer implementation.  This invokes the static "Create"
986   /// method on the class to actually do the construction.  Usage:
987   ///
988   /// extern "C" void LLVMInitializeFooTarget() {
989   ///   extern Target TheFooTarget;
990   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
991   /// }
992   template<class MCInstrAnalysisImpl>
993   struct RegisterMCInstrAnalysis {
994     RegisterMCInstrAnalysis(Target &T) {
995       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
996     }
997   private:
998     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
999       return new MCInstrAnalysisImpl(Info);
1000     }
1001   };
1002
1003   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1004   /// instruction analyzer implementation.  This invokes the specified function
1005   /// to do the construction.  Usage:
1006   ///
1007   /// extern "C" void LLVMInitializeFooTarget() {
1008   ///   extern Target TheFooTarget;
1009   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1010   /// }
1011   struct RegisterMCInstrAnalysisFn {
1012     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1013       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1014     }
1015   };
1016
1017   /// RegisterMCRegInfo - Helper template for registering a target register info
1018   /// implementation.  This invokes the static "Create" method on the class to
1019   /// actually do the construction.  Usage:
1020   ///
1021   /// extern "C" void LLVMInitializeFooTarget() {
1022   ///   extern Target TheFooTarget;
1023   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1024   /// }
1025   template<class MCRegisterInfoImpl>
1026   struct RegisterMCRegInfo {
1027     RegisterMCRegInfo(Target &T) {
1028       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1029     }
1030   private:
1031     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1032       return new MCRegisterInfoImpl();
1033     }
1034   };
1035
1036   /// RegisterMCRegInfoFn - Helper template for registering a target register
1037   /// info implementation.  This invokes the specified function to do the
1038   /// construction.  Usage:
1039   ///
1040   /// extern "C" void LLVMInitializeFooTarget() {
1041   ///   extern Target TheFooTarget;
1042   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1043   /// }
1044   struct RegisterMCRegInfoFn {
1045     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1046       TargetRegistry::RegisterMCRegInfo(T, Fn);
1047     }
1048   };
1049
1050   /// RegisterMCSubtargetInfo - Helper template for registering a target
1051   /// subtarget info implementation.  This invokes the static "Create" method
1052   /// on the class to actually do the construction.  Usage:
1053   ///
1054   /// extern "C" void LLVMInitializeFooTarget() {
1055   ///   extern Target TheFooTarget;
1056   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1057   /// }
1058   template<class MCSubtargetInfoImpl>
1059   struct RegisterMCSubtargetInfo {
1060     RegisterMCSubtargetInfo(Target &T) {
1061       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1062     }
1063   private:
1064     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1065                                       StringRef /*FS*/) {
1066       return new MCSubtargetInfoImpl();
1067     }
1068   };
1069
1070   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1071   /// subtarget info implementation.  This invokes the specified function to
1072   /// do the construction.  Usage:
1073   ///
1074   /// extern "C" void LLVMInitializeFooTarget() {
1075   ///   extern Target TheFooTarget;
1076   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1077   /// }
1078   struct RegisterMCSubtargetInfoFn {
1079     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1080       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1081     }
1082   };
1083
1084   /// RegisterTargetMachine - Helper template for registering a target machine
1085   /// implementation, for use in the target machine initialization
1086   /// function. Usage:
1087   ///
1088   /// extern "C" void LLVMInitializeFooTarget() {
1089   ///   extern Target TheFooTarget;
1090   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1091   /// }
1092   template<class TargetMachineImpl>
1093   struct RegisterTargetMachine {
1094     RegisterTargetMachine(Target &T) {
1095       TargetRegistry::RegisterTargetMachine(T, &Allocator);
1096     }
1097
1098   private:
1099     static TargetMachine *Allocator(const Target &T, StringRef TT,
1100                                     StringRef CPU, StringRef FS,
1101                                     const TargetOptions &Options,
1102                                     Reloc::Model RM,
1103                                     CodeModel::Model CM,
1104                                     CodeGenOpt::Level OL) {
1105       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1106     }
1107   };
1108
1109   /// RegisterMCAsmBackend - Helper template for registering a target specific
1110   /// assembler backend. Usage:
1111   ///
1112   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1113   ///   extern Target TheFooTarget;
1114   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1115   /// }
1116   template<class MCAsmBackendImpl>
1117   struct RegisterMCAsmBackend {
1118     RegisterMCAsmBackend(Target &T) {
1119       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1120     }
1121
1122   private:
1123     static MCAsmBackend *Allocator(const Target &T,
1124                                    const MCRegisterInfo &MRI,
1125                                    StringRef Triple, StringRef CPU) {
1126       return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1127     }
1128   };
1129
1130   /// RegisterMCAsmParser - Helper template for registering a target specific
1131   /// assembly parser, for use in the target machine initialization
1132   /// function. Usage:
1133   ///
1134   /// extern "C" void LLVMInitializeFooMCAsmParser() {
1135   ///   extern Target TheFooTarget;
1136   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1137   /// }
1138   template<class MCAsmParserImpl>
1139   struct RegisterMCAsmParser {
1140     RegisterMCAsmParser(Target &T) {
1141       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1142     }
1143
1144   private:
1145     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1146       return new MCAsmParserImpl(STI, P);
1147     }
1148   };
1149
1150   /// RegisterAsmPrinter - Helper template for registering a target specific
1151   /// assembly printer, for use in the target machine initialization
1152   /// function. Usage:
1153   ///
1154   /// extern "C" void LLVMInitializeFooAsmPrinter() {
1155   ///   extern Target TheFooTarget;
1156   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1157   /// }
1158   template<class AsmPrinterImpl>
1159   struct RegisterAsmPrinter {
1160     RegisterAsmPrinter(Target &T) {
1161       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1162     }
1163
1164   private:
1165     static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1166       return new AsmPrinterImpl(TM, Streamer);
1167     }
1168   };
1169
1170   /// RegisterMCCodeEmitter - Helper template for registering a target specific
1171   /// machine code emitter, for use in the target initialization
1172   /// function. Usage:
1173   ///
1174   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1175   ///   extern Target TheFooTarget;
1176   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1177   /// }
1178   template<class MCCodeEmitterImpl>
1179   struct RegisterMCCodeEmitter {
1180     RegisterMCCodeEmitter(Target &T) {
1181       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1182     }
1183
1184   private:
1185     static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1186                                     const MCRegisterInfo &/*MRI*/,
1187                                     const MCSubtargetInfo &/*STI*/,
1188                                     MCContext &/*Ctx*/) {
1189       return new MCCodeEmitterImpl();
1190     }
1191   };
1192
1193 }
1194
1195 #endif