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);
292 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
294 /* Operations on composite constants */
295 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
296 int DontNullTerminate);
297 LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy,
298 LLVMValueRef *ConstantVals, unsigned Length);
299 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
301 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
303 /* Constant expressions */
304 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
305 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
306 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
307 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
308 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
309 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
310 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
311 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
312 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
313 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
314 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
315 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
316 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
317 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
318 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
319 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
320 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
321 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
322 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
323 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
324 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
325 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
326 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
327 LLVMValueRef *ConstantIndices, unsigned NumIndices);
328 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
329 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
330 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
331 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
332 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
333 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
334 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
335 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
336 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
337 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
338 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
339 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
340 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
341 LLVMValueRef ConstantIfTrue,
342 LLVMValueRef ConstantIfFalse);
343 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
344 LLVMValueRef IndexConstant);
345 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
346 LLVMValueRef ElementValueConstant,
347 LLVMValueRef IndexConstant);
348 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
349 LLVMValueRef VectorBConstant,
350 LLVMValueRef MaskConstant);
352 /* Operations on global variables, functions, and aliases (globals) */
353 int LLVMIsDeclaration(LLVMValueRef Global);
354 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
355 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
356 const char *LLVMGetSection(LLVMValueRef Global);
357 void LLVMSetSection(LLVMValueRef Global, const char *Section);
358 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
359 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
360 unsigned LLVMGetAlignment(LLVMValueRef Global);
361 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
363 /* Operations on global variables */
364 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
365 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
366 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
367 int LLVMHasInitializer(LLVMValueRef GlobalVar);
368 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
369 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
370 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
371 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
372 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
373 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
375 /* Operations on functions */
376 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
377 LLVMTypeRef FunctionTy);
378 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
379 void LLVMDeleteFunction(LLVMValueRef Fn);
380 unsigned LLVMCountParams(LLVMValueRef Fn);
381 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
382 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
383 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
384 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
385 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
386 const char *LLVMGetCollector(LLVMValueRef Fn);
387 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
389 /* Operations on basic blocks */
390 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
391 int LLVMValueIsBasicBlock(LLVMValueRef Val);
392 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
393 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
394 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
395 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
396 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
397 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
399 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
401 /* Operations on call sites */
402 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
403 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
405 /* Operations on phi nodes */
406 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
407 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
408 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
409 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
410 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
412 /*===-- Instruction builders ----------------------------------------------===*/
414 /* An instruction builder represents a point within a basic block, and is the
415 * exclusive means of building instructions using the C interface.
418 LLVMBuilderRef LLVMCreateBuilder();
419 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
420 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
421 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
424 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
425 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
426 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
427 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
428 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
429 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
430 LLVMBasicBlockRef Else, unsigned NumCases);
431 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
432 LLVMValueRef *Args, unsigned NumArgs,
433 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
435 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
436 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
438 /* Add a case to the switch instruction */
439 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
440 LLVMBasicBlockRef Dest);
443 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
445 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
447 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
449 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
451 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
453 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
455 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
457 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
459 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
461 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
463 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
465 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
467 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
469 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
471 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
473 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
474 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
477 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
478 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
479 LLVMValueRef Val, const char *Name);
480 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
481 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
482 LLVMValueRef Val, const char *Name);
483 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
484 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
486 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
487 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
488 LLVMValueRef *Indices, unsigned NumIndices,
492 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
493 LLVMTypeRef DestTy, const char *Name);
494 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
495 LLVMTypeRef DestTy, const char *Name);
496 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
497 LLVMTypeRef DestTy, const char *Name);
498 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
499 LLVMTypeRef DestTy, const char *Name);
500 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
501 LLVMTypeRef DestTy, const char *Name);
502 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
503 LLVMTypeRef DestTy, const char *Name);
504 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
505 LLVMTypeRef DestTy, const char *Name);
506 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
507 LLVMTypeRef DestTy, const char *Name);
508 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
509 LLVMTypeRef DestTy, const char *Name);
510 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
511 LLVMTypeRef DestTy, const char *Name);
512 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
513 LLVMTypeRef DestTy, const char *Name);
514 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
515 LLVMTypeRef DestTy, const char *Name);
518 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
519 LLVMValueRef LHS, LLVMValueRef RHS,
521 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
522 LLVMValueRef LHS, LLVMValueRef RHS,
525 /* Miscellaneous instructions */
526 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
527 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
528 LLVMValueRef *Args, unsigned NumArgs,
530 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
531 LLVMValueRef Then, LLVMValueRef Else,
533 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
535 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
536 LLVMValueRef Index, const char *Name);
537 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
538 LLVMValueRef EltVal, LLVMValueRef Index,
540 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
541 LLVMValueRef V2, LLVMValueRef Mask,
545 /*===-- Module providers --------------------------------------------------===*/
547 /* Encapsulates the module M in a module provider, taking ownership of the
549 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
551 LLVMModuleProviderRef
552 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
554 /* Destroys the module provider MP as well as the contained module.
555 * See the destructor llvm::ModuleProvider::~ModuleProvider.
557 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
560 /*===-- Memory buffers ----------------------------------------------------===*/
562 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
563 LLVMMemoryBufferRef *OutMemBuf,
565 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
567 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
573 class ModuleProvider;
576 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
577 inline ty *unwrap(ref P) { \
578 return reinterpret_cast<ty*>(P); \
581 inline ref wrap(const ty *P) { \
582 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
585 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Type, LLVMTypeRef )
586 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Value, LLVMValueRef )
587 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
588 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
589 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef )
590 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
591 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
592 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
594 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
596 /* Specialized opaque type conversions.
599 inline T *unwrap(LLVMTypeRef Ty) {
600 return cast<T>(unwrap(Ty));
603 inline Type **unwrap(LLVMTypeRef* Tys) {
604 return reinterpret_cast<Type**>(Tys);
607 inline LLVMTypeRef *wrap(const Type **Tys) {
608 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
611 /* Specialized opaque value conversions.
614 inline T *unwrap(LLVMValueRef Val) {
615 return cast<T>(unwrap(Val));
618 inline Value **unwrap(LLVMValueRef *Vals) {
619 return reinterpret_cast<Value**>(Vals);
623 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
625 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
628 return reinterpret_cast<T**>(Vals);
631 inline LLVMValueRef *wrap(const Value **Vals) {
632 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
636 #endif /* !defined(__cplusplus) */
638 #endif /* !defined(LLVM_C_CORE_H) */