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_TARGET_TARGETSELECT_H
00017 #define LLVM_TARGET_TARGETSELECT_H
00018 
00019 #include "llvm/Config/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 available assembly printer initialization functions.
00030 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
00031 #include "llvm/Config/AsmPrinters.def"
00032 
00033   // Declare all of the available assembly parser initialization functions.
00034 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
00035 #include "llvm/Config/AsmParsers.def"
00036 }
00037 
00038 namespace llvm {
00039   /// InitializeAllTargetInfos - The main program should call this function if
00040   /// it wants access to all available targets that LLVM is configured to
00041   /// support, to make them available via the TargetRegistry.
00042   ///
00043   /// It is legal for a client to make multiple calls to this function.
00044   inline void InitializeAllTargetInfos() {
00045 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
00046 #include "llvm/Config/Targets.def"
00047   }
00048   
00049   /// InitializeAllTargets - The main program should call this function if it
00050   /// wants access to all available target machines that LLVM is configured to
00051   /// support, to make them available via the TargetRegistry.
00052   ///
00053   /// It is legal for a client to make multiple calls to this function.
00054   inline void InitializeAllTargets() {
00055     // FIXME: Remove this, clients should do it.
00056     InitializeAllTargetInfos();
00057 
00058 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
00059 #include "llvm/Config/Targets.def"
00060   }
00061   
00062   /// InitializeAllAsmPrinters - The main program should call this function if
00063   /// it wants all asm printers that LLVM is configured to support, to make them
00064   /// available via the TargetRegistry.
00065   ///
00066   /// It is legal for a client to make multiple calls to this function.
00067   inline void InitializeAllAsmPrinters() {
00068 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
00069 #include "llvm/Config/AsmPrinters.def"
00070   }
00071   
00072   /// InitializeAllAsmParsers - The main program should call this function if it
00073   /// wants all asm parsers that LLVM is configured to support, to make them
00074   /// available via the TargetRegistry.
00075   ///
00076   /// It is legal for a client to make multiple calls to this function.
00077   inline void InitializeAllAsmParsers() {
00078 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
00079 #include "llvm/Config/AsmParsers.def"
00080   }
00081   
00082   /// InitializeNativeTarget - The main program should call this function to
00083   /// initialize the native target corresponding to the host.  This is useful 
00084   /// for JIT applications to ensure that the target gets linked in correctly.
00085   ///
00086   /// It is legal for a client to make multiple calls to this function.
00087   inline bool InitializeNativeTarget() {
00088   // If we have a native target, initialize it to ensure it is linked in.
00089 #ifdef LLVM_NATIVE_ARCH
00090 #define DoInit2(TARG) \
00091     LLVMInitialize ## TARG ## Info ();          \
00092     LLVMInitialize ## TARG ()
00093 #define DoInit(T) DoInit2(T)
00094     DoInit(LLVM_NATIVE_ARCH);
00095     return false;
00096 #undef DoInit
00097 #undef DoInit2
00098 #else
00099     return true;
00100 #endif
00101   }  
00102 }
00103 
00104 #endif