blob: fb01b8373520001891a9c064c75efce317c7457e [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);
228
229/* Operations on constants of any type */
230LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
231LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
232LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000233int LLVMIsConstant(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000234int LLVMIsNull(LLVMValueRef Val);
Gordon Henriksendc88c062007-09-18 18:07:51 +0000235int LLVMIsUndef(LLVMValueRef Val);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000236
237/* Operations on scalar constants */
238LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
239 int SignExtend);
240LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N);
241
242/* Operations on composite constants */
243LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
244 int DontNullTerminate);
245LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ArrayTy,
246 LLVMValueRef *ConstantVals, unsigned Length);
247LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
248 int packed);
249LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
250 unsigned Size);
251
252/* Operations on global variables, functions, and aliases (globals) */
253int LLVMIsDeclaration(LLVMValueRef Global);
254LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
255void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
256const char *LLVMGetSection(LLVMValueRef Global);
257void LLVMSetSection(LLVMValueRef Global, const char *Section);
258LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
259void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
260unsigned LLVMGetAlignment(LLVMValueRef Global);
261void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
262
263/* Operations on global variables */
264LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
265void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
266int LLVMHasInitializer(LLVMValueRef GlobalVar);
267LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
268void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
269int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
270void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
271
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000272/* Operations on functions */
273LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
274 LLVMTypeRef FunctionTy);
275void LLVMDeleteFunction(LLVMValueRef Fn);
276unsigned LLVMCountParams(LLVMValueRef Fn);
277void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
278LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
279unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
280unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
281void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
282
283/* Operations on basic blocks */
284LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
285int LLVMValueIsBasicBlock(LLVMValueRef Val);
286LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
287unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
288void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
289LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
290LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
291LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
292 const char *Name);
293void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
294
295
296/*===-- Instruction builders ----------------------------------------------===*/
297
298/* An instruction builder represents a point within a basic block, and is the
299 * exclusive means of building instructions using the C interface.
300 */
301
302LLVMBuilderRef LLVMCreateBuilder();
303void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
304void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
305void LLVMDisposeBuilder(LLVMBuilderRef Builder);
306
307/* Terminators */
308LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
309LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
310LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
311LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
312 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
313LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
314 LLVMBasicBlockRef Else, unsigned NumCases);
315LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
316 LLVMValueRef *Args, unsigned NumArgs,
317 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
318 const char *Name);
319LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
320LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
321
322/* Arithmetic */
323LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
324 const char *Name);
325LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
326 const char *Name);
327LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
328 const char *Name);
329LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
330 const char *Name);
331LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
332 const char *Name);
333LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
334 const char *Name);
335LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
336 const char *Name);
337LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
338 const char *Name);
339LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
340 const char *Name);
341LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
342 const char *Name);
343LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
344 const char *Name);
345LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
346 const char *Name);
347LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
348 const char *Name);
349LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
350 const char *Name);
351LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
352 const char *Name);
353LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
354LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
355
356/* Memory */
357LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
358LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
359 LLVMValueRef Val, const char *Name);
360LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
361LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
362 LLVMValueRef Val, const char *Name);
363LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
364LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
365 const char *Name);
366LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
367LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
368 LLVMValueRef *Indices, unsigned NumIndices,
369 const char *Name);
370
371/* Casts */
372LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
373 LLVMTypeRef DestTy, const char *Name);
374LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
375 LLVMTypeRef DestTy, const char *Name);
376LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
377 LLVMTypeRef DestTy, const char *Name);
378LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
379 LLVMTypeRef DestTy, const char *Name);
380LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
381 LLVMTypeRef DestTy, const char *Name);
382LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
383 LLVMTypeRef DestTy, const char *Name);
384LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
385 LLVMTypeRef DestTy, const char *Name);
386LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
387 LLVMTypeRef DestTy, const char *Name);
388LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
389 LLVMTypeRef DestTy, const char *Name);
390LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
391 LLVMTypeRef DestTy, const char *Name);
392LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
393 LLVMTypeRef DestTy, const char *Name);
394LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
395 LLVMTypeRef DestTy, const char *Name);
396
397/* Comparisons */
398LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
399 LLVMValueRef LHS, LLVMValueRef RHS,
400 const char *Name);
401LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
402 LLVMValueRef LHS, LLVMValueRef RHS,
403 const char *Name);
404
405/* Miscellaneous instructions */
406LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
407LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
408 LLVMValueRef *Args, unsigned NumArgs,
409 const char *Name);
410LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
411 LLVMValueRef Then, LLVMValueRef Else,
412 const char *Name);
413LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
414 const char *Name);
415LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
416 LLVMValueRef Index, const char *Name);
417LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
418 LLVMValueRef EltVal, LLVMValueRef Index,
419 const char *Name);
420LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
421 LLVMValueRef V2, LLVMValueRef Mask,
422 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000423
424#ifdef __cplusplus
425}
Gordon Henriksen76a03742007-09-18 03:18:57 +0000426
Gordon Henriksen7330acd2007-10-05 23:59:36 +0000427namespace llvm {
428 /* Opaque module conversions
429 */
430 inline Module *unwrap(LLVMModuleRef M) {
431 return reinterpret_cast<Module*>(M);
432 }
433
434 inline LLVMModuleRef wrap(Module *M) {
435 return reinterpret_cast<LLVMModuleRef>(M);
436 }
437
438 /* Opaque type conversions
439 */
440 inline Type *unwrap(LLVMTypeRef Ty) {
441 return reinterpret_cast<Type*>(Ty);
442 }
443
444 template<typename T>
445 inline T *unwrap(LLVMTypeRef Ty) {
446 return cast<T>(unwrap(Ty));
447 }
448
449 inline Type **unwrap(LLVMTypeRef* Tys) {
450 return reinterpret_cast<Type**>(Tys);
451 }
452
453 inline LLVMTypeRef wrap(const Type *Ty) {
454 return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty));
455 }
456
457 inline LLVMTypeRef *wrap(const Type **Tys) {
458 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
459 }
460
461 /* Opaque value conversions
462 */
463 inline Value *unwrap(LLVMValueRef Val) {
464 return reinterpret_cast<Value*>(Val);
465 }
466
467 template<typename T>
468 inline T *unwrap(LLVMValueRef Val) {
469 return cast<T>(unwrap(Val));
470 }
471
472 inline Value **unwrap(LLVMValueRef *Vals) {
473 return reinterpret_cast<Value**>(Vals);
474 }
475
476 template<typename T>
477 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
478 #if DEBUG
479 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
480 cast<T>(*I);
481 #endif
482 return reinterpret_cast<T**>(Vals);
483 }
484
485 inline LLVMValueRef wrap(const Value *Val) {
486 return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val));
487 }
488
489 inline LLVMValueRef *wrap(const Value **Vals) {
490 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
491 }
492
493 /* Basic block conversions
494 */
495 inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) {
496 return reinterpret_cast<BasicBlock*>(BBRef);
497 }
498
499 inline LLVMBasicBlockRef wrap(const BasicBlock *BB) {
500 return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB));
501 }
502
503 /* Opaque builder conversions.
504 */
505 inline LLVMBuilder *unwrap(LLVMBuilderRef B) {
506 return reinterpret_cast<LLVMBuilder*>(B);
507 }
508
509 inline LLVMBuilderRef wrap(LLVMBuilder *B) {
510 return reinterpret_cast<LLVMBuilderRef>(B);
511 }
512}
513
514#endif /* !defined(__cplusplus) */
515
516#endif /* !defined(LLVM_C_CORE_H) */