blob: eb4bc207e8ee49167d89a17ec2b7568f0a8a8e81 [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 Henriksen054817c2008-03-19 03:47:18 +0000392LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
393LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
394LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
395LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000396void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000397unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
398unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
399void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksen71183b62007-12-10 03:18:06 +0000400const char *LLVMGetCollector(LLVMValueRef Fn);
401void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000402
Gordon Henriksen265f7802008-03-19 01:11:35 +0000403/* Operations on parameters */
404unsigned LLVMCountParams(LLVMValueRef Fn);
405void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
406LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
407LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
408
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000409/* Operations on basic blocks */
410LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
411int LLVMValueIsBasicBlock(LLVMValueRef Val);
412LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000413LLVMValueRef LLVMGetBasicBlockParent(LLVMValueRef V);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000414unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
415void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000416LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
417LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
418LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
419LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000420LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
421LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
422LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
423 const char *Name);
424void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
425
Gordon Henriksen265f7802008-03-19 01:11:35 +0000426/* Operations on instructions */
427LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000428LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
429LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
430LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
431LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000432
Gordon Henriksen1158c532007-12-29 20:45:00 +0000433/* Operations on call sites */
434void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
435unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
436
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000437/* Operations on phi nodes */
438void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
439 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
440unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
441LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
442LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000443
444/*===-- Instruction builders ----------------------------------------------===*/
445
446/* An instruction builder represents a point within a basic block, and is the
447 * exclusive means of building instructions using the C interface.
448 */
449
450LLVMBuilderRef LLVMCreateBuilder();
Gordon Henriksen054817c2008-03-19 03:47:18 +0000451void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
452 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000453void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
454void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000455LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000456void LLVMDisposeBuilder(LLVMBuilderRef Builder);
457
458/* Terminators */
459LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
460LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
461LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
462LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
463 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
464LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
465 LLVMBasicBlockRef Else, unsigned NumCases);
466LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
467 LLVMValueRef *Args, unsigned NumArgs,
468 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
469 const char *Name);
470LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
471LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
472
Gordon Henriksen097102c2008-01-01 05:50:53 +0000473/* Add a case to the switch instruction */
474void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
475 LLVMBasicBlockRef Dest);
476
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000477/* Arithmetic */
478LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
479 const char *Name);
480LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
481 const char *Name);
482LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
483 const char *Name);
484LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
485 const char *Name);
486LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
487 const char *Name);
488LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
489 const char *Name);
490LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
491 const char *Name);
492LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
493 const char *Name);
494LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
495 const char *Name);
496LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
497 const char *Name);
498LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
499 const char *Name);
500LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
501 const char *Name);
502LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
503 const char *Name);
504LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
505 const char *Name);
506LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
507 const char *Name);
508LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
509LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
510
511/* Memory */
512LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
513LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
514 LLVMValueRef Val, const char *Name);
515LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
516LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
517 LLVMValueRef Val, const char *Name);
518LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
519LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
520 const char *Name);
521LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
522LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
523 LLVMValueRef *Indices, unsigned NumIndices,
524 const char *Name);
525
526/* Casts */
527LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
528 LLVMTypeRef DestTy, const char *Name);
529LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
530 LLVMTypeRef DestTy, const char *Name);
531LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
532 LLVMTypeRef DestTy, const char *Name);
533LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
534 LLVMTypeRef DestTy, const char *Name);
535LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
536 LLVMTypeRef DestTy, const char *Name);
537LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
538 LLVMTypeRef DestTy, const char *Name);
539LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
540 LLVMTypeRef DestTy, const char *Name);
541LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
542 LLVMTypeRef DestTy, const char *Name);
543LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
544 LLVMTypeRef DestTy, const char *Name);
545LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
546 LLVMTypeRef DestTy, const char *Name);
547LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
548 LLVMTypeRef DestTy, const char *Name);
549LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
550 LLVMTypeRef DestTy, const char *Name);
551
552/* Comparisons */
553LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
554 LLVMValueRef LHS, LLVMValueRef RHS,
555 const char *Name);
556LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
557 LLVMValueRef LHS, LLVMValueRef RHS,
558 const char *Name);
559
560/* Miscellaneous instructions */
561LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
562LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
563 LLVMValueRef *Args, unsigned NumArgs,
564 const char *Name);
565LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
566 LLVMValueRef Then, LLVMValueRef Else,
567 const char *Name);
568LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
569 const char *Name);
570LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
571 LLVMValueRef Index, const char *Name);
572LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
573 LLVMValueRef EltVal, LLVMValueRef Index,
574 const char *Name);
575LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
576 LLVMValueRef V2, LLVMValueRef Mask,
577 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000578
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000579
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000580/*===-- Module providers --------------------------------------------------===*/
581
582/* Encapsulates the module M in a module provider, taking ownership of the
583 * module.
584 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
585 */
586LLVMModuleProviderRef
587LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
588
589/* Destroys the module provider MP as well as the contained module.
590 * See the destructor llvm::ModuleProvider::~ModuleProvider.
591 */
592void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
593
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000594
595/*===-- Memory buffers ----------------------------------------------------===*/
596
597int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
598 LLVMMemoryBufferRef *OutMemBuf,
599 char **OutMessage);
600int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
601 char **OutMessage);
602void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
603
Gordon Henriksen878114b2008-03-16 04:20:44 +0000604
605/*===-- Pass Managers -----------------------------------------------------===*/
606
607/** Constructs a new whole-module pass pipeline. This type of pipeline is
608 suitable for link-time optimization and whole-module transformations.
609 See llvm::PassManager::PassManager. */
610LLVMPassManagerRef LLVMCreatePassManager();
611
612/** Constructs a new function-by-function pass pipeline over the module
613 provider. It does not take ownership of the module provider. This type of
614 pipeline is suitable for code generation and JIT compilation tasks.
615 See llvm::FunctionPassManager::FunctionPassManager. */
616LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
617
618/** Initializes, executes on the provided module, and finalizes all of the
619 passes scheduled in the pass manager. Returns 1 if any of the passes
620 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
621int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
622
623/** Initializes all of the function passes scheduled in the function pass
624 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
625 See llvm::FunctionPassManager::doInitialization. */
626int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
627
628/** Executes all of the function passes scheduled in the function pass manager
629 on the provided function. Returns 1 if any of the passes modified the
630 function, false otherwise.
631 See llvm::FunctionPassManager::run(Function&). */
632int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
633
634/** Finalizes all of the function passes scheduled in in the function pass
635 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
636 See llvm::FunctionPassManager::doFinalization. */
637int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
638
639/** Frees the memory of a pass pipeline. For function pipelines, does not free
640 the module provider.
641 See llvm::PassManagerBase::~PassManagerBase. */
642void LLVMDisposePassManager(LLVMPassManagerRef PM);
643
644
Gordon Henriksen76a03742007-09-18 03:18:57 +0000645#ifdef __cplusplus
646}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000647
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000648namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000649 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000650 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000651 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000652
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000653 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
654 inline ty *unwrap(ref P) { \
655 return reinterpret_cast<ty*>(P); \
656 } \
657 \
658 inline ref wrap(const ty *P) { \
659 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
660 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000661
Gordon Henriksen878114b2008-03-16 04:20:44 +0000662 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
663 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
664 \
665 template<typename T> \
666 inline T *unwrap(ref P) { \
667 return cast<T>(unwrap(P)); \
668 }
669
670 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
671 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
672 \
673 template<typename T> \
674 inline T *unwrap(ref P) { \
675 T *Q = dynamic_cast<T*>(unwrap(P)); \
676 assert(Q && "Invalid cast!"); \
677 return Q; \
678 }
679
680 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
681 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000682 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
683 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
684 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef )
685 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
686 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
687 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000688 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000689
Gordon Henriksen878114b2008-03-16 04:20:44 +0000690 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
691 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000692 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000693
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000694 /* Specialized opaque type conversions.
695 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000696 inline Type **unwrap(LLVMTypeRef* Tys) {
697 return reinterpret_cast<Type**>(Tys);
698 }
699
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000700 inline LLVMTypeRef *wrap(const Type **Tys) {
701 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
702 }
703
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000704 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000705 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000706 inline Value **unwrap(LLVMValueRef *Vals) {
707 return reinterpret_cast<Value**>(Vals);
708 }
709
710 template<typename T>
711 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
712 #if DEBUG
713 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
714 cast<T>(*I);
715 #endif
716 return reinterpret_cast<T**>(Vals);
717 }
718
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000719 inline LLVMValueRef *wrap(const Value **Vals) {
720 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
721 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000722}
723
724#endif /* !defined(__cplusplus) */
725
726#endif /* !defined(LLVM_C_CORE_H) */