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