Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\ |
| 2 | |* *| |
| 3 | |* The LLVM Compiler Infrastructure *| |
| 4 | |* *| |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | |* This file is distributed under the University of Illinois Open Source *| |
| 6 | |* License. See LICENSE.TXT for details. *| |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
| 10 | |* This header declares the C interface to libLLVMCore.a, which implements *| |
| 11 | |* the LLVM intermediate representation. *| |
| 12 | |* *| |
| 13 | |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *| |
| 14 | |* parameters must be passed as base types. Despite the declared types, most *| |
| 15 | |* of the functions provided operate only on branches of the type hierarchy. *| |
| 16 | |* The declared parameter names are descriptive and specify which type is *| |
| 17 | |* required. Additionally, each type hierarchy is documented along with the *| |
| 18 | |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *| |
| 19 | |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *| |
| 20 | |* form unwrap<RequiredType>(Param). *| |
| 21 | |* *| |
| 22 | |* Many exotic languages can interoperate with C code but have a harder time *| |
| 23 | |* with C++ due to name mangling. So in addition to C, this interface enables *| |
| 24 | |* tools written in such languages. *| |
| 25 | |* *| |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 26 | |* When included into a C++ source file, also declares 'wrap' and 'unwrap' *| |
| 27 | |* helpers to perform opaque reference<-->pointer conversions. These helpers *| |
| 28 | |* are shorter and more tightly typed than writing the casts by hand when *| |
| 29 | |* authoring bindings. In assert builds, they will do runtime type checking. *| |
| 30 | |* *| |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 31 | \*===----------------------------------------------------------------------===*/ |
| 32 | |
| 33 | #ifndef LLVM_C_CORE_H |
| 34 | #define LLVM_C_CORE_H |
| 35 | |
| 36 | #ifdef __cplusplus |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 37 | |
| 38 | /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' |
| 39 | and 'unwrap' conversion functions. */ |
| 40 | #include "llvm/Module.h" |
| 41 | #include "llvm/Support/LLVMBuilder.h" |
| 42 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 43 | extern "C" { |
| 44 | #endif |
| 45 | |
| 46 | |
| 47 | /* Opaque types. */ |
| 48 | typedef struct LLVMOpaqueModule *LLVMModuleRef; |
| 49 | typedef struct LLVMOpaqueType *LLVMTypeRef; |
Gordon Henriksen | 1cf08fd | 2007-10-07 00:13:35 +0000 | [diff] [blame] | 50 | typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef; |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 51 | typedef struct LLVMOpaqueValue *LLVMValueRef; |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 52 | typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; |
| 53 | typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 54 | |
| 55 | /* Used to provide a module to JIT or interpreter. |
| 56 | * See the llvm::ModuleProvider class. |
| 57 | */ |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 58 | typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 59 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 60 | /* Used to provide a module to JIT or interpreter. |
| 61 | * See the llvm::MemoryBuffer class. |
| 62 | */ |
| 63 | typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; |
| 64 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 65 | typedef enum { |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 66 | LLVMVoidTypeKind, /* type with no size */ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 67 | LLVMFloatTypeKind, /* 32 bit floating point type */ |
| 68 | LLVMDoubleTypeKind, /* 64 bit floating point type */ |
| 69 | LLVMX86_FP80TypeKind, /* 80 bit floating point type (X87) */ |
| 70 | LLVMFP128TypeKind, /* 128 bit floating point type (112-bit mantissa) */ |
| 71 | LLVMPPC_FP128TypeKind, /* 128 bit floating point type (two 64-bits) */ |
| 72 | LLVMLabelTypeKind, /* Labels */ |
| 73 | LLVMIntegerTypeKind, /* Arbitrary bit width integers */ |
| 74 | LLVMFunctionTypeKind, /* Functions */ |
| 75 | LLVMStructTypeKind, /* Structures */ |
| 76 | LLVMArrayTypeKind, /* Arrays */ |
| 77 | LLVMPointerTypeKind, /* Pointers */ |
| 78 | LLVMOpaqueTypeKind, /* Opaque: type with unknown structure */ |
| 79 | LLVMVectorTypeKind /* SIMD 'packed' format, or other vector type */ |
| 80 | } LLVMTypeKind; |
| 81 | |
| 82 | typedef enum { |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 83 | LLVMExternalLinkage, /* Externally visible function */ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 84 | LLVMLinkOnceLinkage, /* Keep one copy of function when linking (inline) */ |
| 85 | LLVMWeakLinkage, /* Keep one copy of function when linking (weak) */ |
| 86 | LLVMAppendingLinkage, /* Special purpose, only applies to global arrays */ |
| 87 | LLVMInternalLinkage, /* Rename collisions when linking (static functions)*/ |
| 88 | LLVMDLLImportLinkage, /* Function to be imported from DLL */ |
| 89 | LLVMDLLExportLinkage, /* Function to be accessible from DLL */ |
| 90 | LLVMExternalWeakLinkage,/* ExternalWeak linkage description */ |
| 91 | LLVMGhostLinkage /* Stand-in functions for streaming fns from bitcode*/ |
| 92 | } LLVMLinkage; |
| 93 | |
| 94 | typedef enum { |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 95 | LLVMDefaultVisibility, /* The GV is visible */ |
| 96 | LLVMHiddenVisibility, /* The GV is hidden */ |
| 97 | LLVMProtectedVisibility /* The GV is protected */ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 98 | } LLVMVisibility; |
| 99 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 100 | typedef enum { |
| 101 | LLVMCCallConv = 0, |
| 102 | LLVMFastCallConv = 8, |
| 103 | LLVMColdCallConv = 9, |
| 104 | LLVMX86StdcallCallConv = 64, |
| 105 | LLVMX86FastcallCallConv = 65 |
| 106 | } LLVMCallConv; |
| 107 | |
| 108 | typedef enum { |
| 109 | LLVMIntEQ = 32, /* equal */ |
| 110 | LLVMIntNE, /* not equal */ |
| 111 | LLVMIntUGT, /* unsigned greater than */ |
| 112 | LLVMIntUGE, /* unsigned greater or equal */ |
| 113 | LLVMIntULT, /* unsigned less than */ |
| 114 | LLVMIntULE, /* unsigned less or equal */ |
| 115 | LLVMIntSGT, /* signed greater than */ |
| 116 | LLVMIntSGE, /* signed greater or equal */ |
| 117 | LLVMIntSLT, /* signed less than */ |
| 118 | LLVMIntSLE /* signed less or equal */ |
| 119 | } LLVMIntPredicate; |
| 120 | |
| 121 | typedef enum { |
| 122 | LLVMRealPredicateFalse, /* Always false (always folded) */ |
| 123 | LLVMRealOEQ, /* True if ordered and equal */ |
| 124 | LLVMRealOGT, /* True if ordered and greater than */ |
| 125 | LLVMRealOGE, /* True if ordered and greater than or equal */ |
| 126 | LLVMRealOLT, /* True if ordered and less than */ |
| 127 | LLVMRealOLE, /* True if ordered and less than or equal */ |
| 128 | LLVMRealONE, /* True if ordered and operands are unequal */ |
| 129 | LLVMRealORD, /* True if ordered (no nans) */ |
| 130 | LLVMRealUNO, /* True if unordered: isnan(X) | isnan(Y) */ |
| 131 | LLVMRealUEQ, /* True if unordered or equal */ |
| 132 | LLVMRealUGT, /* True if unordered or greater than */ |
| 133 | LLVMRealUGE, /* True if unordered, greater than, or equal */ |
| 134 | LLVMRealULT, /* True if unordered or less than */ |
| 135 | LLVMRealULE, /* True if unordered, less than, or equal */ |
| 136 | LLVMRealUNE, /* True if unordered or not equal */ |
| 137 | LLVMRealPredicateTrue /* Always true (always folded) */ |
| 138 | } LLVMRealPredicate; |
| 139 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 140 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 141 | /*===-- Error handling ----------------------------------------------------===*/ |
| 142 | |
| 143 | void LLVMDisposeMessage(char *Message); |
| 144 | |
| 145 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 146 | /*===-- Modules -----------------------------------------------------------===*/ |
| 147 | |
| 148 | /* Create and destroy modules. */ |
| 149 | LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); |
| 150 | void LLVMDisposeModule(LLVMModuleRef M); |
| 151 | |
Gordon Henriksen | a353ffa | 2007-12-27 20:13:47 +0000 | [diff] [blame] | 152 | /* Data layout */ |
| 153 | const char *LLVMGetDataLayout(LLVMModuleRef M); |
| 154 | void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); |
| 155 | |
| 156 | /* Target triple */ |
| 157 | const char *LLVMGetTarget(LLVMModuleRef M); |
| 158 | void LLVMSetTarget(LLVMModuleRef M, const char *Triple); |
| 159 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 160 | /* Same as Module::addTypeName. */ |
| 161 | int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 162 | void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 163 | |
| 164 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 165 | /*===-- Types -------------------------------------------------------------===*/ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 166 | |
| 167 | /* LLVM types conform to the following hierarchy: |
| 168 | * |
| 169 | * types: |
| 170 | * integer type |
| 171 | * real type |
| 172 | * function type |
| 173 | * sequence types: |
| 174 | * array type |
| 175 | * pointer type |
| 176 | * vector type |
| 177 | * void type |
| 178 | * label type |
| 179 | * opaque type |
| 180 | */ |
| 181 | |
| 182 | LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); |
| 183 | void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType); |
| 184 | |
| 185 | /* Operations on integer types */ |
| 186 | LLVMTypeRef LLVMInt1Type(); |
| 187 | LLVMTypeRef LLVMInt8Type(); |
| 188 | LLVMTypeRef LLVMInt16Type(); |
| 189 | LLVMTypeRef LLVMInt32Type(); |
| 190 | LLVMTypeRef LLVMInt64Type(); |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 191 | LLVMTypeRef LLVMIntType(unsigned NumBits); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 192 | unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 193 | |
| 194 | /* Operations on real types */ |
| 195 | LLVMTypeRef LLVMFloatType(); |
| 196 | LLVMTypeRef LLVMDoubleType(); |
| 197 | LLVMTypeRef LLVMX86FP80Type(); |
| 198 | LLVMTypeRef LLVMFP128Type(); |
| 199 | LLVMTypeRef LLVMPPCFP128Type(); |
| 200 | |
| 201 | /* Operations on function types */ |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 202 | LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, |
| 203 | LLVMTypeRef *ParamTypes, unsigned ParamCount, |
| 204 | int IsVarArg); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 205 | int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 206 | LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); |
| 207 | unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); |
| 208 | void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 209 | |
| 210 | /* Operations on struct types */ |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 211 | LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, |
| 212 | int Packed); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 213 | unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 214 | void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); |
| 215 | int LLVMIsPackedStruct(LLVMTypeRef StructTy); |
| 216 | |
| 217 | /* Operations on array, pointer, and vector types (sequence types) */ |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 218 | LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 219 | LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 220 | LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 221 | |
| 222 | LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); |
| 223 | unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 224 | unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 225 | unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); |
| 226 | |
| 227 | /* Operations on other types */ |
| 228 | LLVMTypeRef LLVMVoidType(); |
| 229 | LLVMTypeRef LLVMLabelType(); |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 230 | LLVMTypeRef LLVMOpaqueType(); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 231 | |
Gordon Henriksen | 1cf08fd | 2007-10-07 00:13:35 +0000 | [diff] [blame] | 232 | /* Operations on type handles */ |
| 233 | LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy); |
| 234 | void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy); |
| 235 | LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle); |
| 236 | void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle); |
| 237 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 238 | |
| 239 | /*===-- Values ------------------------------------------------------------===*/ |
| 240 | |
| 241 | /* The bulk of LLVM's object model consists of values, which comprise a very |
| 242 | * rich type hierarchy. |
| 243 | * |
| 244 | * values: |
| 245 | * constants: |
| 246 | * scalar constants |
| 247 | * composite contants |
| 248 | * globals: |
| 249 | * global variable |
| 250 | * function |
| 251 | * alias |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 252 | * basic blocks |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 253 | */ |
| 254 | |
| 255 | /* Operations on all values */ |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 256 | LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 257 | const char *LLVMGetValueName(LLVMValueRef Val); |
| 258 | void LLVMSetValueName(LLVMValueRef Val, const char *Name); |
Gordon Henriksen | 88cc699 | 2007-10-06 00:08:49 +0000 | [diff] [blame] | 259 | void LLVMDumpValue(LLVMValueRef Val); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 260 | |
| 261 | /* Operations on constants of any type */ |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 262 | LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ |
| 263 | LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 264 | LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 265 | int LLVMIsConstant(LLVMValueRef Val); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 266 | int LLVMIsNull(LLVMValueRef Val); |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 267 | int LLVMIsUndef(LLVMValueRef Val); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 268 | |
| 269 | /* Operations on scalar constants */ |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 270 | LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, |
| 271 | int SignExtend); |
| 272 | LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 273 | |
| 274 | /* Operations on composite constants */ |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 275 | LLVMValueRef LLVMConstString(const char *Str, unsigned Length, |
| 276 | int DontNullTerminate); |
| 277 | LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy, |
| 278 | LLVMValueRef *ConstantVals, unsigned Length); |
| 279 | LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, |
| 280 | int packed); |
| 281 | LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 282 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 283 | /* Constant expressions */ |
| 284 | LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); |
| 285 | LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); |
| 286 | LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); |
| 287 | LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 288 | LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 289 | LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 290 | LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 291 | LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 292 | LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 293 | LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 294 | LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 295 | LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 296 | LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 297 | LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 298 | LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 299 | LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, |
| 300 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 301 | LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, |
| 302 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 303 | LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 304 | LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 305 | LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 306 | LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, |
| 307 | LLVMValueRef *ConstantIndices, unsigned NumIndices); |
| 308 | LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 309 | LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 310 | LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 311 | LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 312 | LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 313 | LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 314 | LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 315 | LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 316 | LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 317 | LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 318 | LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 319 | LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 320 | LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, |
| 321 | LLVMValueRef ConstantIfTrue, |
| 322 | LLVMValueRef ConstantIfFalse); |
| 323 | LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, |
| 324 | LLVMValueRef IndexConstant); |
| 325 | LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, |
| 326 | LLVMValueRef ElementValueConstant, |
| 327 | LLVMValueRef IndexConstant); |
| 328 | LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, |
| 329 | LLVMValueRef VectorBConstant, |
| 330 | LLVMValueRef MaskConstant); |
| 331 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 332 | /* Operations on global variables, functions, and aliases (globals) */ |
| 333 | int LLVMIsDeclaration(LLVMValueRef Global); |
| 334 | LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); |
| 335 | void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); |
| 336 | const char *LLVMGetSection(LLVMValueRef Global); |
| 337 | void LLVMSetSection(LLVMValueRef Global, const char *Section); |
| 338 | LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); |
| 339 | void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); |
| 340 | unsigned LLVMGetAlignment(LLVMValueRef Global); |
| 341 | void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); |
| 342 | |
| 343 | /* Operations on global variables */ |
| 344 | LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 345 | LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 346 | void LLVMDeleteGlobal(LLVMValueRef GlobalVar); |
| 347 | int LLVMHasInitializer(LLVMValueRef GlobalVar); |
| 348 | LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); |
| 349 | void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); |
| 350 | int LLVMIsThreadLocal(LLVMValueRef GlobalVar); |
| 351 | void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal); |
Gordon Henriksen | c84c16b | 2007-10-07 17:31:42 +0000 | [diff] [blame] | 352 | int LLVMIsGlobalConstant(LLVMValueRef GlobalVar); |
| 353 | void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 354 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 355 | /* Operations on functions */ |
| 356 | LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, |
| 357 | LLVMTypeRef FunctionTy); |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 358 | LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 359 | void LLVMDeleteFunction(LLVMValueRef Fn); |
| 360 | unsigned LLVMCountParams(LLVMValueRef Fn); |
| 361 | void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); |
| 362 | LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); |
| 363 | unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); |
| 364 | unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); |
| 365 | void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 366 | const char *LLVMGetCollector(LLVMValueRef Fn); |
| 367 | void LLVMSetCollector(LLVMValueRef Fn, const char *Coll); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 368 | |
| 369 | /* Operations on basic blocks */ |
| 370 | LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb); |
| 371 | int LLVMValueIsBasicBlock(LLVMValueRef Val); |
| 372 | LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); |
| 373 | unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); |
| 374 | void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); |
| 375 | LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); |
| 376 | LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); |
| 377 | LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, |
| 378 | const char *Name); |
| 379 | void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); |
| 380 | |
Gordon Henriksen | cc0928f | 2007-12-29 20:45:00 +0000 | [diff] [blame^] | 381 | /* Operations on call sites */ |
| 382 | void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); |
| 383 | unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); |
| 384 | |
Gordon Henriksen | 2618a6c | 2007-10-08 18:14:39 +0000 | [diff] [blame] | 385 | /* Operations on phi nodes */ |
| 386 | void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, |
| 387 | LLVMBasicBlockRef *IncomingBlocks, unsigned Count); |
| 388 | unsigned LLVMCountIncoming(LLVMValueRef PhiNode); |
| 389 | LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); |
| 390 | LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 391 | |
| 392 | /*===-- Instruction builders ----------------------------------------------===*/ |
| 393 | |
| 394 | /* An instruction builder represents a point within a basic block, and is the |
| 395 | * exclusive means of building instructions using the C interface. |
| 396 | */ |
| 397 | |
| 398 | LLVMBuilderRef LLVMCreateBuilder(); |
| 399 | void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); |
| 400 | void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); |
| 401 | void LLVMDisposeBuilder(LLVMBuilderRef Builder); |
| 402 | |
| 403 | /* Terminators */ |
| 404 | LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); |
| 405 | LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); |
| 406 | LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); |
| 407 | LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, |
| 408 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); |
| 409 | LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, |
| 410 | LLVMBasicBlockRef Else, unsigned NumCases); |
| 411 | LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, |
| 412 | LLVMValueRef *Args, unsigned NumArgs, |
| 413 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, |
| 414 | const char *Name); |
| 415 | LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); |
| 416 | LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); |
| 417 | |
| 418 | /* Arithmetic */ |
| 419 | LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 420 | const char *Name); |
| 421 | LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 422 | const char *Name); |
| 423 | LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 424 | const char *Name); |
| 425 | LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 426 | const char *Name); |
| 427 | LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 428 | const char *Name); |
| 429 | LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 430 | const char *Name); |
| 431 | LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 432 | const char *Name); |
| 433 | LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 434 | const char *Name); |
| 435 | LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 436 | const char *Name); |
| 437 | LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 438 | const char *Name); |
| 439 | LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 440 | const char *Name); |
| 441 | LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 442 | const char *Name); |
| 443 | LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 444 | const char *Name); |
| 445 | LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 446 | const char *Name); |
| 447 | LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 448 | const char *Name); |
| 449 | LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); |
| 450 | LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); |
| 451 | |
| 452 | /* Memory */ |
| 453 | LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 454 | LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, |
| 455 | LLVMValueRef Val, const char *Name); |
| 456 | LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 457 | LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, |
| 458 | LLVMValueRef Val, const char *Name); |
| 459 | LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); |
| 460 | LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, |
| 461 | const char *Name); |
| 462 | LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); |
| 463 | LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 464 | LLVMValueRef *Indices, unsigned NumIndices, |
| 465 | const char *Name); |
| 466 | |
| 467 | /* Casts */ |
| 468 | LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, |
| 469 | LLVMTypeRef DestTy, const char *Name); |
| 470 | LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, |
| 471 | LLVMTypeRef DestTy, const char *Name); |
| 472 | LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, |
| 473 | LLVMTypeRef DestTy, const char *Name); |
| 474 | LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, |
| 475 | LLVMTypeRef DestTy, const char *Name); |
| 476 | LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, |
| 477 | LLVMTypeRef DestTy, const char *Name); |
| 478 | LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, |
| 479 | LLVMTypeRef DestTy, const char *Name); |
| 480 | LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, |
| 481 | LLVMTypeRef DestTy, const char *Name); |
| 482 | LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, |
| 483 | LLVMTypeRef DestTy, const char *Name); |
| 484 | LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, |
| 485 | LLVMTypeRef DestTy, const char *Name); |
| 486 | LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, |
| 487 | LLVMTypeRef DestTy, const char *Name); |
| 488 | LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, |
| 489 | LLVMTypeRef DestTy, const char *Name); |
| 490 | LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, |
| 491 | LLVMTypeRef DestTy, const char *Name); |
| 492 | |
| 493 | /* Comparisons */ |
| 494 | LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, |
| 495 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 496 | const char *Name); |
| 497 | LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, |
| 498 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 499 | const char *Name); |
| 500 | |
| 501 | /* Miscellaneous instructions */ |
| 502 | LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 503 | LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, |
| 504 | LLVMValueRef *Args, unsigned NumArgs, |
| 505 | const char *Name); |
| 506 | LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, |
| 507 | LLVMValueRef Then, LLVMValueRef Else, |
| 508 | const char *Name); |
| 509 | LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, |
| 510 | const char *Name); |
| 511 | LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, |
| 512 | LLVMValueRef Index, const char *Name); |
| 513 | LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, |
| 514 | LLVMValueRef EltVal, LLVMValueRef Index, |
| 515 | const char *Name); |
| 516 | LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, |
| 517 | LLVMValueRef V2, LLVMValueRef Mask, |
| 518 | const char *Name); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 519 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 520 | |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 521 | /*===-- Module providers --------------------------------------------------===*/ |
| 522 | |
| 523 | /* Encapsulates the module M in a module provider, taking ownership of the |
| 524 | * module. |
| 525 | * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider. |
| 526 | */ |
| 527 | LLVMModuleProviderRef |
| 528 | LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); |
| 529 | |
| 530 | /* Destroys the module provider MP as well as the contained module. |
| 531 | * See the destructor llvm::ModuleProvider::~ModuleProvider. |
| 532 | */ |
| 533 | void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP); |
| 534 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 535 | |
| 536 | /*===-- Memory buffers ----------------------------------------------------===*/ |
| 537 | |
| 538 | int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, |
| 539 | LLVMMemoryBufferRef *OutMemBuf, |
| 540 | char **OutMessage); |
| 541 | int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, |
| 542 | char **OutMessage); |
| 543 | void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); |
| 544 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 545 | #ifdef __cplusplus |
| 546 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 547 | |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 548 | namespace llvm { |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 549 | class ModuleProvider; |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 550 | class MemoryBuffer; |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 551 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 552 | #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ |
| 553 | inline ty *unwrap(ref P) { \ |
| 554 | return reinterpret_cast<ty*>(P); \ |
| 555 | } \ |
| 556 | \ |
| 557 | inline ref wrap(const ty *P) { \ |
| 558 | return reinterpret_cast<ref>(const_cast<ty*>(P)); \ |
| 559 | } |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 560 | |
Gordon Henriksen | 1d2e49c | 2007-12-27 18:25:59 +0000 | [diff] [blame] | 561 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Type, LLVMTypeRef ) |
| 562 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Value, LLVMValueRef ) |
| 563 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef ) |
| 564 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef ) |
| 565 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef ) |
| 566 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef ) |
| 567 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef) |
| 568 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef ) |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 569 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 570 | #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 571 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 572 | /* Specialized opaque type conversions. |
| 573 | */ |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 574 | template<typename T> |
| 575 | inline T *unwrap(LLVMTypeRef Ty) { |
| 576 | return cast<T>(unwrap(Ty)); |
| 577 | } |
| 578 | |
| 579 | inline Type **unwrap(LLVMTypeRef* Tys) { |
| 580 | return reinterpret_cast<Type**>(Tys); |
| 581 | } |
| 582 | |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 583 | inline LLVMTypeRef *wrap(const Type **Tys) { |
| 584 | return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); |
| 585 | } |
| 586 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 587 | /* Specialized opaque value conversions. |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 588 | */ |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 589 | template<typename T> |
| 590 | inline T *unwrap(LLVMValueRef Val) { |
| 591 | return cast<T>(unwrap(Val)); |
| 592 | } |
| 593 | |
| 594 | inline Value **unwrap(LLVMValueRef *Vals) { |
| 595 | return reinterpret_cast<Value**>(Vals); |
| 596 | } |
| 597 | |
| 598 | template<typename T> |
| 599 | inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { |
| 600 | #if DEBUG |
| 601 | for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I) |
| 602 | cast<T>(*I); |
| 603 | #endif |
| 604 | return reinterpret_cast<T**>(Vals); |
| 605 | } |
| 606 | |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 607 | inline LLVMValueRef *wrap(const Value **Vals) { |
| 608 | return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); |
| 609 | } |
Gordon Henriksen | acd9619 | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | #endif /* !defined(__cplusplus) */ |
| 613 | |
| 614 | #endif /* !defined(LLVM_C_CORE_H) */ |