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