Eric Christopher | eec5008 | 2010-08-08 02:44:17 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- 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 header declares the C interface to libLLVMTarget.a, which */ |
| 11 | /* implements target information. */ |
| 12 | /* */ |
| 13 | /* Many exotic languages can interoperate with C code but have a harder time */ |
| 14 | /* with C++ due to name mangling. So in addition to C, this interface enables */ |
| 15 | /* tools written in such languages. */ |
| 16 | /* */ |
| 17 | /*===----------------------------------------------------------------------===*/ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 18 | |
| 19 | #ifndef LLVM_C_TARGET_H |
| 20 | #define LLVM_C_TARGET_H |
| 21 | |
| 22 | #include "llvm-c/Core.h" |
Eric Christopher | eec5008 | 2010-08-08 02:44:17 +0000 | [diff] [blame] | 23 | #include "llvm/Config/llvm-config.h" |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
Chris Lattner | d686c8e | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 29 | enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian }; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 30 | |
| 31 | typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; |
| 32 | typedef struct LLVMStructLayout *LLVMStructLayoutRef; |
| 33 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 34 | /* Declare all of the target-initialization functions that are available. */ |
Eric Christopher | ca3ca13 | 2010-07-12 05:13:35 +0000 | [diff] [blame] | 35 | #define LLVM_TARGET(TargetName) \ |
| 36 | void LLVMInitialize##TargetName##TargetInfo(void); |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 37 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 38 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 39 | |
Chris Lattner | ff33d83 | 2010-04-28 20:24:45 +0000 | [diff] [blame] | 40 | #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 41 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 42 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 43 | |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 44 | #define LLVM_TARGET(TargetName) \ |
| 45 | void LLVMInitialize##TargetName##MCAsmInfo(void); |
| 46 | #include "llvm/Config/Targets.def" |
| 47 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 48 | |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame^] | 49 | #define LLVM_TARGET(TargetName) \ |
| 50 | void LLVMInitialize##TargetName##MCCodeGenInfo(void); |
| 51 | #include "llvm/Config/Targets.def" |
| 52 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 53 | |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 54 | /** LLVMInitializeAllTargetInfos - The main program should call this function if |
| 55 | it wants access to all available targets that LLVM is configured to |
| 56 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 57 | static inline void LLVMInitializeAllTargetInfos(void) { |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 58 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); |
| 59 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 60 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 63 | /** LLVMInitializeAllTargets - The main program should call this function if it |
| 64 | wants to link in all available targets that LLVM is configured to |
| 65 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 66 | static inline void LLVMInitializeAllTargets(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 67 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); |
| 68 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 69 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** LLVMInitializeNativeTarget - The main program should call this function to |
| 73 | initialize the native target corresponding to the host. This is useful |
| 74 | for JIT applications to ensure that the target gets linked in correctly. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 75 | static inline LLVMBool LLVMInitializeNativeTarget(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 76 | /* If we have a native target, initialize it to ensure it is linked in. */ |
Eric Christopher | 753f326 | 2010-08-30 18:34:48 +0000 | [diff] [blame] | 77 | #ifdef LLVM_NATIVE_TARGET |
| 78 | LLVM_NATIVE_TARGETINFO(); |
| 79 | LLVM_NATIVE_TARGET(); |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 80 | LLVM_NATIVE_MCASMINFO(); |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame^] | 81 | LLVM_NATIVE_MCCODEGENINFO(); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 82 | return 0; |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 83 | #else |
| 84 | return 1; |
| 85 | #endif |
| 86 | } |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 87 | |
| 88 | /*===-- Target Data -------------------------------------------------------===*/ |
| 89 | |
| 90 | /** Creates target data from a target layout string. |
| 91 | See the constructor llvm::TargetData::TargetData. */ |
| 92 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); |
| 93 | |
| 94 | /** Adds target data information to a pass manager. This does not take ownership |
| 95 | of the target data. |
| 96 | See the method llvm::PassManagerBase::add. */ |
| 97 | void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); |
| 98 | |
| 99 | /** Converts target data to a target layout string. The string must be disposed |
| 100 | with LLVMDisposeMessage. |
| 101 | See the constructor llvm::TargetData::TargetData. */ |
| 102 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); |
| 103 | |
| 104 | /** Returns the byte order of a target, either LLVMBigEndian or |
| 105 | LLVMLittleEndian. |
| 106 | See the method llvm::TargetData::isLittleEndian. */ |
Chris Lattner | 10bc755 | 2010-01-09 23:25:21 +0000 | [diff] [blame] | 107 | enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 108 | |
| 109 | /** Returns the pointer size in bytes for a target. |
| 110 | See the method llvm::TargetData::getPointerSize. */ |
| 111 | unsigned LLVMPointerSize(LLVMTargetDataRef); |
| 112 | |
| 113 | /** Returns the integer type that is the same size as a pointer on a target. |
| 114 | See the method llvm::TargetData::getIntPtrType. */ |
| 115 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); |
| 116 | |
| 117 | /** Computes the size of a type in bytes for a target. |
| 118 | See the method llvm::TargetData::getTypeSizeInBits. */ |
| 119 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); |
| 120 | |
| 121 | /** Computes the storage size of a type in bytes for a target. |
| 122 | See the method llvm::TargetData::getTypeStoreSize. */ |
| 123 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 124 | |
| 125 | /** Computes the ABI size of a type in bytes for a target. |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 126 | See the method llvm::TargetData::getTypeAllocSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 127 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 128 | |
| 129 | /** Computes the ABI alignment of a type in bytes for a target. |
| 130 | See the method llvm::TargetData::getTypeABISize. */ |
| 131 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 132 | |
| 133 | /** Computes the call frame alignment of a type in bytes for a target. |
| 134 | See the method llvm::TargetData::getTypeABISize. */ |
| 135 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 136 | |
| 137 | /** Computes the preferred alignment of a type in bytes for a target. |
| 138 | See the method llvm::TargetData::getTypeABISize. */ |
| 139 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 140 | |
| 141 | /** Computes the preferred alignment of a global variable in bytes for a target. |
| 142 | See the method llvm::TargetData::getPreferredAlignment. */ |
| 143 | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, |
| 144 | LLVMValueRef GlobalVar); |
| 145 | |
| 146 | /** Computes the structure element that contains the byte offset for a target. |
| 147 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 148 | unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 149 | unsigned long long Offset); |
| 150 | |
| 151 | /** Computes the byte offset of the indexed struct element for a target. |
| 152 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 153 | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 154 | unsigned Element); |
| 155 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 156 | /** Deallocates a TargetData. |
| 157 | See the destructor llvm::TargetData::~TargetData. */ |
| 158 | void LLVMDisposeTargetData(LLVMTargetDataRef); |
| 159 | |
| 160 | |
| 161 | #ifdef __cplusplus |
| 162 | } |
| 163 | |
| 164 | namespace llvm { |
| 165 | class TargetData; |
| 166 | |
| 167 | inline TargetData *unwrap(LLVMTargetDataRef P) { |
| 168 | return reinterpret_cast<TargetData*>(P); |
| 169 | } |
| 170 | |
| 171 | inline LLVMTargetDataRef wrap(const TargetData *P) { |
| 172 | return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P)); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | #endif /* defined(__cplusplus) */ |
| 177 | |
| 178 | #endif |