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