Targets: Add InitializeNativeTargetAsmPrinter(), patch by Jan Sjodin, although
[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/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   // FIXME: Workaround for unfortunate definition of LLVM_NATIVE_ARCH.
34 #define LLVM_ASM_PRINTER(TargetName) \
35   static inline void LLVMInitialize##TargetName##TargetAsmPrinter() { \
36     LLVMInitialize##TargetName##AsmPrinter(); \
37   }
38 #include "llvm/Config/AsmPrinters.def"
39
40   // Declare all of the available assembly parser initialization functions.
41 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
42 #include "llvm/Config/AsmParsers.def"
43
44   // Declare all of the available disassembler initialization functions.
45 #define LLVM_DISASSEMBLER(TargetName) void LLVMInitialize##TargetName##Disassembler();
46 #include "llvm/Config/Disassemblers.def"
47 }
48
49 namespace llvm {
50   /// InitializeAllTargetInfos - The main program should call this function if
51   /// it wants access to all available targets that LLVM is configured to
52   /// support, to make them available via the TargetRegistry.
53   ///
54   /// It is legal for a client to make multiple calls to this function.
55   inline void InitializeAllTargetInfos() {
56 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
57 #include "llvm/Config/Targets.def"
58   }
59   
60   /// InitializeAllTargets - The main program should call this function if it
61   /// wants access to all available target machines that LLVM is configured to
62   /// support, to make them available via the TargetRegistry.
63   ///
64   /// It is legal for a client to make multiple calls to this function.
65   inline void InitializeAllTargets() {
66     // FIXME: Remove this, clients should do it.
67     InitializeAllTargetInfos();
68
69 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
70 #include "llvm/Config/Targets.def"
71   }
72   
73   /// InitializeAllAsmPrinters - The main program should call this function if
74   /// it wants all asm printers that LLVM is configured to support, to make them
75   /// available via the TargetRegistry.
76   ///
77   /// It is legal for a client to make multiple calls to this function.
78   inline void InitializeAllAsmPrinters() {
79 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
80 #include "llvm/Config/AsmPrinters.def"
81   }
82   
83   /// InitializeAllAsmParsers - The main program should call this function if it
84   /// wants all asm parsers that LLVM is configured to support, to make them
85   /// available via the TargetRegistry.
86   ///
87   /// It is legal for a client to make multiple calls to this function.
88   inline void InitializeAllAsmParsers() {
89 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
90 #include "llvm/Config/AsmParsers.def"
91   }
92   
93   /// InitializeAllDisassemblers - The main program should call this function if
94   /// it wants all disassemblers that LLVM is configured to support, to make
95   /// them available via the TargetRegistry.
96   ///
97   /// It is legal for a client to make multiple calls to this function.
98   inline void InitializeAllDisassemblers() {
99 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
100 #include "llvm/Config/Disassemblers.def"
101   }
102   
103   /// InitializeNativeTarget - The main program should call this function to
104   /// initialize the native target corresponding to the host.  This is useful 
105   /// for JIT applications to ensure that the target gets linked in correctly.
106   ///
107   /// It is legal for a client to make multiple calls to this function.
108   inline bool InitializeNativeTarget() {
109   // If we have a native target, initialize it to ensure it is linked in.
110 #ifdef LLVM_NATIVE_ARCH
111 #define DoInit2(TARG) \
112     LLVMInitialize ## TARG ## Info ();          \
113     LLVMInitialize ## TARG ()
114 #define DoInit(T) DoInit2(T)
115     DoInit(LLVM_NATIVE_ARCH);
116     return false;
117 #undef DoInit
118 #undef DoInit2
119 #else
120     return true;
121 #endif
122   }  
123
124   /// InitializeNativeTargetAsmPrinter - The main program should call
125   /// this function to initialize the native target asm printer.
126   inline bool InitializeNativeTargetAsmPrinter() {
127   // If we have a native target, initialize the corresponding asm printer.
128 #ifdef LLVM_NATIVE_ARCH
129 #define DoInit2(TARG) \
130     LLVMInitialize ## TARG ## AsmPrinter ();
131 #define DoInit(T) DoInit2(T)
132     DoInit(LLVM_NATIVE_ARCH);
133     return false;
134 #undef DoInit
135 #undef DoInit2
136 #else
137     return true;
138 #endif
139   }  
140 }
141
142 #endif