blob: 734f066f1b9b1ef1b9849560fa0fc02bdfd5c6fd [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
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 Henriksen7330acd2007-10-05 23:59:36 +000026|* 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 Henriksen76a03742007-09-18 03:18:57 +000031\*===----------------------------------------------------------------------===*/
32
33#ifndef LLVM_C_CORE_H
34#define LLVM_C_CORE_H
35
36#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000037
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 Henriksen76a03742007-09-18 03:18:57 +000043extern "C" {
44#endif
45
46
47/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000048
49/**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
52 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000053typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000054
55/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000056 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000058 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000060
61/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000062 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000066typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
Gordon Henriksen76a03742007-09-18 03:18:57 +000068typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000069typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000071
72/* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
74 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000075typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000077/* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
79 */
80typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
81
Gordon Henriksen878114b2008-03-16 04:20:44 +000082/** See the llvm::PassManagerBase class. */
83typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
84
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000086 LLVMVoidTypeKind, /**< type with no size */
87 LLVMFloatTypeKind, /**< 32 bit floating point type */
88 LLVMDoubleTypeKind, /**< 64 bit floating point type */
89 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
90 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
91 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
92 LLVMLabelTypeKind, /**< Labels */
93 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
94 LLVMFunctionTypeKind, /**< Functions */
95 LLVMStructTypeKind, /**< Structures */
96 LLVMArrayTypeKind, /**< Arrays */
97 LLVMPointerTypeKind, /**< Pointers */
98 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
99 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000100} LLVMTypeKind;
101
102typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000103 LLVMExternalLinkage, /**< Externally visible function */
104 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
105 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
106 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
107 LLVMInternalLinkage, /**< Rename collisions when linking (static
108 functions) */
109 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
110 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
111 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
112 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
113 bitcode */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114} LLVMLinkage;
115
116typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000117 LLVMDefaultVisibility, /**< The GV is visible */
118 LLVMHiddenVisibility, /**< The GV is hidden */
119 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000120} LLVMVisibility;
121
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000122typedef enum {
123 LLVMCCallConv = 0,
124 LLVMFastCallConv = 8,
125 LLVMColdCallConv = 9,
126 LLVMX86StdcallCallConv = 64,
127 LLVMX86FastcallCallConv = 65
128} LLVMCallConv;
129
130typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000131 LLVMIntEQ = 32, /**< equal */
132 LLVMIntNE, /**< not equal */
133 LLVMIntUGT, /**< unsigned greater than */
134 LLVMIntUGE, /**< unsigned greater or equal */
135 LLVMIntULT, /**< unsigned less than */
136 LLVMIntULE, /**< unsigned less or equal */
137 LLVMIntSGT, /**< signed greater than */
138 LLVMIntSGE, /**< signed greater or equal */
139 LLVMIntSLT, /**< signed less than */
140 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000141} LLVMIntPredicate;
142
143typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000144 LLVMRealPredicateFalse, /**< Always false (always folded) */
145 LLVMRealOEQ, /**< True if ordered and equal */
146 LLVMRealOGT, /**< True if ordered and greater than */
147 LLVMRealOGE, /**< True if ordered and greater than or equal */
148 LLVMRealOLT, /**< True if ordered and less than */
149 LLVMRealOLE, /**< True if ordered and less than or equal */
150 LLVMRealONE, /**< True if ordered and operands are unequal */
151 LLVMRealORD, /**< True if ordered (no nans) */
152 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
153 LLVMRealUEQ, /**< True if unordered or equal */
154 LLVMRealUGT, /**< True if unordered or greater than */
155 LLVMRealUGE, /**< True if unordered, greater than, or equal */
156 LLVMRealULT, /**< True if unordered or less than */
157 LLVMRealULE, /**< True if unordered, less than, or equal */
158 LLVMRealUNE, /**< True if unordered or not equal */
159 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000160} LLVMRealPredicate;
161
Gordon Henriksen76a03742007-09-18 03:18:57 +0000162
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000163/*===-- Error handling ----------------------------------------------------===*/
164
165void LLVMDisposeMessage(char *Message);
166
167
Gordon Henriksen76a03742007-09-18 03:18:57 +0000168/*===-- Modules -----------------------------------------------------------===*/
169
170/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000171/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000172LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000173
174/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000175void LLVMDisposeModule(LLVMModuleRef M);
176
Gordon Henriksena49d4352008-03-07 19:13:06 +0000177/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000178const char *LLVMGetDataLayout(LLVMModuleRef M);
179void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
180
Gordon Henriksena49d4352008-03-07 19:13:06 +0000181/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000182const char *LLVMGetTarget(LLVMModuleRef M);
183void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
184
Gordon Henriksena49d4352008-03-07 19:13:06 +0000185/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000186int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000187void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000188
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000189/** See Module::dump. */
190void LLVMDumpModule(LLVMModuleRef M);
191
Gordon Henriksen76a03742007-09-18 03:18:57 +0000192
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000193/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000194
195/* LLVM types conform to the following hierarchy:
196 *
197 * types:
198 * integer type
199 * real type
200 * function type
201 * sequence types:
202 * array type
203 * pointer type
204 * vector type
205 * void type
206 * label type
207 * opaque type
208 */
209
Gordon Henriksena49d4352008-03-07 19:13:06 +0000210/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000211LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000212
213/** See llvm::DerivedType::refineAbstractTypeTo. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
215
216/* Operations on integer types */
217LLVMTypeRef LLVMInt1Type();
218LLVMTypeRef LLVMInt8Type();
219LLVMTypeRef LLVMInt16Type();
220LLVMTypeRef LLVMInt32Type();
221LLVMTypeRef LLVMInt64Type();
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000222LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000223unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000224
225/* Operations on real types */
226LLVMTypeRef LLVMFloatType();
227LLVMTypeRef LLVMDoubleType();
228LLVMTypeRef LLVMX86FP80Type();
229LLVMTypeRef LLVMFP128Type();
230LLVMTypeRef LLVMPPCFP128Type();
231
232/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000233LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
234 LLVMTypeRef *ParamTypes, unsigned ParamCount,
235 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000236int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000237LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
238unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
239void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000240
241/* Operations on struct types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000242LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
243 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000244unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000245void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
246int LLVMIsPackedStruct(LLVMTypeRef StructTy);
247
248/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000249LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000250LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000251LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000252
253LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
254unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000255unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000256unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
257
258/* Operations on other types */
259LLVMTypeRef LLVMVoidType();
260LLVMTypeRef LLVMLabelType();
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000261LLVMTypeRef LLVMOpaqueType();
Gordon Henriksen76a03742007-09-18 03:18:57 +0000262
Gordon Henriksenffb48762007-10-07 00:13:35 +0000263/* Operations on type handles */
264LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
265void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
266LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
267void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
268
Gordon Henriksen76a03742007-09-18 03:18:57 +0000269
270/*===-- Values ------------------------------------------------------------===*/
271
272/* The bulk of LLVM's object model consists of values, which comprise a very
273 * rich type hierarchy.
274 *
275 * values:
276 * constants:
277 * scalar constants
278 * composite contants
279 * globals:
280 * global variable
281 * function
282 * alias
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000283 * basic blocks
Gordon Henriksen76a03742007-09-18 03:18:57 +0000284 */
285
286/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000287LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000288const char *LLVMGetValueName(LLVMValueRef Val);
289void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000290void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291
292/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000293LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
294LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000295LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000296int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000298int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000299
300/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000301LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
302 int SignExtend);
303LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000304LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000305
306/* Operations on composite constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000307LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
308 int DontNullTerminate);
309LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy,
310 LLVMValueRef *ConstantVals, unsigned Length);
311LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
312 int packed);
313LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000314
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000315/* Constant expressions */
316LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
317LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
318LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
319LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
320LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
321LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
322LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
323LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
324LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
325LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
326LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
327LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
328LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
329LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
330LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
331LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
332 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
333LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
334 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
339 LLVMValueRef *ConstantIndices, unsigned NumIndices);
340LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
341LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
342LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
343LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
344LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
345LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
346LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
347LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
348LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
349LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
350LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
351LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
352LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
353 LLVMValueRef ConstantIfTrue,
354 LLVMValueRef ConstantIfFalse);
355LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
356 LLVMValueRef IndexConstant);
357LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
358 LLVMValueRef ElementValueConstant,
359 LLVMValueRef IndexConstant);
360LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
361 LLVMValueRef VectorBConstant,
362 LLVMValueRef MaskConstant);
363
Gordon Henriksen76a03742007-09-18 03:18:57 +0000364/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000365LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000366int LLVMIsDeclaration(LLVMValueRef Global);
367LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
368void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
369const char *LLVMGetSection(LLVMValueRef Global);
370void LLVMSetSection(LLVMValueRef Global, const char *Section);
371LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
372void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
373unsigned LLVMGetAlignment(LLVMValueRef Global);
374void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
375
376/* Operations on global variables */
377LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000378LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000379void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
380int LLVMHasInitializer(LLVMValueRef GlobalVar);
381LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
382void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
383int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
384void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000385int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
386void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000387
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000388/* Operations on functions */
389LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
390 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000391LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000392void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000393unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
394unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
395void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000396const char *LLVMGetCollector(LLVMValueRef Fn);
397void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000398
Gordon Henriksen265f7802008-03-19 01:11:35 +0000399/* Operations on parameters */
400unsigned LLVMCountParams(LLVMValueRef Fn);
401void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
402LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
403LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
404
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000405/* Operations on basic blocks */
406LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
407int LLVMValueIsBasicBlock(LLVMValueRef Val);
408LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000409LLVMValueRef LLVMGetBasicBlockParent(LLVMValueRef V);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000410unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
411void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
412LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
413LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
414LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
415 const char *Name);
416void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
417
Gordon Henriksen265f7802008-03-19 01:11:35 +0000418/* Operations on instructions */
419LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
420
Gordon Henriksen1158c532007-12-29 20:45:00 +0000421/* Operations on call sites */
422void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
423unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
424
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000425/* Operations on phi nodes */
426void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
427 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
428unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
429LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
430LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000431
432/*===-- Instruction builders ----------------------------------------------===*/
433
434/* An instruction builder represents a point within a basic block, and is the
435 * exclusive means of building instructions using the C interface.
436 */
437
438LLVMBuilderRef LLVMCreateBuilder();
439void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
440void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000441LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000442void LLVMDisposeBuilder(LLVMBuilderRef Builder);
443
444/* Terminators */
445LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
446LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
447LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
448LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
449 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
450LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
451 LLVMBasicBlockRef Else, unsigned NumCases);
452LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
453 LLVMValueRef *Args, unsigned NumArgs,
454 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
455 const char *Name);
456LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
457LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
458
Gordon Henriksen097102c2008-01-01 05:50:53 +0000459/* Add a case to the switch instruction */
460void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
461 LLVMBasicBlockRef Dest);
462
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000463/* Arithmetic */
464LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
465 const char *Name);
466LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
467 const char *Name);
468LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
469 const char *Name);
470LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
471 const char *Name);
472LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
473 const char *Name);
474LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
475 const char *Name);
476LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
477 const char *Name);
478LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
479 const char *Name);
480LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
481 const char *Name);
482LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
483 const char *Name);
484LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
485 const char *Name);
486LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
487 const char *Name);
488LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
489 const char *Name);
490LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
491 const char *Name);
492LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
493 const char *Name);
494LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
495LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
496
497/* Memory */
498LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
499LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
500 LLVMValueRef Val, const char *Name);
501LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
502LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
503 LLVMValueRef Val, const char *Name);
504LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
505LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
506 const char *Name);
507LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
508LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
509 LLVMValueRef *Indices, unsigned NumIndices,
510 const char *Name);
511
512/* Casts */
513LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
514 LLVMTypeRef DestTy, const char *Name);
515LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
516 LLVMTypeRef DestTy, const char *Name);
517LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
518 LLVMTypeRef DestTy, const char *Name);
519LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
520 LLVMTypeRef DestTy, const char *Name);
521LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
522 LLVMTypeRef DestTy, const char *Name);
523LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
524 LLVMTypeRef DestTy, const char *Name);
525LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
526 LLVMTypeRef DestTy, const char *Name);
527LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
528 LLVMTypeRef DestTy, const char *Name);
529LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
530 LLVMTypeRef DestTy, const char *Name);
531LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
532 LLVMTypeRef DestTy, const char *Name);
533LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
534 LLVMTypeRef DestTy, const char *Name);
535LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
536 LLVMTypeRef DestTy, const char *Name);
537
538/* Comparisons */
539LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
540 LLVMValueRef LHS, LLVMValueRef RHS,
541 const char *Name);
542LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
543 LLVMValueRef LHS, LLVMValueRef RHS,
544 const char *Name);
545
546/* Miscellaneous instructions */
547LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
548LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
549 LLVMValueRef *Args, unsigned NumArgs,
550 const char *Name);
551LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
552 LLVMValueRef Then, LLVMValueRef Else,
553 const char *Name);
554LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
555 const char *Name);
556LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
557 LLVMValueRef Index, const char *Name);
558LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
559 LLVMValueRef EltVal, LLVMValueRef Index,
560 const char *Name);
561LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
562 LLVMValueRef V2, LLVMValueRef Mask,
563 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000564
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000565
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000566/*===-- Module providers --------------------------------------------------===*/
567
568/* Encapsulates the module M in a module provider, taking ownership of the
569 * module.
570 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
571 */
572LLVMModuleProviderRef
573LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
574
575/* Destroys the module provider MP as well as the contained module.
576 * See the destructor llvm::ModuleProvider::~ModuleProvider.
577 */
578void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
579
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000580
581/*===-- Memory buffers ----------------------------------------------------===*/
582
583int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
584 LLVMMemoryBufferRef *OutMemBuf,
585 char **OutMessage);
586int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
587 char **OutMessage);
588void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
589
Gordon Henriksen878114b2008-03-16 04:20:44 +0000590
591/*===-- Pass Managers -----------------------------------------------------===*/
592
593/** Constructs a new whole-module pass pipeline. This type of pipeline is
594 suitable for link-time optimization and whole-module transformations.
595 See llvm::PassManager::PassManager. */
596LLVMPassManagerRef LLVMCreatePassManager();
597
598/** Constructs a new function-by-function pass pipeline over the module
599 provider. It does not take ownership of the module provider. This type of
600 pipeline is suitable for code generation and JIT compilation tasks.
601 See llvm::FunctionPassManager::FunctionPassManager. */
602LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
603
604/** Initializes, executes on the provided module, and finalizes all of the
605 passes scheduled in the pass manager. Returns 1 if any of the passes
606 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
607int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
608
609/** Initializes all of the function passes scheduled in the function pass
610 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
611 See llvm::FunctionPassManager::doInitialization. */
612int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
613
614/** Executes all of the function passes scheduled in the function pass manager
615 on the provided function. Returns 1 if any of the passes modified the
616 function, false otherwise.
617 See llvm::FunctionPassManager::run(Function&). */
618int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
619
620/** Finalizes all of the function passes scheduled in in the function pass
621 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
622 See llvm::FunctionPassManager::doFinalization. */
623int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
624
625/** Frees the memory of a pass pipeline. For function pipelines, does not free
626 the module provider.
627 See llvm::PassManagerBase::~PassManagerBase. */
628void LLVMDisposePassManager(LLVMPassManagerRef PM);
629
630
Gordon Henriksen76a03742007-09-18 03:18:57 +0000631#ifdef __cplusplus
632}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000633
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000634namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000635 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000636 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000637 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000638
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000639 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
640 inline ty *unwrap(ref P) { \
641 return reinterpret_cast<ty*>(P); \
642 } \
643 \
644 inline ref wrap(const ty *P) { \
645 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
646 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000647
Gordon Henriksen878114b2008-03-16 04:20:44 +0000648 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
649 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
650 \
651 template<typename T> \
652 inline T *unwrap(ref P) { \
653 return cast<T>(unwrap(P)); \
654 }
655
656 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
657 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
658 \
659 template<typename T> \
660 inline T *unwrap(ref P) { \
661 T *Q = dynamic_cast<T*>(unwrap(P)); \
662 assert(Q && "Invalid cast!"); \
663 return Q; \
664 }
665
666 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
667 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000668 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
669 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
670 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef )
671 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
672 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
673 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000674 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000675
Gordon Henriksen878114b2008-03-16 04:20:44 +0000676 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
677 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000678 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000679
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000680 /* Specialized opaque type conversions.
681 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000682 inline Type **unwrap(LLVMTypeRef* Tys) {
683 return reinterpret_cast<Type**>(Tys);
684 }
685
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000686 inline LLVMTypeRef *wrap(const Type **Tys) {
687 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
688 }
689
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000690 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000691 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000692 inline Value **unwrap(LLVMValueRef *Vals) {
693 return reinterpret_cast<Value**>(Vals);
694 }
695
696 template<typename T>
697 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
698 #if DEBUG
699 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
700 cast<T>(*I);
701 #endif
702 return reinterpret_cast<T**>(Vals);
703 }
704
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000705 inline LLVMValueRef *wrap(const Value **Vals) {
706 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
707 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000708}
709
710#endif /* !defined(__cplusplus) */
711
712#endif /* !defined(LLVM_C_CORE_H) */