Fix LLVM target initialization to deal with sociopathic outside projects
[oota-llvm.git] / include / llvm / Target / TargetSelect.h
1 //===- TargetSelect.h - Target Selection & 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 provides utilities to make sure that certain classes of targets are
11 // linked into the main application executable, and initialize them as
12 // appropriate.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_TARGETSELECT_H
17 #define LLVM_TARGET_TARGETSELECT_H
18
19 #include "llvm/Config/llvm-config.h"
20
21 extern "C" {
22   // Declare all of the target-initialization functions that are available.
23 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
24 #include "llvm/Config/Targets.def"
25
26 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
27 #include "llvm/Config/Targets.def"
28   
29   // Declare all of the available assembly printer initialization functions.
30 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
31 #include "llvm/Config/AsmPrinters.def"
32
33   // Declare all of the available assembly parser initialization functions.
34 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
35 #include "llvm/Config/AsmParsers.def"
36
37   // Declare all of the available disassembler initialization functions.
38 #define LLVM_DISASSEMBLER(TargetName) void LLVMInitialize##TargetName##Disassembler();
39 #include "llvm/Config/Disassemblers.def"
40 }
41
42 namespace llvm {
43   /// InitializeAllTargetInfos - The main program should call this function if
44   /// it wants access to all available targets that LLVM is configured to
45   /// support, to make them available via the TargetRegistry.
46   ///
47   /// It is legal for a client to make multiple calls to this function.
48   inline void InitializeAllTargetInfos() {
49 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
50 #include "llvm/Config/Targets.def"
51   }
52   
53   /// InitializeAllTargets - The main program should call this function if it
54   /// wants access to all available target machines that LLVM is configured to
55   /// support, to make them available via the TargetRegistry.
56   ///
57   /// It is legal for a client to make multiple calls to this function.
58   inline void InitializeAllTargets() {
59     // FIXME: Remove this, clients should do it.
60     InitializeAllTargetInfos();
61
62 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
63 #include "llvm/Config/Targets.def"
64   }
65   
66   /// InitializeAllAsmPrinters - The main program should call this function if
67   /// it wants all asm printers that LLVM is configured to support, to make them
68   /// available via the TargetRegistry.
69   ///
70   /// It is legal for a client to make multiple calls to this function.
71   inline void InitializeAllAsmPrinters() {
72 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
73 #include "llvm/Config/AsmPrinters.def"
74   }
75   
76   /// InitializeAllAsmParsers - The main program should call this function if it
77   /// wants all asm parsers that LLVM is configured to support, to make them
78   /// available via the TargetRegistry.
79   ///
80   /// It is legal for a client to make multiple calls to this function.
81   inline void InitializeAllAsmParsers() {
82 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
83 #include "llvm/Config/AsmParsers.def"
84   }
85   
86   /// InitializeAllDisassemblers - The main program should call this function if
87   /// it wants all disassemblers that LLVM is configured to support, to make
88   /// them available via the TargetRegistry.
89   ///
90   /// It is legal for a client to make multiple calls to this function.
91   inline void InitializeAllDisassemblers() {
92 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
93 #include "llvm/Config/Disassemblers.def"
94   }
95   
96   /// InitializeNativeTarget - The main program should call this function to
97   /// initialize the native target corresponding to the host.  This is useful 
98   /// for JIT applications to ensure that the target gets linked in correctly.
99   ///
100   /// It is legal for a client to make multiple calls to this function.
101   inline bool InitializeNativeTarget() {
102   // If we have a native target, initialize it to ensure it is linked in.
103 #ifdef LLVM_NATIVE_TARGET
104     LLVM_NATIVE_TARGETINFO();
105     LLVM_NATIVE_TARGET();
106     return false;
107 #else
108     return true;
109 #endif
110   }  
111
112   /// InitializeNativeTargetAsmPrinter - The main program should call
113   /// this function to initialize the native target asm printer.
114   inline bool InitializeNativeTargetAsmPrinter() {
115   // If we have a native target, initialize the corresponding asm printer.
116 #ifdef LLVM_NATIVE_ASMPRINTER
117     LLVM_NATIVE_ASMPRINTER();
118     return false;
119 #else
120     return true;
121 #endif
122   }  
123 }
124
125 #endif