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