blob: 0bcab83aed9743645b9e17df95d3a574dbbfa692 [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
Erick Tryzelaardd991352009-08-16 23:36:46 +000036#include "llvm/Support/DataTypes.h"
37
Gordon Henriksen76a03742007-09-18 03:18:57 +000038#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000039
40/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41 and 'unwrap' conversion functions. */
42#include "llvm/Module.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000043#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000044
Gordon Henriksen76a03742007-09-18 03:18:57 +000045extern "C" {
46#endif
47
48
49/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000050
51/**
Owen Anderson6773d382009-07-01 16:58:40 +000052 * The top-level container for all LLVM global data. See the LLVMContext class.
53 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000054typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000055
56/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000057 * The top-level container for all other LLVM Intermediate Representation (IR)
58 * objects. See the llvm::Module class.
59 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000060typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000061
62/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000063 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
64 * class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000065 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000066typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000067
68/**
Gordon Henriksena49d4352008-03-07 19:13:06 +000069 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
70 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
71 * llvm::AbstractTypeHolder class.
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000072 */
Gordon Henriksenffb48762007-10-07 00:13:35 +000073typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000074
Gordon Henriksen76a03742007-09-18 03:18:57 +000075typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000076typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
77typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000078
79/* Used to provide a module to JIT or interpreter.
80 * See the llvm::ModuleProvider class.
81 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +000082typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000083
Gordon Henriksen34eb6d82007-12-19 22:30:40 +000084/* Used to provide a module to JIT or interpreter.
85 * See the llvm::MemoryBuffer class.
86 */
87typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
88
Gordon Henriksen878114b2008-03-16 04:20:44 +000089/** See the llvm::PassManagerBase class. */
90typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
91
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +000093 LLVMZExtAttribute = 1<<0,
94 LLVMSExtAttribute = 1<<1,
95 LLVMNoReturnAttribute = 1<<2,
96 LLVMInRegAttribute = 1<<3,
97 LLVMStructRetAttribute = 1<<4,
98 LLVMNoUnwindAttribute = 1<<5,
99 LLVMNoAliasAttribute = 1<<6,
100 LLVMByValAttribute = 1<<7,
101 LLVMNestAttribute = 1<<8,
102 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000103 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000104 LLVMNoInlineAttribute = 1<<11,
105 LLVMAlwaysInlineAttribute = 1<<12,
106 LLVMOptimizeForSizeAttribute = 1<<13,
107 LLVMStackProtectAttribute = 1<<14,
108 LLVMStackProtectReqAttribute = 1<<15,
109 LLVMNoCaptureAttribute = 1<<21,
110 LLVMNoRedZoneAttribute = 1<<22,
111 LLVMNoImplicitFloatAttribute = 1<<23,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000112 LLVMNakedAttribute = 1<<24
Devang Patel4c758ea2008-09-25 21:00:45 +0000113} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000114
115typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000116 LLVMVoidTypeKind, /**< type with no size */
117 LLVMFloatTypeKind, /**< 32 bit floating point type */
118 LLVMDoubleTypeKind, /**< 64 bit floating point type */
119 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
120 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
121 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
122 LLVMLabelTypeKind, /**< Labels */
123 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
124 LLVMFunctionTypeKind, /**< Functions */
125 LLVMStructTypeKind, /**< Structures */
126 LLVMArrayTypeKind, /**< Arrays */
127 LLVMPointerTypeKind, /**< Pointers */
128 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000129 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
130 LLVMMetadataTypeKind /**< Metadata */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000131} LLVMTypeKind;
132
133typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000134 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000135 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000136 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
137 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
138 equivalent. */
139 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
140 LLVMWeakODRLinkage, /**< Same, but only replaced by something
141 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000142 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
143 LLVMInternalLinkage, /**< Rename collisions when linking (static
144 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000145 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000146 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
147 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000148 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000149 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000150 bitcode */
Bill Wendling002b1672009-07-20 18:22:52 +0000151 LLVMCommonLinkage, /**< Tentative definitions */
152 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000153} LLVMLinkage;
154
155typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000156 LLVMDefaultVisibility, /**< The GV is visible */
157 LLVMHiddenVisibility, /**< The GV is hidden */
158 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000159} LLVMVisibility;
160
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000161typedef enum {
162 LLVMCCallConv = 0,
163 LLVMFastCallConv = 8,
164 LLVMColdCallConv = 9,
165 LLVMX86StdcallCallConv = 64,
166 LLVMX86FastcallCallConv = 65
167} LLVMCallConv;
168
169typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000170 LLVMIntEQ = 32, /**< equal */
171 LLVMIntNE, /**< not equal */
172 LLVMIntUGT, /**< unsigned greater than */
173 LLVMIntUGE, /**< unsigned greater or equal */
174 LLVMIntULT, /**< unsigned less than */
175 LLVMIntULE, /**< unsigned less or equal */
176 LLVMIntSGT, /**< signed greater than */
177 LLVMIntSGE, /**< signed greater or equal */
178 LLVMIntSLT, /**< signed less than */
179 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000180} LLVMIntPredicate;
181
182typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000183 LLVMRealPredicateFalse, /**< Always false (always folded) */
184 LLVMRealOEQ, /**< True if ordered and equal */
185 LLVMRealOGT, /**< True if ordered and greater than */
186 LLVMRealOGE, /**< True if ordered and greater than or equal */
187 LLVMRealOLT, /**< True if ordered and less than */
188 LLVMRealOLE, /**< True if ordered and less than or equal */
189 LLVMRealONE, /**< True if ordered and operands are unequal */
190 LLVMRealORD, /**< True if ordered (no nans) */
191 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
192 LLVMRealUEQ, /**< True if unordered or equal */
193 LLVMRealUGT, /**< True if unordered or greater than */
194 LLVMRealUGE, /**< True if unordered, greater than, or equal */
195 LLVMRealULT, /**< True if unordered or less than */
196 LLVMRealULE, /**< True if unordered, less than, or equal */
197 LLVMRealUNE, /**< True if unordered or not equal */
198 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000199} LLVMRealPredicate;
200
Gordon Henriksen76a03742007-09-18 03:18:57 +0000201
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000202/*===-- Error handling ----------------------------------------------------===*/
203
204void LLVMDisposeMessage(char *Message);
205
206
Gordon Henriksen76a03742007-09-18 03:18:57 +0000207/*===-- Modules -----------------------------------------------------------===*/
208
Owen Anderson6773d382009-07-01 16:58:40 +0000209/* Create and destroy contexts. */
210LLVMContextRef LLVMContextCreate();
Owen Andersonf7691d32009-07-02 00:16:38 +0000211LLVMContextRef LLVMGetGlobalContext();
Owen Anderson6773d382009-07-01 16:58:40 +0000212void LLVMContextDispose(LLVMContextRef C);
213
Gordon Henriksen76a03742007-09-18 03:18:57 +0000214/* Create and destroy modules. */
Gordon Henriksena49d4352008-03-07 19:13:06 +0000215/** See llvm::Module::Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000216LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Owen Anderson31d44e42009-07-02 07:17:57 +0000217LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
218 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000219
220/** See llvm::Module::~Module. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000221void LLVMDisposeModule(LLVMModuleRef M);
222
Gordon Henriksena49d4352008-03-07 19:13:06 +0000223/** Data layout. See Module::getDataLayout. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000224const char *LLVMGetDataLayout(LLVMModuleRef M);
225void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
226
Gordon Henriksena49d4352008-03-07 19:13:06 +0000227/** Target triple. See Module::getTargetTriple. */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000228const char *LLVMGetTarget(LLVMModuleRef M);
229void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
230
Gordon Henriksena49d4352008-03-07 19:13:06 +0000231/** See Module::addTypeName. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000232int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000233void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Chris Lattner7f318242009-07-06 17:29:59 +0000234LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000236/** See Module::dump. */
237void LLVMDumpModule(LLVMModuleRef M);
238
Gordon Henriksen76a03742007-09-18 03:18:57 +0000239
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000240/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000241
242/* LLVM types conform to the following hierarchy:
243 *
244 * types:
245 * integer type
246 * real type
247 * function type
248 * sequence types:
249 * array type
250 * pointer type
251 * vector type
252 * void type
253 * label type
254 * opaque type
255 */
256
Gordon Henriksena49d4352008-03-07 19:13:06 +0000257/** See llvm::LLVMTypeKind::getTypeID. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000258LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000259
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000260/** See llvm::LLVMType::getContext. */
261LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
262
Gordon Henriksen76a03742007-09-18 03:18:57 +0000263/* Operations on integer types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000264LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
265LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
266LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
267LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
268LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
269LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
270
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000271LLVMTypeRef LLVMInt1Type(void);
272LLVMTypeRef LLVMInt8Type(void);
273LLVMTypeRef LLVMInt16Type(void);
274LLVMTypeRef LLVMInt32Type(void);
275LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000276LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000277unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000278
279/* Operations on real types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000280LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
281LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
282LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
283LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
284LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
285
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000286LLVMTypeRef LLVMFloatType(void);
287LLVMTypeRef LLVMDoubleType(void);
288LLVMTypeRef LLVMX86FP80Type(void);
289LLVMTypeRef LLVMFP128Type(void);
290LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291
292/* Operations on function types */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000293LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
294 LLVMTypeRef *ParamTypes, unsigned ParamCount,
295 int IsVarArg);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000296int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000297LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
298unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
299void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000300
301/* Operations on struct types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000302LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
303 unsigned ElementCount, int Packed);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000304LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
305 int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000306unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000307void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
308int LLVMIsPackedStruct(LLVMTypeRef StructTy);
309
310/* Operations on array, pointer, and vector types (sequence types) */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000311LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000312LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000313LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000314
315LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
316unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000317unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000318unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
319
320/* Operations on other types */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000321LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
322LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
323LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
324
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000325LLVMTypeRef LLVMVoidType(void);
326LLVMTypeRef LLVMLabelType(void);
327LLVMTypeRef LLVMOpaqueType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000328
Gordon Henriksenffb48762007-10-07 00:13:35 +0000329/* Operations on type handles */
330LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
331void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
332LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
333void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
334
Gordon Henriksen76a03742007-09-18 03:18:57 +0000335
336/*===-- Values ------------------------------------------------------------===*/
337
338/* The bulk of LLVM's object model consists of values, which comprise a very
339 * rich type hierarchy.
Gordon Henriksen76a03742007-09-18 03:18:57 +0000340 */
341
Gordon Henriksen29e38942008-12-19 18:39:45 +0000342#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
343 macro(Argument) \
344 macro(BasicBlock) \
345 macro(InlineAsm) \
346 macro(User) \
347 macro(Constant) \
348 macro(ConstantAggregateZero) \
349 macro(ConstantArray) \
350 macro(ConstantExpr) \
351 macro(ConstantFP) \
352 macro(ConstantInt) \
353 macro(ConstantPointerNull) \
354 macro(ConstantStruct) \
355 macro(ConstantVector) \
356 macro(GlobalValue) \
357 macro(Function) \
358 macro(GlobalAlias) \
359 macro(GlobalVariable) \
360 macro(UndefValue) \
361 macro(Instruction) \
362 macro(BinaryOperator) \
363 macro(CallInst) \
364 macro(IntrinsicInst) \
365 macro(DbgInfoIntrinsic) \
366 macro(DbgDeclareInst) \
367 macro(DbgFuncStartInst) \
368 macro(DbgRegionEndInst) \
369 macro(DbgRegionStartInst) \
370 macro(DbgStopPointInst) \
371 macro(EHSelectorInst) \
372 macro(MemIntrinsic) \
373 macro(MemCpyInst) \
374 macro(MemMoveInst) \
375 macro(MemSetInst) \
376 macro(CmpInst) \
377 macro(FCmpInst) \
378 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000379 macro(ExtractElementInst) \
380 macro(GetElementPtrInst) \
381 macro(InsertElementInst) \
382 macro(InsertValueInst) \
383 macro(PHINode) \
384 macro(SelectInst) \
385 macro(ShuffleVectorInst) \
386 macro(StoreInst) \
387 macro(TerminatorInst) \
388 macro(BranchInst) \
389 macro(InvokeInst) \
390 macro(ReturnInst) \
391 macro(SwitchInst) \
392 macro(UnreachableInst) \
393 macro(UnwindInst) \
394 macro(UnaryInstruction) \
395 macro(AllocationInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000396 macro(AllocaInst) \
397 macro(MallocInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000398 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +0000399 macro(BitCastInst) \
400 macro(FPExtInst) \
401 macro(FPToSIInst) \
402 macro(FPToUIInst) \
403 macro(FPTruncInst) \
404 macro(IntToPtrInst) \
405 macro(PtrToIntInst) \
406 macro(SExtInst) \
407 macro(SIToFPInst) \
408 macro(TruncInst) \
409 macro(UIToFPInst) \
410 macro(ZExtInst) \
411 macro(ExtractValueInst) \
412 macro(FreeInst) \
413 macro(LoadInst) \
414 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +0000415
Gordon Henriksen76a03742007-09-18 03:18:57 +0000416/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000417LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000418const char *LLVMGetValueName(LLVMValueRef Val);
419void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000420void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000421
Gordon Henriksen29e38942008-12-19 18:39:45 +0000422/* Conversion functions. Return the input value if it is an instance of the
423 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
424#define LLVM_DECLARE_VALUE_CAST(name) \
425 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
426LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
427
Gordon Henriksen76a03742007-09-18 03:18:57 +0000428/* Operations on constants of any type */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000429LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
430LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000431LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000432int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000433int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000434int LLVMIsUndef(LLVMValueRef Val);
Chris Lattner7f318242009-07-06 17:29:59 +0000435LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000436
437/* Operations on scalar constants */
Gordon Henriksen1046c732007-10-06 15:11:06 +0000438LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
439 int SignExtend);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000440LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
441 uint8_t Radix);
442LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
443 unsigned SLen, uint8_t Radix);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000444LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gordon Henriksen931e1212008-02-02 01:07:50 +0000445LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Erick Tryzelaardd991352009-08-16 23:36:46 +0000446LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
447 unsigned SLen);
448
Gordon Henriksen76a03742007-09-18 03:18:57 +0000449
450/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000451LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
452 unsigned Length, int DontNullTerminate);
453LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
454 LLVMValueRef *ConstantVals,
455 unsigned Count, int Packed);
456
Gordon Henriksen1046c732007-10-06 15:11:06 +0000457LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
458 int DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +0000459LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +0000460 LLVMValueRef *ConstantVals, unsigned Length);
461LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000462 int Packed);
Gordon Henriksen1046c732007-10-06 15:11:06 +0000463LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000464
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000465/* Constant expressions */
466LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
467LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000468LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000469LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
470LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000471LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
472LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000473LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000474LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000475LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000476LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000477LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
478LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000479LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000480LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
481LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
482LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
483LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
484LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
485LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
486LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
487LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
488 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
489LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
490 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
491LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
492LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
493LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
494LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
495 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000496LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
497 LLVMValueRef *ConstantIndices,
498 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000499LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
500LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
501LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
502LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
503LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
504LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
505LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
506LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
507LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
508LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
509LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
510LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +0000511LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
512 LLVMTypeRef ToType);
513LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
514 LLVMTypeRef ToType);
515LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
516 LLVMTypeRef ToType);
517LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
518 LLVMTypeRef ToType);
519LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
520 unsigned isSigned);
521LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000522LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
523 LLVMValueRef ConstantIfTrue,
524 LLVMValueRef ConstantIfFalse);
525LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
526 LLVMValueRef IndexConstant);
527LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
528 LLVMValueRef ElementValueConstant,
529 LLVMValueRef IndexConstant);
530LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
531 LLVMValueRef VectorBConstant,
532 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +0000533LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
534 unsigned NumIdx);
535LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
536 LLVMValueRef ElementValueConstant,
537 unsigned *IdxList, unsigned NumIdx);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000538LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
539 const char *AsmString, const char *Constraints,
540 int HasSideEffects);
Gordon Henriksen7ce31762007-10-06 14:29:36 +0000541
Gordon Henriksen76a03742007-09-18 03:18:57 +0000542/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +0000543LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000544int LLVMIsDeclaration(LLVMValueRef Global);
545LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
546void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
547const char *LLVMGetSection(LLVMValueRef Global);
548void LLVMSetSection(LLVMValueRef Global, const char *Section);
549LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
550void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
551unsigned LLVMGetAlignment(LLVMValueRef Global);
552void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
553
554/* Operations on global variables */
555LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000556LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000557LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
558LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
559LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
560LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000561void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000562LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
563void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
564int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
565void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
Gordon Henriksen751ebf72007-10-07 17:31:42 +0000566int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
567void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000568
Chris Lattner3d1f5522008-12-17 21:39:50 +0000569/* Operations on aliases */
570LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
571 const char *Name);
572
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000573/* Operations on functions */
574LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
575 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +0000576LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000577LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
578LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
579LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
580LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000581void LLVMDeleteFunction(LLVMValueRef Fn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000582unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
583unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
584void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gordon Henriksend930f912008-08-17 18:44:35 +0000585const char *LLVMGetGC(LLVMValueRef Fn);
586void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Duncan Sands7374a012009-05-06 12:21:17 +0000587void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
588void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000589
Gordon Henriksen265f7802008-03-19 01:11:35 +0000590/* Operations on parameters */
591unsigned LLVMCountParams(LLVMValueRef Fn);
592void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
593LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
594LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000595LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
596LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
597LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
598LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Devang Patel4c758ea2008-09-25 21:00:45 +0000599void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
600void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000601void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000602
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000603/* Operations on basic blocks */
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000604LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000605int LLVMValueIsBasicBlock(LLVMValueRef Val);
606LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gordon Henriksen07a45f42008-03-23 22:21:29 +0000607LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000608unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
609void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000610LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
611LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
612LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
613LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000614LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000615
616LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
617 LLVMValueRef Fn,
618 const char *Name);
619LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
620 LLVMBasicBlockRef BB,
621 const char *Name);
622
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000623LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
624LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
625 const char *Name);
626void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
627
Gordon Henriksen265f7802008-03-19 01:11:35 +0000628/* Operations on instructions */
629LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000630LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
631LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
632LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
633LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000634
Gordon Henriksen1158c532007-12-29 20:45:00 +0000635/* Operations on call sites */
636void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
637unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Devang Patel4c758ea2008-09-25 21:00:45 +0000638void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
639void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
640 LLVMAttribute);
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000641void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
642 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +0000643
Gordon Henrikseneeb65372008-08-30 16:34:54 +0000644/* Operations on call instructions (only) */
645int LLVMIsTailCall(LLVMValueRef CallInst);
646void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
647
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +0000648/* Operations on phi nodes */
649void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
650 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
651unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
652LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
653LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000654
655/*===-- Instruction builders ----------------------------------------------===*/
656
657/* An instruction builder represents a point within a basic block, and is the
658 * exclusive means of building instructions using the C interface.
659 */
660
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000661LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000662LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +0000663void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
664 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000665void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
666void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +0000667LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +0000668void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
669void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +0000670void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
671 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000672void LLVMDisposeBuilder(LLVMBuilderRef Builder);
673
674/* Terminators */
675LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
676LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000677LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef RetVals,
678 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000679LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
680LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
681 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
682LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
683 LLVMBasicBlockRef Else, unsigned NumCases);
684LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
685 LLVMValueRef *Args, unsigned NumArgs,
686 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
687 const char *Name);
688LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
689LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
690
Gordon Henriksen097102c2008-01-01 05:50:53 +0000691/* Add a case to the switch instruction */
692void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
693 LLVMBasicBlockRef Dest);
694
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000695/* Arithmetic */
696LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
697 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000698LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
699 const char *Name);
700LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
701 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000702LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
703 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000704LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
705 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000706LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
707 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000708LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
709 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000710LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
711 const char *Name);
712LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
713 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000714LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
715 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000716LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
717 const char *Name);
718LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
719 const char *Name);
720LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
721 const char *Name);
722LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
723 const char *Name);
724LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
725 const char *Name);
726LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
727 const char *Name);
728LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
729 const char *Name);
730LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
731 const char *Name);
732LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
733 const char *Name);
734LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
735 const char *Name);
736LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
737LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
738
739/* Memory */
740LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
741LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
742 LLVMValueRef Val, const char *Name);
743LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
744LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
745 LLVMValueRef Val, const char *Name);
746LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
747LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
748 const char *Name);
749LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
750LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
751 LLVMValueRef *Indices, unsigned NumIndices,
752 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000753LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
754 LLVMValueRef *Indices, unsigned NumIndices,
755 const char *Name);
756LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
757 unsigned Idx, const char *Name);
758LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
759 const char *Name);
760LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
761 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000762
763/* Casts */
764LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
765 LLVMTypeRef DestTy, const char *Name);
766LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
767 LLVMTypeRef DestTy, const char *Name);
768LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
769 LLVMTypeRef DestTy, const char *Name);
770LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
771 LLVMTypeRef DestTy, const char *Name);
772LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
773 LLVMTypeRef DestTy, const char *Name);
774LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
775 LLVMTypeRef DestTy, const char *Name);
776LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
777 LLVMTypeRef DestTy, const char *Name);
778LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
779 LLVMTypeRef DestTy, const char *Name);
780LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
781 LLVMTypeRef DestTy, const char *Name);
782LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
783 LLVMTypeRef DestTy, const char *Name);
784LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
785 LLVMTypeRef DestTy, const char *Name);
786LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
787 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000788LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
789 LLVMTypeRef DestTy, const char *Name);
790LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
791 LLVMTypeRef DestTy, const char *Name);
792LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
793 LLVMTypeRef DestTy, const char *Name);
794LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
795 LLVMTypeRef DestTy, const char *Name);
796LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
797 LLVMTypeRef DestTy, const char *Name);
798LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
799 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000800
801/* Comparisons */
802LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
803 LLVMValueRef LHS, LLVMValueRef RHS,
804 const char *Name);
805LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
806 LLVMValueRef LHS, LLVMValueRef RHS,
807 const char *Name);
808
809/* Miscellaneous instructions */
810LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
811LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
812 LLVMValueRef *Args, unsigned NumArgs,
813 const char *Name);
814LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
815 LLVMValueRef Then, LLVMValueRef Else,
816 const char *Name);
817LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
818 const char *Name);
819LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
820 LLVMValueRef Index, const char *Name);
821LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
822 LLVMValueRef EltVal, LLVMValueRef Index,
823 const char *Name);
824LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
825 LLVMValueRef V2, LLVMValueRef Mask,
826 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +0000827LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
828 unsigned Index, const char *Name);
829LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
830 LLVMValueRef EltVal, unsigned Index,
831 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000832
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +0000833LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
834 const char *Name);
835LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
836 const char *Name);
837LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
838 LLVMValueRef RHS, const char *Name);
839
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000840
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000841/*===-- Module providers --------------------------------------------------===*/
842
843/* Encapsulates the module M in a module provider, taking ownership of the
844 * module.
845 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
846 */
847LLVMModuleProviderRef
848LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
849
850/* Destroys the module provider MP as well as the contained module.
851 * See the destructor llvm::ModuleProvider::~ModuleProvider.
852 */
853void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
854
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000855
856/*===-- Memory buffers ----------------------------------------------------===*/
857
858int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
859 LLVMMemoryBufferRef *OutMemBuf,
860 char **OutMessage);
861int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
862 char **OutMessage);
863void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
864
Gordon Henriksen878114b2008-03-16 04:20:44 +0000865
866/*===-- Pass Managers -----------------------------------------------------===*/
867
868/** Constructs a new whole-module pass pipeline. This type of pipeline is
869 suitable for link-time optimization and whole-module transformations.
870 See llvm::PassManager::PassManager. */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000871LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +0000872
873/** Constructs a new function-by-function pass pipeline over the module
874 provider. It does not take ownership of the module provider. This type of
875 pipeline is suitable for code generation and JIT compilation tasks.
876 See llvm::FunctionPassManager::FunctionPassManager. */
877LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
878
879/** Initializes, executes on the provided module, and finalizes all of the
880 passes scheduled in the pass manager. Returns 1 if any of the passes
881 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
882int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
883
884/** Initializes all of the function passes scheduled in the function pass
885 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
886 See llvm::FunctionPassManager::doInitialization. */
887int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
888
889/** Executes all of the function passes scheduled in the function pass manager
890 on the provided function. Returns 1 if any of the passes modified the
891 function, false otherwise.
892 See llvm::FunctionPassManager::run(Function&). */
893int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
894
895/** Finalizes all of the function passes scheduled in in the function pass
896 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
897 See llvm::FunctionPassManager::doFinalization. */
898int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
899
900/** Frees the memory of a pass pipeline. For function pipelines, does not free
901 the module provider.
902 See llvm::PassManagerBase::~PassManagerBase. */
903void LLVMDisposePassManager(LLVMPassManagerRef PM);
904
905
Gordon Henriksen76a03742007-09-18 03:18:57 +0000906#ifdef __cplusplus
907}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000908
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000909namespace llvm {
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000910 class ModuleProvider;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000911 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +0000912 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000913
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000914 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
915 inline ty *unwrap(ref P) { \
916 return reinterpret_cast<ty*>(P); \
917 } \
918 \
919 inline ref wrap(const ty *P) { \
920 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
921 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000922
Gordon Henriksen878114b2008-03-16 04:20:44 +0000923 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
924 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
925 \
926 template<typename T> \
927 inline T *unwrap(ref P) { \
928 return cast<T>(unwrap(P)); \
929 }
930
931 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
932 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
933 \
934 template<typename T> \
935 inline T *unwrap(ref P) { \
936 T *Q = dynamic_cast<T*>(unwrap(P)); \
937 assert(Q && "Invalid cast!"); \
938 return Q; \
939 }
940
941 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
942 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000943 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
944 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +0000945 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +0000946 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
947 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
948 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +0000949 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +0000950 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000951
Gordon Henriksen878114b2008-03-16 04:20:44 +0000952 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
953 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000954 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000955
956 /* Specialized opaque context conversions.
957 */
958 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
959 return reinterpret_cast<LLVMContext**>(Tys);
960 }
961
962 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
963 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
964 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000965
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000966 /* Specialized opaque type conversions.
967 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000968 inline Type **unwrap(LLVMTypeRef* Tys) {
969 return reinterpret_cast<Type**>(Tys);
970 }
971
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000972 inline LLVMTypeRef *wrap(const Type **Tys) {
973 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
974 }
975
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000976 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000977 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000978 inline Value **unwrap(LLVMValueRef *Vals) {
979 return reinterpret_cast<Value**>(Vals);
980 }
981
982 template<typename T>
983 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
984 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +0000985 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000986 cast<T>(*I);
987 #endif
988 return reinterpret_cast<T**>(Vals);
989 }
990
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000991 inline LLVMValueRef *wrap(const Value **Vals) {
992 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
993 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000994}
995
996#endif /* !defined(__cplusplus) */
997
998#endif /* !defined(LLVM_C_CORE_H) */