Initialize the target info via the InitializeNativeTarget() hook.
[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 asm-printer initialization functions.
30 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
31 #include "llvm/Config/AsmPrinters.def"
32 }
33
34 namespace llvm {
35   /// InitializeAllTargets - The main program should call this function if it
36   /// wants access to all available targets that LLVM is configured to
37   /// support. This allows the client to query the available targets using the
38   /// target registration mechanisms.
39   inline void InitializeAllTargets() {
40 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
41 #include "llvm/Config/Targets.def"
42
43 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
44 #include "llvm/Config/Targets.def"
45   }
46   
47   /// InitializeAllAsmPrinters - The main program should call this function if
48   /// it wants all asm printers that LLVM is configured to support.  This will
49   /// cause them to be linked into its executable.
50   inline void InitializeAllAsmPrinters() {
51 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
52 #include "llvm/Config/AsmPrinters.def"
53   }
54   
55   /// InitializeNativeTarget - The main program should call this function to
56   /// initialize the native target corresponding to the host.  This is useful 
57   /// for JIT applications to ensure that the target gets linked in correctly.
58   inline bool InitializeNativeTarget() {
59   // If we have a native target, initialize it to ensure it is linked in.
60 #ifdef LLVM_NATIVE_ARCH
61 #define DoInit2(TARG) \
62     LLVMInitialize ## TARG ## Info ();          \
63     LLVMInitialize ## TARG ()
64 #define DoInit(T) DoInit2(T)
65     DoInit(LLVM_NATIVE_ARCH);
66     return false;
67 #undef DoInit
68 #undef DoInit2
69 #else
70     return true;
71 #endif
72   }  
73 }
74
75 #endif