LLVM API Documentation

Target.h
Go to the documentation of this file.
00001 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- 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 header declares the C interface to libLLVMTarget.a, which             */
00011 /* implements target information.                                             */
00012 /*                                                                            */
00013 /* Many exotic languages can interoperate with C code but have a harder time  */
00014 /* with C++ due to name mangling. So in addition to C, this interface enables */
00015 /* tools written in such languages.                                           */
00016 /*                                                                            */
00017 /*===----------------------------------------------------------------------===*/
00018 
00019 #ifndef LLVM_C_TARGET_H
00020 #define LLVM_C_TARGET_H
00021 
00022 #include "llvm-c/Core.h"
00023 #include "llvm/Config/llvm-config.h"
00024 
00025 #if defined(_MSC_VER) && !defined(inline)
00026 #define inline __inline
00027 #endif
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 /**
00034  * @defgroup LLVMCTarget Target information
00035  * @ingroup LLVMC
00036  *
00037  * @{
00038  */
00039 
00040 enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
00041 
00042 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
00043 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
00044 
00045 /* Declare all of the target-initialization functions that are available. */
00046 #define LLVM_TARGET(TargetName) \
00047   void LLVMInitialize##TargetName##TargetInfo(void);
00048 #include "llvm/Config/Targets.def"
00049 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00050 
00051 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
00052 #include "llvm/Config/Targets.def"
00053 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00054 
00055 #define LLVM_TARGET(TargetName) \
00056   void LLVMInitialize##TargetName##TargetMC(void);
00057 #include "llvm/Config/Targets.def"
00058 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00059 
00060 /* Declare all of the available assembly printer initialization functions. */
00061 #define LLVM_ASM_PRINTER(TargetName) \
00062   void LLVMInitialize##TargetName##AsmPrinter(void);
00063 #include "llvm/Config/AsmPrinters.def"
00064 #undef LLVM_ASM_PRINTER  /* Explicit undef to make SWIG happier */
00065 
00066 /* Declare all of the available assembly parser initialization functions. */
00067 #define LLVM_ASM_PARSER(TargetName) \
00068   void LLVMInitialize##TargetName##AsmParser(void);
00069 #include "llvm/Config/AsmParsers.def"
00070 #undef LLVM_ASM_PARSER  /* Explicit undef to make SWIG happier */
00071 
00072 /* Declare all of the available disassembler initialization functions. */
00073 #define LLVM_DISASSEMBLER(TargetName) \
00074   void LLVMInitialize##TargetName##Disassembler(void);
00075 #include "llvm/Config/Disassemblers.def"
00076 #undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
00077 
00078 /** LLVMInitializeAllTargetInfos - The main program should call this function if
00079     it wants access to all available targets that LLVM is configured to
00080     support. */
00081 static inline void LLVMInitializeAllTargetInfos(void) {
00082 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
00083 #include "llvm/Config/Targets.def"
00084 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00085 }
00086 
00087 /** LLVMInitializeAllTargets - The main program should call this function if it
00088     wants to link in all available targets that LLVM is configured to
00089     support. */
00090 static inline void LLVMInitializeAllTargets(void) {
00091 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
00092 #include "llvm/Config/Targets.def"
00093 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00094 }
00095 
00096 /** LLVMInitializeAllTargetMCs - The main program should call this function if
00097     it wants access to all available target MC that LLVM is configured to
00098     support. */
00099 static inline void LLVMInitializeAllTargetMCs(void) {
00100 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
00101 #include "llvm/Config/Targets.def"
00102 #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
00103 }
00104 
00105 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
00106     it wants all asm printers that LLVM is configured to support, to make them
00107     available via the TargetRegistry. */
00108 static inline void LLVMInitializeAllAsmPrinters(void) {
00109 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
00110 #include "llvm/Config/AsmPrinters.def"
00111 #undef LLVM_ASM_PRINTER  /* Explicit undef to make SWIG happier */
00112 }
00113 
00114 /** LLVMInitializeAllAsmParsers - The main program should call this function if
00115     it wants all asm parsers that LLVM is configured to support, to make them
00116     available via the TargetRegistry. */
00117 static inline void LLVMInitializeAllAsmParsers(void) {
00118 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
00119 #include "llvm/Config/AsmParsers.def"
00120 #undef LLVM_ASM_PARSER  /* Explicit undef to make SWIG happier */
00121 }
00122 
00123 /** LLVMInitializeAllDisassemblers - The main program should call this function
00124     if it wants all disassemblers that LLVM is configured to support, to make
00125     them available via the TargetRegistry. */
00126 static inline void LLVMInitializeAllDisassemblers(void) {
00127 #define LLVM_DISASSEMBLER(TargetName) \
00128   LLVMInitialize##TargetName##Disassembler();
00129 #include "llvm/Config/Disassemblers.def"
00130 #undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
00131 }
00132 
00133 /** LLVMInitializeNativeTarget - The main program should call this function to
00134     initialize the native target corresponding to the host.  This is useful
00135     for JIT applications to ensure that the target gets linked in correctly. */
00136 static inline LLVMBool LLVMInitializeNativeTarget(void) {
00137   /* If we have a native target, initialize it to ensure it is linked in. */
00138 #ifdef LLVM_NATIVE_TARGET
00139   LLVM_NATIVE_TARGETINFO();
00140   LLVM_NATIVE_TARGET();
00141   LLVM_NATIVE_TARGETMC();
00142   return 0;
00143 #else
00144   return 1;
00145 #endif
00146 }
00147 
00148 /** LLVMInitializeNativeTargetAsmParser - The main program should call this
00149     function to initialize the parser for the native target corresponding to the
00150     host. */
00151 static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
00152 #ifdef LLVM_NATIVE_ASMPARSER
00153   LLVM_NATIVE_ASMPARSER();
00154   return 0;
00155 #else
00156   return 1;
00157 #endif
00158 }
00159 
00160 /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
00161     function to initialize the printer for the native target corresponding to
00162     the host. */
00163 static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
00164 #ifdef LLVM_NATIVE_ASMPRINTER
00165   LLVM_NATIVE_ASMPRINTER();
00166   return 0;
00167 #else
00168   return 1;
00169 #endif
00170 }
00171 
00172 /** LLVMInitializeNativeTargetDisassembler - The main program should call this
00173     function to initialize the disassembler for the native target corresponding
00174     to the host. */
00175 static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
00176 #ifdef LLVM_NATIVE_DISASSEMBLER
00177   LLVM_NATIVE_DISASSEMBLER();
00178   return 0;
00179 #else
00180   return 1;
00181 #endif
00182 }
00183 
00184 /*===-- Target Data -------------------------------------------------------===*/
00185 
00186 /** Creates target data from a target layout string.
00187     See the constructor llvm::DataLayout::DataLayout. */
00188 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
00189 
00190 /** Adds target data information to a pass manager. This does not take ownership
00191     of the target data.
00192     See the method llvm::PassManagerBase::add. */
00193 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM);
00194 
00195 /** Adds target library information to a pass manager. This does not take
00196     ownership of the target library info.
00197     See the method llvm::PassManagerBase::add. */
00198 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
00199                               LLVMPassManagerRef PM);
00200 
00201 /** Converts target data to a target layout string. The string must be disposed
00202     with LLVMDisposeMessage.
00203     See the constructor llvm::DataLayout::DataLayout. */
00204 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
00205 
00206 /** Returns the byte order of a target, either LLVMBigEndian or
00207     LLVMLittleEndian.
00208     See the method llvm::DataLayout::isLittleEndian. */
00209 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
00210 
00211 /** Returns the pointer size in bytes for a target.
00212     See the method llvm::DataLayout::getPointerSize. */
00213 unsigned LLVMPointerSize(LLVMTargetDataRef TD);
00214 
00215 /** Returns the pointer size in bytes for a target for a specified
00216     address space.
00217     See the method llvm::DataLayout::getPointerSize. */
00218 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
00219 
00220 /** Returns the integer type that is the same size as a pointer on a target.
00221     See the method llvm::DataLayout::getIntPtrType. */
00222 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
00223 
00224 /** Returns the integer type that is the same size as a pointer on a target.
00225     This version allows the address space to be specified.
00226     See the method llvm::DataLayout::getIntPtrType. */
00227 LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
00228 
00229 /** Returns the integer type that is the same size as a pointer on a target.
00230     See the method llvm::DataLayout::getIntPtrType. */
00231 LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
00232 
00233 /** Returns the integer type that is the same size as a pointer on a target.
00234     This version allows the address space to be specified.
00235     See the method llvm::DataLayout::getIntPtrType. */
00236 LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
00237                                          unsigned AS);
00238 
00239 /** Computes the size of a type in bytes for a target.
00240     See the method llvm::DataLayout::getTypeSizeInBits. */
00241 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00242 
00243 /** Computes the storage size of a type in bytes for a target.
00244     See the method llvm::DataLayout::getTypeStoreSize. */
00245 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00246 
00247 /** Computes the ABI size of a type in bytes for a target.
00248     See the method llvm::DataLayout::getTypeAllocSize. */
00249 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00250 
00251 /** Computes the ABI alignment of a type in bytes for a target.
00252     See the method llvm::DataLayout::getTypeABISize. */
00253 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00254 
00255 /** Computes the call frame alignment of a type in bytes for a target.
00256     See the method llvm::DataLayout::getTypeABISize. */
00257 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00258 
00259 /** Computes the preferred alignment of a type in bytes for a target.
00260     See the method llvm::DataLayout::getTypeABISize. */
00261 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
00262 
00263 /** Computes the preferred alignment of a global variable in bytes for a target.
00264     See the method llvm::DataLayout::getPreferredAlignment. */
00265 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
00266                                         LLVMValueRef GlobalVar);
00267 
00268 /** Computes the structure element that contains the byte offset for a target.
00269     See the method llvm::StructLayout::getElementContainingOffset. */
00270 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
00271                              unsigned long long Offset);
00272 
00273 /** Computes the byte offset of the indexed struct element for a target.
00274     See the method llvm::StructLayout::getElementContainingOffset. */
00275 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
00276                                        LLVMTypeRef StructTy, unsigned Element);
00277 
00278 /** Deallocates a TargetData.
00279     See the destructor llvm::DataLayout::~DataLayout. */
00280 void LLVMDisposeTargetData(LLVMTargetDataRef TD);
00281 
00282 /**
00283  * @}
00284  */
00285 
00286 #ifdef __cplusplus
00287 }
00288 #endif /* defined(__cplusplus) */
00289 
00290 #endif