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 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 29 | /** |
| 30 | * @defgroup LLVMCTarget Target information |
| 31 | * @ingroup LLVMC |
| 32 | * |
| 33 | * @{ |
| 34 | */ |
| 35 | |
Chris Lattner | d686c8e | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 36 | enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian }; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 37 | |
| 38 | typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 39 | typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 40 | typedef struct LLVMStructLayout *LLVMStructLayoutRef; |
| 41 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 42 | /* Declare all of the target-initialization functions that are available. */ |
Eric Christopher | ca3ca13 | 2010-07-12 05:13:35 +0000 | [diff] [blame] | 43 | #define LLVM_TARGET(TargetName) \ |
| 44 | void LLVMInitialize##TargetName##TargetInfo(void); |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 45 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 46 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 47 | |
Chris Lattner | ff33d83 | 2010-04-28 20:24:45 +0000 | [diff] [blame] | 48 | #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 49 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 50 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 51 | |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 52 | #define LLVM_TARGET(TargetName) \ |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 53 | void LLVMInitialize##TargetName##TargetMC(void); |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 54 | #include "llvm/Config/Targets.def" |
| 55 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 56 | |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 57 | /* Declare all of the available assembly printer initialization functions. */ |
| 58 | #define LLVM_ASM_PRINTER(TargetName) \ |
| 59 | void LLVMInitialize##TargetName##AsmPrinter(); |
| 60 | #include "llvm/Config/AsmPrinters.def" |
| 61 | |
| 62 | /* Declare all of the available assembly parser initialization functions. */ |
| 63 | #define LLVM_ASM_PARSER(TargetName) \ |
| 64 | void LLVMInitialize##TargetName##AsmParser(); |
| 65 | #include "llvm/Config/AsmParsers.def" |
| 66 | |
| 67 | /* Declare all of the available disassembler initialization functions. */ |
| 68 | #define LLVM_DISASSEMBLER(TargetName) \ |
| 69 | void LLVMInitialize##TargetName##Disassembler(); |
| 70 | #include "llvm/Config/Disassemblers.def" |
| 71 | |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 72 | /** LLVMInitializeAllTargetInfos - The main program should call this function if |
| 73 | it wants access to all available targets that LLVM is configured to |
| 74 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 75 | static inline void LLVMInitializeAllTargetInfos(void) { |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 76 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); |
| 77 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 78 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Daniel Dunbar | baf3edd | 2009-08-18 03:03:27 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 81 | /** LLVMInitializeAllTargets - The main program should call this function if it |
| 82 | wants to link in all available targets that LLVM is configured to |
| 83 | support. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 84 | static inline void LLVMInitializeAllTargets(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 85 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); |
| 86 | #include "llvm/Config/Targets.def" |
Chris Lattner | b6219ba | 2009-12-21 07:52:40 +0000 | [diff] [blame] | 87 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 88 | } |
Daniel Dunbar | 72736d1 | 2011-11-29 00:06:55 +0000 | [diff] [blame] | 89 | |
| 90 | /** LLVMInitializeAllTargetMCs - The main program should call this function if |
| 91 | it wants access to all available target MC that LLVM is configured to |
| 92 | support. */ |
| 93 | static inline void LLVMInitializeAllTargetMCs(void) { |
| 94 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC(); |
| 95 | #include "llvm/Config/Targets.def" |
| 96 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ |
| 97 | } |
| 98 | |
| 99 | /** LLVMInitializeAllAsmPrinters - The main program should call this function if |
| 100 | it wants all asm printers that LLVM is configured to support, to make them |
| 101 | available via the TargetRegistry. */ |
| 102 | static inline void LLVMInitializeAllAsmPrinters() { |
| 103 | #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter(); |
| 104 | #include "llvm/Config/AsmPrinters.def" |
| 105 | #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ |
| 106 | } |
| 107 | |
| 108 | /** LLVMInitializeAllAsmParsers - The main program should call this function if |
| 109 | it wants all asm parsers that LLVM is configured to support, to make them |
| 110 | available via the TargetRegistry. */ |
| 111 | static inline void LLVMInitializeAllAsmParsers() { |
| 112 | #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser(); |
| 113 | #include "llvm/Config/AsmParsers.def" |
| 114 | #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ |
| 115 | } |
| 116 | |
| 117 | /** LLVMInitializeAllDisassemblers - The main program should call this function |
| 118 | if it wants all disassemblers that LLVM is configured to support, to make |
| 119 | them available via the TargetRegistry. */ |
| 120 | static inline void LLVMInitializeAllDisassemblers() { |
| 121 | #define LLVM_DISASSEMBLER(TargetName) \ |
| 122 | LLVMInitialize##TargetName##Disassembler(); |
| 123 | #include "llvm/Config/Disassemblers.def" |
| 124 | #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ |
| 125 | } |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 126 | |
| 127 | /** LLVMInitializeNativeTarget - The main program should call this function to |
| 128 | initialize the native target corresponding to the host. This is useful |
| 129 | for JIT applications to ensure that the target gets linked in correctly. */ |
Chris Lattner | c799c55 | 2010-04-29 23:27:32 +0000 | [diff] [blame] | 130 | static inline LLVMBool LLVMInitializeNativeTarget(void) { |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 131 | /* 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] | 132 | #ifdef LLVM_NATIVE_TARGET |
| 133 | LLVM_NATIVE_TARGETINFO(); |
| 134 | LLVM_NATIVE_TARGET(); |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 135 | LLVM_NATIVE_TARGETMC(); |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 136 | return 0; |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 137 | #else |
| 138 | return 1; |
| 139 | #endif |
| 140 | } |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 141 | |
| 142 | /*===-- Target Data -------------------------------------------------------===*/ |
| 143 | |
| 144 | /** Creates target data from a target layout string. |
| 145 | See the constructor llvm::TargetData::TargetData. */ |
| 146 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); |
| 147 | |
| 148 | /** Adds target data information to a pass manager. This does not take ownership |
| 149 | of the target data. |
| 150 | See the method llvm::PassManagerBase::add. */ |
| 151 | void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); |
| 152 | |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 153 | /** Adds target library information to a pass manager. This does not take |
| 154 | ownership of the target library info. |
| 155 | See the method llvm::PassManagerBase::add. */ |
| 156 | void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef); |
| 157 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 158 | /** Converts target data to a target layout string. The string must be disposed |
| 159 | with LLVMDisposeMessage. |
| 160 | See the constructor llvm::TargetData::TargetData. */ |
| 161 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); |
| 162 | |
| 163 | /** Returns the byte order of a target, either LLVMBigEndian or |
| 164 | LLVMLittleEndian. |
| 165 | See the method llvm::TargetData::isLittleEndian. */ |
Chris Lattner | 10bc755 | 2010-01-09 23:25:21 +0000 | [diff] [blame] | 166 | enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 167 | |
| 168 | /** Returns the pointer size in bytes for a target. |
| 169 | See the method llvm::TargetData::getPointerSize. */ |
| 170 | unsigned LLVMPointerSize(LLVMTargetDataRef); |
| 171 | |
| 172 | /** Returns the integer type that is the same size as a pointer on a target. |
| 173 | See the method llvm::TargetData::getIntPtrType. */ |
| 174 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); |
| 175 | |
| 176 | /** Computes the size of a type in bytes for a target. |
| 177 | See the method llvm::TargetData::getTypeSizeInBits. */ |
| 178 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); |
| 179 | |
| 180 | /** Computes the storage size of a type in bytes for a target. |
| 181 | See the method llvm::TargetData::getTypeStoreSize. */ |
| 182 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 183 | |
| 184 | /** Computes the ABI size of a type in bytes for a target. |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 185 | See the method llvm::TargetData::getTypeAllocSize. */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 186 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 187 | |
| 188 | /** Computes the ABI alignment of a type in bytes for a target. |
| 189 | See the method llvm::TargetData::getTypeABISize. */ |
| 190 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 191 | |
| 192 | /** Computes the call frame alignment of a type in bytes for a target. |
| 193 | See the method llvm::TargetData::getTypeABISize. */ |
| 194 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 195 | |
| 196 | /** Computes the preferred alignment of a type in bytes for a target. |
| 197 | See the method llvm::TargetData::getTypeABISize. */ |
| 198 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); |
| 199 | |
| 200 | /** Computes the preferred alignment of a global variable in bytes for a target. |
| 201 | See the method llvm::TargetData::getPreferredAlignment. */ |
| 202 | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, |
| 203 | LLVMValueRef GlobalVar); |
| 204 | |
| 205 | /** Computes the structure element that contains the byte offset for a target. |
| 206 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 207 | unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 208 | unsigned long long Offset); |
| 209 | |
| 210 | /** Computes the byte offset of the indexed struct element for a target. |
| 211 | See the method llvm::StructLayout::getElementContainingOffset. */ |
| 212 | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, |
| 213 | unsigned Element); |
| 214 | |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 215 | /** Deallocates a TargetData. |
| 216 | See the destructor llvm::TargetData::~TargetData. */ |
| 217 | void LLVMDisposeTargetData(LLVMTargetDataRef); |
| 218 | |
Gregory Szorc | 6244b51 | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 219 | /** |
| 220 | * @} |
| 221 | */ |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 222 | |
| 223 | #ifdef __cplusplus |
| 224 | } |
| 225 | |
| 226 | namespace llvm { |
| 227 | class TargetData; |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 228 | class TargetLibraryInfo; |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 229 | |
| 230 | inline TargetData *unwrap(LLVMTargetDataRef P) { |
| 231 | return reinterpret_cast<TargetData*>(P); |
| 232 | } |
| 233 | |
| 234 | inline LLVMTargetDataRef wrap(const TargetData *P) { |
| 235 | return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P)); |
| 236 | } |
Rafael Espindola | 5160d38 | 2011-07-25 21:20:54 +0000 | [diff] [blame] | 237 | |
| 238 | inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) { |
| 239 | return reinterpret_cast<TargetLibraryInfo*>(P); |
| 240 | } |
| 241 | |
| 242 | inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) { |
| 243 | TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P); |
| 244 | return reinterpret_cast<LLVMTargetLibraryInfoRef>(X); |
| 245 | } |
Gordon Henriksen | 3e0c835 | 2008-03-16 20:08:03 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | #endif /* defined(__cplusplus) */ |
| 249 | |
| 250 | #endif |