1 //===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_TARGETSELECT_H
17 #define LLVM_TARGET_TARGETSELECT_H
19 #include "llvm/Config/config.h"
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"
26 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
27 #include "llvm/Config/Targets.def"
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"
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(); \
38 #include "llvm/Config/AsmPrinters.def"
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"
44 // Declare all of the available disassembler initialization functions.
45 #define LLVM_DISASSEMBLER(TargetName) void LLVMInitialize##TargetName##Disassembler();
46 #include "llvm/Config/Disassemblers.def"
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.
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"
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.
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();
69 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
70 #include "llvm/Config/Targets.def"
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.
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"
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.
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"
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.
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"
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.
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);
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);