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