LLVM API Documentation

TargetSelect.h
Go to the documentation of this file.
00001 //===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file provides utilities to make sure that certain classes of targets are
00011 // linked into the main application executable, and initialize them as
00012 // appropriate.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_SUPPORT_TARGETSELECT_H
00017 #define LLVM_SUPPORT_TARGETSELECT_H
00018 
00019 #include "llvm/Config/llvm-config.h"
00020 
00021 extern "C" {
00022   // Declare all of the target-initialization functions that are available.
00023 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
00024 #include "llvm/Config/Targets.def"
00025 
00026 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
00027 #include "llvm/Config/Targets.def"
00028   
00029   // Declare all of the target-MC-initialization functions that are available.
00030 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
00031 #include "llvm/Config/Targets.def"
00032   
00033   // Declare all of the available assembly printer initialization functions.
00034 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
00035 #include "llvm/Config/AsmPrinters.def"
00036 
00037   // Declare all of the available assembly parser initialization functions.
00038 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
00039 #include "llvm/Config/AsmParsers.def"
00040 
00041   // Declare all of the available disassembler initialization functions.
00042 #define LLVM_DISASSEMBLER(TargetName) \
00043   void LLVMInitialize##TargetName##Disassembler();
00044 #include "llvm/Config/Disassemblers.def"
00045 }
00046 
00047 namespace llvm {
00048   /// InitializeAllTargetInfos - The main program should call this function if
00049   /// it wants access to all available targets that LLVM is configured to
00050   /// support, to make them available via the TargetRegistry.
00051   ///
00052   /// It is legal for a client to make multiple calls to this function.
00053   inline void InitializeAllTargetInfos() {
00054 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
00055 #include "llvm/Config/Targets.def"
00056   }
00057   
00058   /// InitializeAllTargets - The main program should call this function if it
00059   /// wants access to all available target machines that LLVM is configured to
00060   /// support, to make them available via the TargetRegistry.
00061   ///
00062   /// It is legal for a client to make multiple calls to this function.
00063   inline void InitializeAllTargets() {
00064     // FIXME: Remove this, clients should do it.
00065     InitializeAllTargetInfos();
00066 
00067 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
00068 #include "llvm/Config/Targets.def"
00069   }
00070   
00071   /// InitializeAllTargetMCs - The main program should call this function if it
00072   /// wants access to all available target MC that LLVM is configured to
00073   /// support, to make them available via the TargetRegistry.
00074   ///
00075   /// It is legal for a client to make multiple calls to this function.
00076   inline void InitializeAllTargetMCs() {
00077 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
00078 #include "llvm/Config/Targets.def"
00079   }
00080   
00081   /// InitializeAllAsmPrinters - The main program should call this function if
00082   /// it wants all asm printers that LLVM is configured to support, to make them
00083   /// available via the TargetRegistry.
00084   ///
00085   /// It is legal for a client to make multiple calls to this function.
00086   inline void InitializeAllAsmPrinters() {
00087 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
00088 #include "llvm/Config/AsmPrinters.def"
00089   }
00090   
00091   /// InitializeAllAsmParsers - The main program should call this function if it
00092   /// wants all asm parsers that LLVM is configured to support, to make them
00093   /// available via the TargetRegistry.
00094   ///
00095   /// It is legal for a client to make multiple calls to this function.
00096   inline void InitializeAllAsmParsers() {
00097 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
00098 #include "llvm/Config/AsmParsers.def"
00099   }
00100   
00101   /// InitializeAllDisassemblers - The main program should call this function if
00102   /// it wants all disassemblers that LLVM is configured to support, to make
00103   /// them available via the TargetRegistry.
00104   ///
00105   /// It is legal for a client to make multiple calls to this function.
00106   inline void InitializeAllDisassemblers() {
00107 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
00108 #include "llvm/Config/Disassemblers.def"
00109   }
00110   
00111   /// InitializeNativeTarget - The main program should call this function to
00112   /// initialize the native target corresponding to the host.  This is useful 
00113   /// for JIT applications to ensure that the target gets linked in correctly.
00114   ///
00115   /// It is legal for a client to make multiple calls to this function.
00116   inline bool InitializeNativeTarget() {
00117   // If we have a native target, initialize it to ensure it is linked in.
00118 #ifdef LLVM_NATIVE_TARGET
00119     LLVM_NATIVE_TARGETINFO();
00120     LLVM_NATIVE_TARGET();
00121     LLVM_NATIVE_TARGETMC();
00122     return false;
00123 #else
00124     return true;
00125 #endif
00126   }  
00127 
00128   /// InitializeNativeTargetAsmPrinter - The main program should call
00129   /// this function to initialize the native target asm printer.
00130   inline bool InitializeNativeTargetAsmPrinter() {
00131   // If we have a native target, initialize the corresponding asm printer.
00132 #ifdef LLVM_NATIVE_ASMPRINTER
00133     LLVM_NATIVE_ASMPRINTER();
00134     return false;
00135 #else
00136     return true;
00137 #endif
00138   }  
00139 
00140   /// InitializeNativeTargetAsmParser - The main program should call
00141   /// this function to initialize the native target asm parser.
00142   inline bool InitializeNativeTargetAsmParser() {
00143   // If we have a native target, initialize the corresponding asm parser.
00144 #ifdef LLVM_NATIVE_ASMPARSER
00145     LLVM_NATIVE_ASMPARSER();
00146     return false;
00147 #else
00148     return true;
00149 #endif
00150   }  
00151 
00152   /// InitializeNativeTargetDisassembler - The main program should call
00153   /// this function to initialize the native target disassembler.
00154   inline bool InitializeNativeTargetDisassembler() {
00155   // If we have a native target, initialize the corresponding disassembler.
00156 #ifdef LLVM_NATIVE_DISASSEMBLER
00157     LLVM_NATIVE_DISASSEMBLER();
00158     return false;
00159 #else
00160     return true;
00161 #endif
00162   }  
00163 
00164 }
00165 
00166 #endif