blob: a9ed27b420142f480f23504e5cad7aecdd9e1a3d [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|* *|
5|* This file was developed by Gordon Henriksen and is distributed under the *|
6|* University of Illinois Open Source License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
13|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14|* parameters must be passed as base types. Despite the declared types, most *|
15|* of the functions provided operate only on branches of the type hierarchy. *|
16|* The declared parameter names are descriptive and specify which type is *|
17|* required. Additionally, each type hierarchy is documented along with the *|
18|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20|* form unwrap<RequiredType>(Param). *|
21|* *|
22|* Many exotic languages can interoperate with C code but have a harder time *|
23|* with C++ due to name mangling. So in addition to C, this interface enables *|
24|* tools written in such languages. *|
25|* *|
Gordon 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. */
48typedef struct LLVMOpaqueModule *LLVMModuleRef;
49typedef struct LLVMOpaqueType *LLVMTypeRef;
50typedef struct LLVMOpaqueValue *LLVMValueRef;
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000051typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
52typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +000053
54typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000055 LLVMVoidTypeKind, /* type with no size */
Gordon Henriksen76a03742007-09-18 03:18:57 +000056 LLVMFloatTypeKind, /* 32 bit floating point type */
57 LLVMDoubleTypeKind, /* 64 bit floating point type */
58 LLVMX86_FP80TypeKind, /* 80 bit floating point type (X87) */
59 LLVMFP128TypeKind, /* 128 bit floating point type (112-bit mantissa) */
60 LLVMPPC_FP128TypeKind, /* 128 bit floating point type (two 64-bits) */
61 LLVMLabelTypeKind, /* Labels */
62 LLVMIntegerTypeKind, /* Arbitrary bit width integers */
63 LLVMFunctionTypeKind, /* Functions */
64 LLVMStructTypeKind, /* Structures */
65 LLVMArrayTypeKind, /* Arrays */
66 LLVMPointerTypeKind, /* Pointers */
67 LLVMOpaqueTypeKind, /* Opaque: type with unknown structure */
68 LLVMVectorTypeKind /* SIMD 'packed' format, or other vector type */
69} LLVMTypeKind;
70
71typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000072 LLVMExternalLinkage, /* Externally visible function */
Gordon Henriksen76a03742007-09-18 03:18:57 +000073 LLVMLinkOnceLinkage, /* Keep one copy of function when linking (inline) */
74 LLVMWeakLinkage, /* Keep one copy of function when linking (weak) */
75 LLVMAppendingLinkage, /* Special purpose, only applies to global arrays */
76 LLVMInternalLinkage, /* Rename collisions when linking (static functions)*/
77 LLVMDLLImportLinkage, /* Function to be imported from DLL */
78 LLVMDLLExportLinkage, /* Function to be accessible from DLL */
79 LLVMExternalWeakLinkage,/* ExternalWeak linkage description */
80 LLVMGhostLinkage /* Stand-in functions for streaming fns from bitcode*/
81} LLVMLinkage;
82
83typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000084 LLVMDefaultVisibility, /* The GV is visible */
85 LLVMHiddenVisibility, /* The GV is hidden */
86 LLVMProtectedVisibility /* The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +000087} LLVMVisibility;
88
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000089typedef enum {
90 LLVMCCallConv = 0,
91 LLVMFastCallConv = 8,
92 LLVMColdCallConv = 9,
93 LLVMX86StdcallCallConv = 64,
94 LLVMX86FastcallCallConv = 65
95} LLVMCallConv;
96
97typedef enum {
98 LLVMIntEQ = 32, /* equal */
99 LLVMIntNE, /* not equal */
100 LLVMIntUGT, /* unsigned greater than */
101 LLVMIntUGE, /* unsigned greater or equal */
102 LLVMIntULT, /* unsigned less than */
103 LLVMIntULE, /* unsigned less or equal */
104 LLVMIntSGT, /* signed greater than */
105 LLVMIntSGE, /* signed greater or equal */
106 LLVMIntSLT, /* signed less than */
107 LLVMIntSLE /* signed less or equal */
108} LLVMIntPredicate;
109
110typedef enum {
111 LLVMRealPredicateFalse, /* Always false (always folded) */
112 LLVMRealOEQ, /* True if ordered and equal */
113 LLVMRealOGT, /* True if ordered and greater than */
114 LLVMRealOGE, /* True if ordered and greater than or equal */
115 LLVMRealOLT, /* True if ordered and less than */
116 LLVMRealOLE, /* True if ordered and less than or equal */
117 LLVMRealONE, /* True if ordered and operands are unequal */
118 LLVMRealORD, /* True if ordered (no nans) */
119 LLVMRealUNO, /* True if unordered: isnan(X) | isnan(Y) */
120 LLVMRealUEQ, /* True if unordered or equal */
121 LLVMRealUGT, /* True if unordered or greater than */
122 LLVMRealUGE, /* True if unordered, greater than, or equal */
123 LLVMRealULT, /* True if unordered or less than */
124 LLVMRealULE, /* True if unordered, less than, or equal */
125 LLVMRealUNE, /* True if unordered or not equal */
126 LLVMRealPredicateTrue /* Always true (always folded) */
127} LLVMRealPredicate;
128
Gordon Henriksen76a03742007-09-18 03:18:57 +0000129
130/*===-- Modules -----------------------------------------------------------===*/
131
132/* Create and destroy modules. */
133LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
134void LLVMDisposeModule(LLVMModuleRef M);
135
136/* Same as Module::addTypeName. */
137int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000138void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000139
140
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000141/*===-- Types -------------------------------------------------------------===*/
Gordon Henriksen76a03742007-09-18 03:18:57 +0000142
143/* LLVM types conform to the following hierarchy:
144 *
145 * types:
146 * integer type
147 * real type
148 * function type
149 * sequence types:
150 * array type
151 * pointer type
152 * vector type
153 * void type
154 * label type
155 * opaque type
156 */
157
158LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
159void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
160
161/* Operations on integer types */
162LLVMTypeRef LLVMInt1Type();
163LLVMTypeRef LLVMInt8Type();
164LLVMTypeRef LLVMInt16Type();
165LLVMTypeRef LLVMInt32Type();
166LLVMTypeRef LLVMInt64Type();
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000167LLVMTypeRef LLVMCreateIntType(unsigned NumBits);
168unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000169
170/* Operations on real types */
171LLVMTypeRef LLVMFloatType();
172LLVMTypeRef LLVMDoubleType();
173LLVMTypeRef LLVMX86FP80Type();
174LLVMTypeRef LLVMFP128Type();
175LLVMTypeRef LLVMPPCFP128Type();
176
177/* Operations on function types */
178LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType,
179 LLVMTypeRef *ParamTypes, unsigned ParamCount,
180 int IsVarArg);
181int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000182LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
183unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
184void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000185
186/* Operations on struct types */
187LLVMTypeRef LLVMCreateStructType(LLVMTypeRef *ElementTypes,
188 unsigned ElementCount, int Packed);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000189unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000190void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
191int LLVMIsPackedStruct(LLVMTypeRef StructTy);
192
193/* Operations on array, pointer, and vector types (sequence types) */
194LLVMTypeRef LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
195LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType);
196LLVMTypeRef LLVMCreateVectorType(LLVMTypeRef ElementType,unsigned ElementCount);
197
198LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
199unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
200unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
201
202/* Operations on other types */
203LLVMTypeRef LLVMVoidType();
204LLVMTypeRef LLVMLabelType();
205LLVMTypeRef LLVMCreateOpaqueType();
206
207
208/*===-- Values ------------------------------------------------------------===*/
209
210/* The bulk of LLVM's object model consists of values, which comprise a very
211 * rich type hierarchy.
212 *
213 * values:
214 * constants:
215 * scalar constants
216 * composite contants
217 * globals:
218 * global variable
219 * function
220 * alias
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000221 * basic blocks
Gordon Henriksen76a03742007-09-18 03:18:57 +0000222 */
223
224/* Operations on all values */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000225LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000226const char *LLVMGetValueName(LLVMValueRef Val);
227void LLVMSetValueName(LLVMValueRef Val, const char *Name);
Gordon Henriksen1d0d24c2007-10-06 00:08:49 +0000228void LLVMDumpValue(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000229
230/* Operations on constants of any type */
231LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
232LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
233LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000234int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000235int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000236int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000237
238/* Operations on scalar constants */
239LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
240 int SignExtend);
241LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N);
242
243/* Operations on composite constants */
244LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
245 int DontNullTerminate);
246LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ArrayTy,
247 LLVMValueRef *ConstantVals, unsigned Length);
248LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
249 int packed);
250LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
251 unsigned Size);
252
253/* Operations on global variables, functions, and aliases (globals) */
254int LLVMIsDeclaration(LLVMValueRef Global);
255LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
256void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
257const char *LLVMGetSection(LLVMValueRef Global);
258void LLVMSetSection(LLVMValueRef Global, const char *Section);
259LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
260void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
261unsigned LLVMGetAlignment(LLVMValueRef Global);
262void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
263
264/* Operations on global variables */
265LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
266void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
267int LLVMHasInitializer(LLVMValueRef GlobalVar);
268LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
269void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
270int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
271void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
272
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000273/* Operations on functions */
274LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
275 LLVMTypeRef FunctionTy);
276void LLVMDeleteFunction(LLVMValueRef Fn);
277unsigned LLVMCountParams(LLVMValueRef Fn);
278void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
279LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
280unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
281unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
282void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
283
284/* Operations on basic blocks */
285LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
286int LLVMValueIsBasicBlock(LLVMValueRef Val);
287LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
288unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
289void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
290LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
291LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
292LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
293 const char *Name);
294void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
295
296
297/*===-- Instruction builders ----------------------------------------------===*/
298
299/* An instruction builder represents a point within a basic block, and is the
300 * exclusive means of building instructions using the C interface.
301 */
302
303LLVMBuilderRef LLVMCreateBuilder();
304void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
305void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
306void LLVMDisposeBuilder(LLVMBuilderRef Builder);
307
308/* Terminators */
309LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
310LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
311LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
312LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
313 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
314LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
315 LLVMBasicBlockRef Else, unsigned NumCases);
316LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
317 LLVMValueRef *Args, unsigned NumArgs,
318 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
319 const char *Name);
320LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
321LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
322
323/* Arithmetic */
324LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
325 const char *Name);
326LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
327 const char *Name);
328LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
329 const char *Name);
330LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
331 const char *Name);
332LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
333 const char *Name);
334LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
335 const char *Name);
336LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
337 const char *Name);
338LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
339 const char *Name);
340LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
341 const char *Name);
342LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
343 const char *Name);
344LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
345 const char *Name);
346LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
347 const char *Name);
348LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
349 const char *Name);
350LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
351 const char *Name);
352LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
353 const char *Name);
354LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
355LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
356
357/* Memory */
358LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
359LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
360 LLVMValueRef Val, const char *Name);
361LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
362LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
363 LLVMValueRef Val, const char *Name);
364LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
365LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
366 const char *Name);
367LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
368LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
369 LLVMValueRef *Indices, unsigned NumIndices,
370 const char *Name);
371
372/* Casts */
373LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
374 LLVMTypeRef DestTy, const char *Name);
375LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
376 LLVMTypeRef DestTy, const char *Name);
377LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
378 LLVMTypeRef DestTy, const char *Name);
379LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
380 LLVMTypeRef DestTy, const char *Name);
381LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
382 LLVMTypeRef DestTy, const char *Name);
383LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
384 LLVMTypeRef DestTy, const char *Name);
385LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
386 LLVMTypeRef DestTy, const char *Name);
387LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
388 LLVMTypeRef DestTy, const char *Name);
389LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
390 LLVMTypeRef DestTy, const char *Name);
391LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
392 LLVMTypeRef DestTy, const char *Name);
393LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
394 LLVMTypeRef DestTy, const char *Name);
395LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
396 LLVMTypeRef DestTy, const char *Name);
397
398/* Comparisons */
399LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
400 LLVMValueRef LHS, LLVMValueRef RHS,
401 const char *Name);
402LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
403 LLVMValueRef LHS, LLVMValueRef RHS,
404 const char *Name);
405
406/* Miscellaneous instructions */
407LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
408LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
409 LLVMValueRef *Args, unsigned NumArgs,
410 const char *Name);
411LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
412 LLVMValueRef Then, LLVMValueRef Else,
413 const char *Name);
414LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
415 const char *Name);
416LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
417 LLVMValueRef Index, const char *Name);
418LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
419 LLVMValueRef EltVal, LLVMValueRef Index,
420 const char *Name);
421LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
422 LLVMValueRef V2, LLVMValueRef Mask,
423 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000424
425#ifdef __cplusplus
426}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000427
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000428namespace llvm {
429 /* Opaque module conversions
430 */
431 inline Module *unwrap(LLVMModuleRef M) {
432 return reinterpret_cast<Module*>(M);
433 }
434
435 inline LLVMModuleRef wrap(Module *M) {
436 return reinterpret_cast<LLVMModuleRef>(M);
437 }
438
439 /* Opaque type conversions
440 */
441 inline Type *unwrap(LLVMTypeRef Ty) {
442 return reinterpret_cast<Type*>(Ty);
443 }
444
445 template<typename T>
446 inline T *unwrap(LLVMTypeRef Ty) {
447 return cast<T>(unwrap(Ty));
448 }
449
450 inline Type **unwrap(LLVMTypeRef* Tys) {
451 return reinterpret_cast<Type**>(Tys);
452 }
453
454 inline LLVMTypeRef wrap(const Type *Ty) {
455 return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty));
456 }
457
458 inline LLVMTypeRef *wrap(const Type **Tys) {
459 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
460 }
461
462 /* Opaque value conversions
463 */
464 inline Value *unwrap(LLVMValueRef Val) {
465 return reinterpret_cast<Value*>(Val);
466 }
467
468 template<typename T>
469 inline T *unwrap(LLVMValueRef Val) {
470 return cast<T>(unwrap(Val));
471 }
472
473 inline Value **unwrap(LLVMValueRef *Vals) {
474 return reinterpret_cast<Value**>(Vals);
475 }
476
477 template<typename T>
478 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
479 #if DEBUG
480 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
481 cast<T>(*I);
482 #endif
483 return reinterpret_cast<T**>(Vals);
484 }
485
486 inline LLVMValueRef wrap(const Value *Val) {
487 return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val));
488 }
489
490 inline LLVMValueRef *wrap(const Value **Vals) {
491 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
492 }
493
494 /* Basic block conversions
495 */
496 inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) {
497 return reinterpret_cast<BasicBlock*>(BBRef);
498 }
499
500 inline LLVMBasicBlockRef wrap(const BasicBlock *BB) {
501 return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB));
502 }
503
504 /* Opaque builder conversions.
505 */
506 inline LLVMBuilder *unwrap(LLVMBuilderRef B) {
507 return reinterpret_cast<LLVMBuilder*>(B);
508 }
509
510 inline LLVMBuilderRef wrap(LLVMBuilder *B) {
511 return reinterpret_cast<LLVMBuilderRef>(B);
512 }
513}
514
515#endif /* !defined(__cplusplus) */
516
517#endif /* !defined(LLVM_C_CORE_H) */