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