1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
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). *|
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. *|
26 |* 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. *|
31 \*===----------------------------------------------------------------------===*/
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"
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
53 typedef struct LLVMOpaqueModule
*LLVMModuleRef
;
56 * Each value in the LLVM IR has a type, an instance of [lltype]. See the
59 typedef struct LLVMOpaqueType
*LLVMTypeRef
;
62 * When building recursive types using [refine_type], [lltype] values may become
63 * invalid; use [lltypehandle] to resolve this problem. See the
64 * llvm::AbstractTypeHolder] class.
66 typedef struct LLVMOpaqueTypeHandle
*LLVMTypeHandleRef
;
68 typedef struct LLVMOpaqueValue
*LLVMValueRef
;
69 typedef struct LLVMOpaqueBasicBlock
*LLVMBasicBlockRef
;
70 typedef struct LLVMOpaqueBuilder
*LLVMBuilderRef
;
72 /* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
75 typedef struct LLVMOpaqueModuleProvider
*LLVMModuleProviderRef
;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
80 typedef struct LLVMOpaqueMemoryBuffer
*LLVMMemoryBufferRef
;
83 LLVMVoidTypeKind
, /**< type with no size */
84 LLVMFloatTypeKind
, /**< 32 bit floating point type */
85 LLVMDoubleTypeKind
, /**< 64 bit floating point type */
86 LLVMX86_FP80TypeKind
, /**< 80 bit floating point type (X87) */
87 LLVMFP128TypeKind
, /**< 128 bit floating point type (112-bit mantissa)*/
88 LLVMPPC_FP128TypeKind
, /**< 128 bit floating point type (two 64-bits) */
89 LLVMLabelTypeKind
, /**< Labels */
90 LLVMIntegerTypeKind
, /**< Arbitrary bit width integers */
91 LLVMFunctionTypeKind
, /**< Functions */
92 LLVMStructTypeKind
, /**< Structures */
93 LLVMArrayTypeKind
, /**< Arrays */
94 LLVMPointerTypeKind
, /**< Pointers */
95 LLVMOpaqueTypeKind
, /**< Opaque: type with unknown structure */
96 LLVMVectorTypeKind
/**< SIMD 'packed' format, or other vector type */
100 LLVMExternalLinkage
, /**< Externally visible function */
101 LLVMLinkOnceLinkage
, /**< Keep one copy of function when linking (inline)*/
102 LLVMWeakLinkage
, /**< Keep one copy of function when linking (weak) */
103 LLVMAppendingLinkage
, /**< Special purpose, only applies to global arrays */
104 LLVMInternalLinkage
, /**< Rename collisions when linking (static
106 LLVMDLLImportLinkage
, /**< Function to be imported from DLL */
107 LLVMDLLExportLinkage
, /**< Function to be accessible from DLL */
108 LLVMExternalWeakLinkage
,/**< ExternalWeak linkage description */
109 LLVMGhostLinkage
/**< Stand-in functions for streaming fns from
114 LLVMDefaultVisibility
, /**< The GV is visible */
115 LLVMHiddenVisibility
, /**< The GV is hidden */
116 LLVMProtectedVisibility
/**< The GV is protected */
121 LLVMFastCallConv
= 8,
122 LLVMColdCallConv
= 9,
123 LLVMX86StdcallCallConv
= 64,
124 LLVMX86FastcallCallConv
= 65
128 LLVMIntEQ
= 32, /**< equal */
129 LLVMIntNE
, /**< not equal */
130 LLVMIntUGT
, /**< unsigned greater than */
131 LLVMIntUGE
, /**< unsigned greater or equal */
132 LLVMIntULT
, /**< unsigned less than */
133 LLVMIntULE
, /**< unsigned less or equal */
134 LLVMIntSGT
, /**< signed greater than */
135 LLVMIntSGE
, /**< signed greater or equal */
136 LLVMIntSLT
, /**< signed less than */
137 LLVMIntSLE
/**< signed less or equal */
141 LLVMRealPredicateFalse
, /**< Always false (always folded) */
142 LLVMRealOEQ
, /**< True if ordered and equal */
143 LLVMRealOGT
, /**< True if ordered and greater than */
144 LLVMRealOGE
, /**< True if ordered and greater than or equal */
145 LLVMRealOLT
, /**< True if ordered and less than */
146 LLVMRealOLE
, /**< True if ordered and less than or equal */
147 LLVMRealONE
, /**< True if ordered and operands are unequal */
148 LLVMRealORD
, /**< True if ordered (no nans) */
149 LLVMRealUNO
, /**< True if unordered: isnan(X) | isnan(Y) */
150 LLVMRealUEQ
, /**< True if unordered or equal */
151 LLVMRealUGT
, /**< True if unordered or greater than */
152 LLVMRealUGE
, /**< True if unordered, greater than, or equal */
153 LLVMRealULT
, /**< True if unordered or less than */
154 LLVMRealULE
, /**< True if unordered, less than, or equal */
155 LLVMRealUNE
, /**< True if unordered or not equal */
156 LLVMRealPredicateTrue
/**< Always true (always folded) */
160 /*===-- Error handling ----------------------------------------------------===*/
162 void LLVMDisposeMessage(char *Message
);
165 /*===-- Modules -----------------------------------------------------------===*/
167 /* Create and destroy modules. */
168 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
);
169 void LLVMDisposeModule(LLVMModuleRef M
);
172 const char *LLVMGetDataLayout(LLVMModuleRef M
);
173 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
);
176 const char *LLVMGetTarget(LLVMModuleRef M
);
177 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
);
179 /* Same as Module::addTypeName. */
180 int LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
);
181 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
);
184 /*===-- Types -------------------------------------------------------------===*/
186 /* LLVM types conform to the following hierarchy:
201 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
);
202 void LLVMRefineAbstractType(LLVMTypeRef AbstractType
, LLVMTypeRef ConcreteType
);
204 /* Operations on integer types */
205 LLVMTypeRef
LLVMInt1Type();
206 LLVMTypeRef
LLVMInt8Type();
207 LLVMTypeRef
LLVMInt16Type();
208 LLVMTypeRef
LLVMInt32Type();
209 LLVMTypeRef
LLVMInt64Type();
210 LLVMTypeRef
LLVMIntType(unsigned NumBits
);
211 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
);
213 /* Operations on real types */
214 LLVMTypeRef
LLVMFloatType();
215 LLVMTypeRef
LLVMDoubleType();
216 LLVMTypeRef
LLVMX86FP80Type();
217 LLVMTypeRef
LLVMFP128Type();
218 LLVMTypeRef
LLVMPPCFP128Type();
220 /* Operations on function types */
221 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
222 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
224 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
);
225 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
);
226 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
);
227 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
);
229 /* Operations on struct types */
230 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
,
232 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
);
233 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
);
234 int LLVMIsPackedStruct(LLVMTypeRef StructTy
);
236 /* Operations on array, pointer, and vector types (sequence types) */
237 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
);
238 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
);
239 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
);
241 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
);
242 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
);
243 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
);
244 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
);
246 /* Operations on other types */
247 LLVMTypeRef
LLVMVoidType();
248 LLVMTypeRef
LLVMLabelType();
249 LLVMTypeRef
LLVMOpaqueType();
251 /* Operations on type handles */
252 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
);
253 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
);
254 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
);
255 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
);
258 /*===-- Values ------------------------------------------------------------===*/
260 /* The bulk of LLVM's object model consists of values, which comprise a very
261 * rich type hierarchy.
274 /* Operations on all values */
275 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
);
276 const char *LLVMGetValueName(LLVMValueRef Val
);
277 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
);
278 void LLVMDumpValue(LLVMValueRef Val
);
280 /* Operations on constants of any type */
281 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
); /* all zeroes */
282 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
); /* only for int/vector */
283 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
);
284 int LLVMIsConstant(LLVMValueRef Val
);
285 int LLVMIsNull(LLVMValueRef Val
);
286 int LLVMIsUndef(LLVMValueRef Val
);
288 /* Operations on scalar constants */
289 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
291 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
);
293 /* Operations on composite constants */
294 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
295 int DontNullTerminate
);
296 LLVMValueRef
LLVMConstArray(LLVMTypeRef ArrayTy
,
297 LLVMValueRef
*ConstantVals
, unsigned Length
);
298 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
300 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
);
302 /* Constant expressions */
303 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
);
304 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
);
305 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
);
306 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
307 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
308 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
309 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
310 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
311 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
312 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
313 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
314 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
315 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
316 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
317 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
318 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
319 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
320 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
321 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
322 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
323 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
324 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
325 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
326 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
);
327 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
328 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
329 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
330 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
331 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
332 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
333 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
334 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
335 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
336 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
337 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
338 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
339 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
340 LLVMValueRef ConstantIfTrue
,
341 LLVMValueRef ConstantIfFalse
);
342 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
343 LLVMValueRef IndexConstant
);
344 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
345 LLVMValueRef ElementValueConstant
,
346 LLVMValueRef IndexConstant
);
347 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
348 LLVMValueRef VectorBConstant
,
349 LLVMValueRef MaskConstant
);
351 /* Operations on global variables, functions, and aliases (globals) */
352 int LLVMIsDeclaration(LLVMValueRef Global
);
353 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
);
354 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
);
355 const char *LLVMGetSection(LLVMValueRef Global
);
356 void LLVMSetSection(LLVMValueRef Global
, const char *Section
);
357 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
);
358 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
);
359 unsigned LLVMGetAlignment(LLVMValueRef Global
);
360 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
);
362 /* Operations on global variables */
363 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
);
364 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
);
365 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
);
366 int LLVMHasInitializer(LLVMValueRef GlobalVar
);
367 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
);
368 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
);
369 int LLVMIsThreadLocal(LLVMValueRef GlobalVar
);
370 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, int IsThreadLocal
);
371 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar
);
372 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, int IsConstant
);
374 /* Operations on functions */
375 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
376 LLVMTypeRef FunctionTy
);
377 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
);
378 void LLVMDeleteFunction(LLVMValueRef Fn
);
379 unsigned LLVMCountParams(LLVMValueRef Fn
);
380 void LLVMGetParams(LLVMValueRef Fn
, LLVMValueRef
*Params
);
381 LLVMValueRef
LLVMGetParam(LLVMValueRef Fn
, unsigned Index
);
382 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
);
383 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
);
384 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
);
385 const char *LLVMGetCollector(LLVMValueRef Fn
);
386 void LLVMSetCollector(LLVMValueRef Fn
, const char *Coll
);
388 /* Operations on basic blocks */
389 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb
);
390 int LLVMValueIsBasicBlock(LLVMValueRef Val
);
391 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
);
392 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn
);
393 void LLVMGetBasicBlocks(LLVMValueRef Fn
, LLVMBasicBlockRef
*BasicBlocks
);
394 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
);
395 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef Fn
, const char *Name
);
396 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB
,
398 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB
);
400 /* Operations on call sites */
401 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
);
402 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
);
404 /* Operations on phi nodes */
405 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
406 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
);
407 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
);
408 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
);
409 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
);
411 /*===-- Instruction builders ----------------------------------------------===*/
413 /* An instruction builder represents a point within a basic block, and is the
414 * exclusive means of building instructions using the C interface.
417 LLVMBuilderRef
LLVMCreateBuilder();
418 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
419 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
);
420 void LLVMDisposeBuilder(LLVMBuilderRef Builder
);
423 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef
);
424 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef
, LLVMValueRef V
);
425 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef
, LLVMBasicBlockRef Dest
);
426 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef
, LLVMValueRef If
,
427 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
);
428 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef
, LLVMValueRef V
,
429 LLVMBasicBlockRef Else
, unsigned NumCases
);
430 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef
, LLVMValueRef Fn
,
431 LLVMValueRef
*Args
, unsigned NumArgs
,
432 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
434 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef
);
435 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef
);
437 /* Add a case to the switch instruction */
438 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
439 LLVMBasicBlockRef Dest
);
442 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
444 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
446 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
448 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
450 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
452 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
454 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
456 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
458 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
460 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
462 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
464 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
466 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
468 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
470 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
472 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
473 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
476 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
477 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
,
478 LLVMValueRef Val
, const char *Name
);
479 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
480 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
,
481 LLVMValueRef Val
, const char *Name
);
482 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef
, LLVMValueRef PointerVal
);
483 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef
, LLVMValueRef PointerVal
,
485 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef
, LLVMValueRef Val
, LLVMValueRef Ptr
);
486 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
487 LLVMValueRef
*Indices
, unsigned NumIndices
,
491 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
492 LLVMTypeRef DestTy
, const char *Name
);
493 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef
, LLVMValueRef Val
,
494 LLVMTypeRef DestTy
, const char *Name
);
495 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef
, LLVMValueRef Val
,
496 LLVMTypeRef DestTy
, const char *Name
);
497 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef
, LLVMValueRef Val
,
498 LLVMTypeRef DestTy
, const char *Name
);
499 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef
, LLVMValueRef Val
,
500 LLVMTypeRef DestTy
, const char *Name
);
501 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
502 LLVMTypeRef DestTy
, const char *Name
);
503 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
504 LLVMTypeRef DestTy
, const char *Name
);
505 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
506 LLVMTypeRef DestTy
, const char *Name
);
507 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef
, LLVMValueRef Val
,
508 LLVMTypeRef DestTy
, const char *Name
);
509 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef
, LLVMValueRef Val
,
510 LLVMTypeRef DestTy
, const char *Name
);
511 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef
, LLVMValueRef Val
,
512 LLVMTypeRef DestTy
, const char *Name
);
513 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
514 LLVMTypeRef DestTy
, const char *Name
);
517 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef
, LLVMIntPredicate Op
,
518 LLVMValueRef LHS
, LLVMValueRef RHS
,
520 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef
, LLVMRealPredicate Op
,
521 LLVMValueRef LHS
, LLVMValueRef RHS
,
524 /* Miscellaneous instructions */
525 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
526 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef
, LLVMValueRef Fn
,
527 LLVMValueRef
*Args
, unsigned NumArgs
,
529 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef
, LLVMValueRef If
,
530 LLVMValueRef Then
, LLVMValueRef Else
,
532 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef
, LLVMValueRef List
, LLVMTypeRef Ty
,
534 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
535 LLVMValueRef Index
, const char *Name
);
536 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
537 LLVMValueRef EltVal
, LLVMValueRef Index
,
539 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef
, LLVMValueRef V1
,
540 LLVMValueRef V2
, LLVMValueRef Mask
,
544 /*===-- Module providers --------------------------------------------------===*/
546 /* Encapsulates the module M in a module provider, taking ownership of the
548 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
550 LLVMModuleProviderRef
551 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
);
553 /* Destroys the module provider MP as well as the contained module.
554 * See the destructor llvm::ModuleProvider::~ModuleProvider.
556 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP
);
559 /*===-- Memory buffers ----------------------------------------------------===*/
561 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path
,
562 LLVMMemoryBufferRef
*OutMemBuf
,
564 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
566 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
);
572 class ModuleProvider
;
575 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
576 inline ty *unwrap(ref P) { \
577 return reinterpret_cast<ty*>(P); \
580 inline ref wrap(const ty *P) { \
581 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
584 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Type
, LLVMTypeRef
)
585 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Value
, LLVMValueRef
)
586 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module
, LLVMModuleRef
)
587 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock
, LLVMBasicBlockRef
)
588 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder
, LLVMBuilderRef
)
589 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder
, LLVMTypeHandleRef
)
590 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider
, LLVMModuleProviderRef
)
591 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer
, LLVMMemoryBufferRef
)
593 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
595 /* Specialized opaque type conversions.
598 inline T
*unwrap(LLVMTypeRef Ty
) {
599 return cast
<T
>(unwrap(Ty
));
602 inline Type
**unwrap(LLVMTypeRef
* Tys
) {
603 return reinterpret_cast<Type
**>(Tys
);
606 inline LLVMTypeRef
*wrap(const Type
**Tys
) {
607 return reinterpret_cast<LLVMTypeRef
*>(const_cast<Type
**>(Tys
));
610 /* Specialized opaque value conversions.
613 inline T
*unwrap(LLVMValueRef Val
) {
614 return cast
<T
>(unwrap(Val
));
617 inline Value
**unwrap(LLVMValueRef
*Vals
) {
618 return reinterpret_cast<Value
**>(Vals
);
622 inline T
**unwrap(LLVMValueRef
*Vals
, unsigned Length
) {
624 for (LLVMValueRef
*I
= Vals
, E
= Vals
+ Length
; I
!= E
; ++I
)
627 return reinterpret_cast<T
**>(Vals
);
630 inline LLVMValueRef
*wrap(const Value
**Vals
) {
631 return reinterpret_cast<LLVMValueRef
*>(const_cast<Value
**>(Vals
));
635 #endif /* !defined(__cplusplus) */
637 #endif /* !defined(LLVM_C_CORE_H) */