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