8544eed76be7ebf35b2c9daa828820757ab4f09e
[oota-llvm.git] / include / llvm / Target / TargetSelect.h
1 //===- TargetSelect.h - Target Selection & Registration -------------------===//
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 namespace llvm {
22   // Declare all of the target-initialization functions that are available.
23 #define LLVM_TARGET(TargetName) void Initialize##TargetName##Target();
24 #include "llvm/Config/Targets.def"
25   
26   // Declare all of the available asm-printer initialization functions.
27   // Declare all of the target-initialization functions.
28 #define LLVM_ASM_PRINTER(TargetName) void Initialize##TargetName##AsmPrinter();
29 #include "llvm/Config/AsmPrinters.def"
30   
31   /// InitializeAllTargets - The main program should call this function if it
32   /// wants to link in all available targets that LLVM is configured to support.
33   inline void InitializeAllTargets() {
34 #define LLVM_TARGET(TargetName) llvm::Initialize##TargetName##Target();
35 #include "llvm/Config/Targets.def"
36   }
37   
38   /// InitializeAllAsmPrinters - The main program should call this function if
39   /// it wants all asm printers that LLVM is configured to support.  This will
40   /// cause them to be linked into its executable.
41   inline void InitializeAllAsmPrinters() {
42 #define LLVM_ASM_PRINTER(TargetName) Initialize##TargetName##AsmPrinter();
43 #include "llvm/Config/AsmPrinters.def"
44   }
45   
46   
47   /// InitializeNativeTarget - The main program should call this function to
48   /// initialize the native target corresponding to the host.  This is useful 
49   /// for JIT applications to ensure that the target gets linked in correctly.
50   inline bool InitializeNativeTarget() {
51   // If we have a native target, initialize it to ensure it is linked in.
52 #ifdef LLVM_NATIVE_ARCH
53 #define DoInit2(TARG, MOD)   llvm::Initialize ## TARG ## MOD()
54 #define DoInit(T, M) DoInit2(T, M)
55     DoInit(LLVM_NATIVE_ARCH, Target);
56     return false;
57 #undef DoInit
58 #undef DoInit2
59 #else
60     return true;
61 #endif
62   }  
63 }
64
65 #endif