Gordon Henriksen | 76a0374 | 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 | |* *| |
| 5 | |* This file was developed by Gordon Henriksen and is distributed under the *| |
| 6 | |* University of Illinois Open Source License. See LICENSE.TXT for details. *| |
| 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 | 7330acd | 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 | 76a0374 | 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 | 7330acd | 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 | 76a0374 | 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; |
| 50 | typedef struct LLVMOpaqueValue *LLVMValueRef; |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 51 | typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; |
| 52 | typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 53 | |
| 54 | typedef enum { |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 55 | LLVMVoidTypeKind, /* type with no size */ |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 56 | LLVMFloatTypeKind, /* 32 bit floating point type */ |
| 57 | LLVMDoubleTypeKind, /* 64 bit floating point type */ |
| 58 | LLVMX86_FP80TypeKind, /* 80 bit floating point type (X87) */ |
| 59 | LLVMFP128TypeKind, /* 128 bit floating point type (112-bit mantissa) */ |
| 60 | LLVMPPC_FP128TypeKind, /* 128 bit floating point type (two 64-bits) */ |
| 61 | LLVMLabelTypeKind, /* Labels */ |
| 62 | LLVMIntegerTypeKind, /* Arbitrary bit width integers */ |
| 63 | LLVMFunctionTypeKind, /* Functions */ |
| 64 | LLVMStructTypeKind, /* Structures */ |
| 65 | LLVMArrayTypeKind, /* Arrays */ |
| 66 | LLVMPointerTypeKind, /* Pointers */ |
| 67 | LLVMOpaqueTypeKind, /* Opaque: type with unknown structure */ |
| 68 | LLVMVectorTypeKind /* SIMD 'packed' format, or other vector type */ |
| 69 | } LLVMTypeKind; |
| 70 | |
| 71 | typedef enum { |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 72 | LLVMExternalLinkage, /* Externally visible function */ |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 73 | LLVMLinkOnceLinkage, /* Keep one copy of function when linking (inline) */ |
| 74 | LLVMWeakLinkage, /* Keep one copy of function when linking (weak) */ |
| 75 | LLVMAppendingLinkage, /* Special purpose, only applies to global arrays */ |
| 76 | LLVMInternalLinkage, /* Rename collisions when linking (static functions)*/ |
| 77 | LLVMDLLImportLinkage, /* Function to be imported from DLL */ |
| 78 | LLVMDLLExportLinkage, /* Function to be accessible from DLL */ |
| 79 | LLVMExternalWeakLinkage,/* ExternalWeak linkage description */ |
| 80 | LLVMGhostLinkage /* Stand-in functions for streaming fns from bitcode*/ |
| 81 | } LLVMLinkage; |
| 82 | |
| 83 | typedef enum { |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 84 | LLVMDefaultVisibility, /* The GV is visible */ |
| 85 | LLVMHiddenVisibility, /* The GV is hidden */ |
| 86 | LLVMProtectedVisibility /* The GV is protected */ |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 87 | } LLVMVisibility; |
| 88 | |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 89 | typedef enum { |
| 90 | LLVMCCallConv = 0, |
| 91 | LLVMFastCallConv = 8, |
| 92 | LLVMColdCallConv = 9, |
| 93 | LLVMX86StdcallCallConv = 64, |
| 94 | LLVMX86FastcallCallConv = 65 |
| 95 | } LLVMCallConv; |
| 96 | |
| 97 | typedef enum { |
| 98 | LLVMIntEQ = 32, /* equal */ |
| 99 | LLVMIntNE, /* not equal */ |
| 100 | LLVMIntUGT, /* unsigned greater than */ |
| 101 | LLVMIntUGE, /* unsigned greater or equal */ |
| 102 | LLVMIntULT, /* unsigned less than */ |
| 103 | LLVMIntULE, /* unsigned less or equal */ |
| 104 | LLVMIntSGT, /* signed greater than */ |
| 105 | LLVMIntSGE, /* signed greater or equal */ |
| 106 | LLVMIntSLT, /* signed less than */ |
| 107 | LLVMIntSLE /* signed less or equal */ |
| 108 | } LLVMIntPredicate; |
| 109 | |
| 110 | typedef enum { |
| 111 | LLVMRealPredicateFalse, /* Always false (always folded) */ |
| 112 | LLVMRealOEQ, /* True if ordered and equal */ |
| 113 | LLVMRealOGT, /* True if ordered and greater than */ |
| 114 | LLVMRealOGE, /* True if ordered and greater than or equal */ |
| 115 | LLVMRealOLT, /* True if ordered and less than */ |
| 116 | LLVMRealOLE, /* True if ordered and less than or equal */ |
| 117 | LLVMRealONE, /* True if ordered and operands are unequal */ |
| 118 | LLVMRealORD, /* True if ordered (no nans) */ |
| 119 | LLVMRealUNO, /* True if unordered: isnan(X) | isnan(Y) */ |
| 120 | LLVMRealUEQ, /* True if unordered or equal */ |
| 121 | LLVMRealUGT, /* True if unordered or greater than */ |
| 122 | LLVMRealUGE, /* True if unordered, greater than, or equal */ |
| 123 | LLVMRealULT, /* True if unordered or less than */ |
| 124 | LLVMRealULE, /* True if unordered, less than, or equal */ |
| 125 | LLVMRealUNE, /* True if unordered or not equal */ |
| 126 | LLVMRealPredicateTrue /* Always true (always folded) */ |
| 127 | } LLVMRealPredicate; |
| 128 | |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 129 | |
| 130 | /*===-- Modules -----------------------------------------------------------===*/ |
| 131 | |
| 132 | /* Create and destroy modules. */ |
| 133 | LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); |
| 134 | void LLVMDisposeModule(LLVMModuleRef M); |
| 135 | |
| 136 | /* Same as Module::addTypeName. */ |
| 137 | int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 138 | void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 139 | |
| 140 | |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 141 | /*===-- Types -------------------------------------------------------------===*/ |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 142 | |
| 143 | /* LLVM types conform to the following hierarchy: |
| 144 | * |
| 145 | * types: |
| 146 | * integer type |
| 147 | * real type |
| 148 | * function type |
| 149 | * sequence types: |
| 150 | * array type |
| 151 | * pointer type |
| 152 | * vector type |
| 153 | * void type |
| 154 | * label type |
| 155 | * opaque type |
| 156 | */ |
| 157 | |
| 158 | LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); |
| 159 | void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType); |
| 160 | |
| 161 | /* Operations on integer types */ |
| 162 | LLVMTypeRef LLVMInt1Type(); |
| 163 | LLVMTypeRef LLVMInt8Type(); |
| 164 | LLVMTypeRef LLVMInt16Type(); |
| 165 | LLVMTypeRef LLVMInt32Type(); |
| 166 | LLVMTypeRef LLVMInt64Type(); |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 167 | LLVMTypeRef LLVMCreateIntType(unsigned NumBits); |
| 168 | unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 169 | |
| 170 | /* Operations on real types */ |
| 171 | LLVMTypeRef LLVMFloatType(); |
| 172 | LLVMTypeRef LLVMDoubleType(); |
| 173 | LLVMTypeRef LLVMX86FP80Type(); |
| 174 | LLVMTypeRef LLVMFP128Type(); |
| 175 | LLVMTypeRef LLVMPPCFP128Type(); |
| 176 | |
| 177 | /* Operations on function types */ |
| 178 | LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType, |
| 179 | LLVMTypeRef *ParamTypes, unsigned ParamCount, |
| 180 | int IsVarArg); |
| 181 | int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 182 | LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); |
| 183 | unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); |
| 184 | void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 185 | |
| 186 | /* Operations on struct types */ |
| 187 | LLVMTypeRef LLVMCreateStructType(LLVMTypeRef *ElementTypes, |
| 188 | unsigned ElementCount, int Packed); |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 189 | unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 190 | void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); |
| 191 | int LLVMIsPackedStruct(LLVMTypeRef StructTy); |
| 192 | |
| 193 | /* Operations on array, pointer, and vector types (sequence types) */ |
| 194 | LLVMTypeRef LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount); |
| 195 | LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType); |
| 196 | LLVMTypeRef LLVMCreateVectorType(LLVMTypeRef ElementType,unsigned ElementCount); |
| 197 | |
| 198 | LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); |
| 199 | unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); |
| 200 | unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); |
| 201 | |
| 202 | /* Operations on other types */ |
| 203 | LLVMTypeRef LLVMVoidType(); |
| 204 | LLVMTypeRef LLVMLabelType(); |
| 205 | LLVMTypeRef LLVMCreateOpaqueType(); |
| 206 | |
| 207 | |
| 208 | /*===-- Values ------------------------------------------------------------===*/ |
| 209 | |
| 210 | /* The bulk of LLVM's object model consists of values, which comprise a very |
| 211 | * rich type hierarchy. |
| 212 | * |
| 213 | * values: |
| 214 | * constants: |
| 215 | * scalar constants |
| 216 | * composite contants |
| 217 | * globals: |
| 218 | * global variable |
| 219 | * function |
| 220 | * alias |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 221 | * basic blocks |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 222 | */ |
| 223 | |
| 224 | /* Operations on all values */ |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 225 | LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 226 | const char *LLVMGetValueName(LLVMValueRef Val); |
| 227 | void LLVMSetValueName(LLVMValueRef Val, const char *Name); |
Gordon Henriksen | 1d0d24c | 2007-10-06 00:08:49 +0000 | [diff] [blame] | 228 | void LLVMDumpValue(LLVMValueRef Val); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 229 | |
| 230 | /* Operations on constants of any type */ |
Gordon Henriksen | 1046c73 | 2007-10-06 15:11:06 +0000 | [diff] [blame^] | 231 | LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ |
| 232 | LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 233 | LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); |
Gordon Henriksen | dc88c06 | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 234 | int LLVMIsConstant(LLVMValueRef Val); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 235 | int LLVMIsNull(LLVMValueRef Val); |
Gordon Henriksen | dc88c06 | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 236 | int LLVMIsUndef(LLVMValueRef Val); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 237 | |
| 238 | /* Operations on scalar constants */ |
Gordon Henriksen | 1046c73 | 2007-10-06 15:11:06 +0000 | [diff] [blame^] | 239 | LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, |
| 240 | int SignExtend); |
| 241 | LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 242 | |
| 243 | /* Operations on composite constants */ |
Gordon Henriksen | 1046c73 | 2007-10-06 15:11:06 +0000 | [diff] [blame^] | 244 | LLVMValueRef LLVMConstString(const char *Str, unsigned Length, |
| 245 | int DontNullTerminate); |
| 246 | LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy, |
| 247 | LLVMValueRef *ConstantVals, unsigned Length); |
| 248 | LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, |
| 249 | int packed); |
| 250 | LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 251 | |
Gordon Henriksen | 7ce3176 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 252 | /* Constant expressions */ |
| 253 | LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); |
| 254 | LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); |
| 255 | LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); |
| 256 | LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 257 | LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 258 | LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 259 | LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 260 | LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 261 | LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 262 | LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 263 | LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 264 | LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 265 | LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 266 | LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 267 | LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 268 | LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, |
| 269 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 270 | LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, |
| 271 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 272 | LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 273 | LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 274 | LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); |
| 275 | LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, |
| 276 | LLVMValueRef *ConstantIndices, unsigned NumIndices); |
| 277 | LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 278 | LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 279 | LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 280 | LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 281 | LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 282 | LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 283 | LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 284 | LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 285 | LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 286 | LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 287 | LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 288 | LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); |
| 289 | LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, |
| 290 | LLVMValueRef ConstantIfTrue, |
| 291 | LLVMValueRef ConstantIfFalse); |
| 292 | LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, |
| 293 | LLVMValueRef IndexConstant); |
| 294 | LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, |
| 295 | LLVMValueRef ElementValueConstant, |
| 296 | LLVMValueRef IndexConstant); |
| 297 | LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, |
| 298 | LLVMValueRef VectorBConstant, |
| 299 | LLVMValueRef MaskConstant); |
| 300 | |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 301 | /* Operations on global variables, functions, and aliases (globals) */ |
| 302 | int LLVMIsDeclaration(LLVMValueRef Global); |
| 303 | LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); |
| 304 | void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); |
| 305 | const char *LLVMGetSection(LLVMValueRef Global); |
| 306 | void LLVMSetSection(LLVMValueRef Global, const char *Section); |
| 307 | LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); |
| 308 | void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); |
| 309 | unsigned LLVMGetAlignment(LLVMValueRef Global); |
| 310 | void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); |
| 311 | |
| 312 | /* Operations on global variables */ |
| 313 | LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); |
| 314 | void LLVMDeleteGlobal(LLVMValueRef GlobalVar); |
| 315 | int LLVMHasInitializer(LLVMValueRef GlobalVar); |
| 316 | LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); |
| 317 | void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); |
| 318 | int LLVMIsThreadLocal(LLVMValueRef GlobalVar); |
| 319 | void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal); |
| 320 | |
Gordon Henriksen | c23b66c | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 321 | /* Operations on functions */ |
| 322 | LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, |
| 323 | LLVMTypeRef FunctionTy); |
| 324 | void LLVMDeleteFunction(LLVMValueRef Fn); |
| 325 | unsigned LLVMCountParams(LLVMValueRef Fn); |
| 326 | void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); |
| 327 | LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); |
| 328 | unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); |
| 329 | unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); |
| 330 | void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); |
| 331 | |
| 332 | /* Operations on basic blocks */ |
| 333 | LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb); |
| 334 | int LLVMValueIsBasicBlock(LLVMValueRef Val); |
| 335 | LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); |
| 336 | unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); |
| 337 | void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); |
| 338 | LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); |
| 339 | LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); |
| 340 | LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, |
| 341 | const char *Name); |
| 342 | void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); |
| 343 | |
| 344 | |
| 345 | /*===-- Instruction builders ----------------------------------------------===*/ |
| 346 | |
| 347 | /* An instruction builder represents a point within a basic block, and is the |
| 348 | * exclusive means of building instructions using the C interface. |
| 349 | */ |
| 350 | |
| 351 | LLVMBuilderRef LLVMCreateBuilder(); |
| 352 | void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); |
| 353 | void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); |
| 354 | void LLVMDisposeBuilder(LLVMBuilderRef Builder); |
| 355 | |
| 356 | /* Terminators */ |
| 357 | LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); |
| 358 | LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); |
| 359 | LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); |
| 360 | LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, |
| 361 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); |
| 362 | LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, |
| 363 | LLVMBasicBlockRef Else, unsigned NumCases); |
| 364 | LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, |
| 365 | LLVMValueRef *Args, unsigned NumArgs, |
| 366 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, |
| 367 | const char *Name); |
| 368 | LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); |
| 369 | LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); |
| 370 | |
| 371 | /* Arithmetic */ |
| 372 | LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 373 | const char *Name); |
| 374 | LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 375 | const char *Name); |
| 376 | LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 377 | const char *Name); |
| 378 | LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 379 | const char *Name); |
| 380 | LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 381 | const char *Name); |
| 382 | LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 383 | const char *Name); |
| 384 | LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 385 | const char *Name); |
| 386 | LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 387 | const char *Name); |
| 388 | LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 389 | const char *Name); |
| 390 | LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 391 | const char *Name); |
| 392 | LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 393 | const char *Name); |
| 394 | LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 395 | const char *Name); |
| 396 | LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 397 | const char *Name); |
| 398 | LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 399 | const char *Name); |
| 400 | LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, |
| 401 | const char *Name); |
| 402 | LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); |
| 403 | LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); |
| 404 | |
| 405 | /* Memory */ |
| 406 | LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 407 | LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, |
| 408 | LLVMValueRef Val, const char *Name); |
| 409 | LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 410 | LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, |
| 411 | LLVMValueRef Val, const char *Name); |
| 412 | LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); |
| 413 | LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, |
| 414 | const char *Name); |
| 415 | LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); |
| 416 | LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 417 | LLVMValueRef *Indices, unsigned NumIndices, |
| 418 | const char *Name); |
| 419 | |
| 420 | /* Casts */ |
| 421 | LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, |
| 422 | LLVMTypeRef DestTy, const char *Name); |
| 423 | LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, |
| 424 | LLVMTypeRef DestTy, const char *Name); |
| 425 | LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, |
| 426 | LLVMTypeRef DestTy, const char *Name); |
| 427 | LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, |
| 428 | LLVMTypeRef DestTy, const char *Name); |
| 429 | LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, |
| 430 | LLVMTypeRef DestTy, const char *Name); |
| 431 | LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, |
| 432 | LLVMTypeRef DestTy, const char *Name); |
| 433 | LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, |
| 434 | LLVMTypeRef DestTy, const char *Name); |
| 435 | LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, |
| 436 | LLVMTypeRef DestTy, const char *Name); |
| 437 | LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, |
| 438 | LLVMTypeRef DestTy, const char *Name); |
| 439 | LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, |
| 440 | LLVMTypeRef DestTy, const char *Name); |
| 441 | LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, |
| 442 | LLVMTypeRef DestTy, const char *Name); |
| 443 | LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, |
| 444 | LLVMTypeRef DestTy, const char *Name); |
| 445 | |
| 446 | /* Comparisons */ |
| 447 | LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, |
| 448 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 449 | const char *Name); |
| 450 | LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, |
| 451 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 452 | const char *Name); |
| 453 | |
| 454 | /* Miscellaneous instructions */ |
| 455 | LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); |
| 456 | LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, |
| 457 | LLVMValueRef *Args, unsigned NumArgs, |
| 458 | const char *Name); |
| 459 | LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, |
| 460 | LLVMValueRef Then, LLVMValueRef Else, |
| 461 | const char *Name); |
| 462 | LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, |
| 463 | const char *Name); |
| 464 | LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, |
| 465 | LLVMValueRef Index, const char *Name); |
| 466 | LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, |
| 467 | LLVMValueRef EltVal, LLVMValueRef Index, |
| 468 | const char *Name); |
| 469 | LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, |
| 470 | LLVMValueRef V2, LLVMValueRef Mask, |
| 471 | const char *Name); |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 472 | |
| 473 | #ifdef __cplusplus |
| 474 | } |
Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 475 | |
Gordon Henriksen | 7330acd | 2007-10-05 23:59:36 +0000 | [diff] [blame] | 476 | namespace llvm { |
| 477 | /* Opaque module conversions |
| 478 | */ |
| 479 | inline Module *unwrap(LLVMModuleRef M) { |
| 480 | return reinterpret_cast<Module*>(M); |
| 481 | } |
| 482 | |
| 483 | inline LLVMModuleRef wrap(Module *M) { |
| 484 | return reinterpret_cast<LLVMModuleRef>(M); |
| 485 | } |
| 486 | |
| 487 | /* Opaque type conversions |
| 488 | */ |
| 489 | inline Type *unwrap(LLVMTypeRef Ty) { |
| 490 | return reinterpret_cast<Type*>(Ty); |
| 491 | } |
| 492 | |
| 493 | template<typename T> |
| 494 | inline T *unwrap(LLVMTypeRef Ty) { |
| 495 | return cast<T>(unwrap(Ty)); |
| 496 | } |
| 497 | |
| 498 | inline Type **unwrap(LLVMTypeRef* Tys) { |
| 499 | return reinterpret_cast<Type**>(Tys); |
| 500 | } |
| 501 | |
| 502 | inline LLVMTypeRef wrap(const Type *Ty) { |
| 503 | return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty)); |
| 504 | } |
| 505 | |
| 506 | inline LLVMTypeRef *wrap(const Type **Tys) { |
| 507 | return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); |
| 508 | } |
| 509 | |
| 510 | /* Opaque value conversions |
| 511 | */ |
| 512 | inline Value *unwrap(LLVMValueRef Val) { |
| 513 | return reinterpret_cast<Value*>(Val); |
| 514 | } |
| 515 | |
| 516 | template<typename T> |
| 517 | inline T *unwrap(LLVMValueRef Val) { |
| 518 | return cast<T>(unwrap(Val)); |
| 519 | } |
| 520 | |
| 521 | inline Value **unwrap(LLVMValueRef *Vals) { |
| 522 | return reinterpret_cast<Value**>(Vals); |
| 523 | } |
| 524 | |
| 525 | template<typename T> |
| 526 | inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { |
| 527 | #if DEBUG |
| 528 | for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I) |
| 529 | cast<T>(*I); |
| 530 | #endif |
| 531 | return reinterpret_cast<T**>(Vals); |
| 532 | } |
| 533 | |
| 534 | inline LLVMValueRef wrap(const Value *Val) { |
| 535 | return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val)); |
| 536 | } |
| 537 | |
| 538 | inline LLVMValueRef *wrap(const Value **Vals) { |
| 539 | return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); |
| 540 | } |
| 541 | |
| 542 | /* Basic block conversions |
| 543 | */ |
| 544 | inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) { |
| 545 | return reinterpret_cast<BasicBlock*>(BBRef); |
| 546 | } |
| 547 | |
| 548 | inline LLVMBasicBlockRef wrap(const BasicBlock *BB) { |
| 549 | return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB)); |
| 550 | } |
| 551 | |
| 552 | /* Opaque builder conversions. |
| 553 | */ |
| 554 | inline LLVMBuilder *unwrap(LLVMBuilderRef B) { |
| 555 | return reinterpret_cast<LLVMBuilder*>(B); |
| 556 | } |
| 557 | |
| 558 | inline LLVMBuilderRef wrap(LLVMBuilder *B) { |
| 559 | return reinterpret_cast<LLVMBuilderRef>(B); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | #endif /* !defined(__cplusplus) */ |
| 564 | |
| 565 | #endif /* !defined(LLVM_C_CORE_H) */ |