comparison tools/binding/llvm/c/Core.d @ 1273:1ba61de8796b

Committing LLVM binding for D as it currently exists in the SVN repository.
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 27 Apr 2009 22:33:17 +0200
parents
children 4ff9ab0d472c
comparison
equal deleted inserted replaced
1272:dd4766851b37 1273:1ba61de8796b
1 // Converted to the D programming language by Tomas Lindquist Olsen 2008
2 // Original file header:
3 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
4 |* *|
5 |* The LLVM Compiler Infrastructure *|
6 |* *|
7 |* This file is distributed under the University of Illinois Open Source *|
8 |* License. See LICENSE.TXT for details. *|
9 |* *|
10 |*===----------------------------------------------------------------------===*|
11 |* *|
12 |* This header declares the C interface to libLLVMCore.a, which implements *|
13 |* the LLVM intermediate representation. *|
14 |* *|
15 |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
16 |* parameters must be passed as base types. Despite the declared types, most *|
17 |* of the functions provided operate only on branches of the type hierarchy. *|
18 |* The declared parameter names are descriptive and specify which type is *|
19 |* required. Additionally, each type hierarchy is documented along with the *|
20 |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
21 |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
22 |* form unwrap<RequiredType>(Param). *|
23 |* *|
24 |* Many exotic languages can interoperate with C code but have a harder time *|
25 |* with C++ due to name mangling. So in addition to C, this interface enables *|
26 |* tools written in such languages. *|
27 |* *|
28 |* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
29 |* helpers to perform opaque reference<-->pointer conversions. These helpers *|
30 |* are shorter and more tightly typed than writing the casts by hand when *|
31 |* authoring bindings. In assert builds, they will do runtime type checking. *|
32 |* *|
33 \*===----------------------------------------------------------------------===*/
34 module llvm.c.Core;
35
36 extern(C):
37
38 /* Opaque types. */
39
40 private
41 {
42 struct LLVM_OpaqueModule {}
43 struct LLVM_OpaqueType {}
44 struct LLVM_OpaqueTypeHandle {}
45 struct LLVM_OpaqueValue {}
46 struct LLVM_OpaqueBasicBlock {}
47 struct LLVM_OpaqueBuilder {}
48 struct LLVM_OpaqueModuleProvider {}
49 struct LLVM_OpaqueMemoryBuffer {}
50 struct LLVM_OpaquePassManager {}
51 }
52
53 /**
54 * The top-level container for all other LLVM Intermediate Representation (IR)
55 * objects. See the llvm::Module class.
56 */
57 typedef LLVM_OpaqueModule* LLVMModuleRef;
58
59 /**
60 * Each value in the LLVM IR has a type, an instance of [lltype]. See the
61 * llvm::Type class.
62 */
63 typedef LLVM_OpaqueType* LLVMTypeRef;
64
65 /**
66 * When building recursive types using [refine_type], [lltype] values may become
67 * invalid; use [lltypehandle] to resolve this problem. See the
68 * llvm::AbstractTypeHolder] class.
69 */
70 typedef LLVM_OpaqueTypeHandle* LLVMTypeHandleRef;
71
72 typedef LLVM_OpaqueValue* LLVMValueRef;
73 typedef LLVM_OpaqueBasicBlock* LLVMBasicBlockRef;
74 typedef LLVM_OpaqueBuilder* LLVMBuilderRef;
75
76 /* Used to provide a module to JIT or interpreter.
77 * See the llvm::ModuleProvider class.
78 */
79 typedef LLVM_OpaqueModuleProvider* LLVMModuleProviderRef;
80
81 /* Used to provide a module to JIT or interpreter.
82 * See the llvm::MemoryBuffer class.
83 */
84 typedef LLVM_OpaqueMemoryBuffer* LLVMMemoryBufferRef;
85
86 /** See the llvm::PassManagerBase class. */
87 typedef LLVM_OpaquePassManager* LLVMPassManagerRef;
88
89 enum LLVMParamAttr {
90 ZExt = 1<<0,
91 SExt = 1<<1,
92 NoReturn = 1<<2,
93 InReg = 1<<3,
94 StructRet = 1<<4,
95 NoUnwind = 1<<5,
96 NoAlias = 1<<6,
97 ByVal = 1<<7,
98 Nest = 1<<8,
99 ReadNone = 1<<9,
100 ReadOnly = 1<<10
101 }
102
103 enum LLVMTypeKind {
104 Void, /**< type with no size */
105 Float, /**< 32 bit floating point type */
106 Double, /**< 64 bit floating point type */
107 X86_FP80, /**< 80 bit floating point type (X87) */
108 FP128, /**< 128 bit floating point type (112-bit mantissa)*/
109 PPC_FP128, /**< 128 bit floating point type (two 64-bits) */
110 Label, /**< Labels */
111 Integer, /**< Arbitrary bit width integers */
112 Function, /**< Functions */
113 Struct, /**< Structures */
114 Array, /**< Arrays */
115 Pointer, /**< Pointers */
116 Opaque, /**< Opaque: type with unknown structure */
117 Vector /**< SIMD 'packed' format, or other vector type */
118 }
119
120 enum LLVMLinkage {
121 External, /**< Externally visible function */
122 LinkOnce, /**< Keep one copy of function when linking (inline)*/
123 Weak, /**< Keep one copy of function when linking (weak) */
124 Appending, /**< Special purpose, only applies to global arrays */
125 Internal, /**< Rename collisions when linking (static functions) */
126 DLLImport, /**< Function to be imported from DLL */
127 DLLExport, /**< Function to be accessible from DLL */
128 ExternalWeak,/**< ExternalWeak linkage description */
129 Ghost /**< Stand-in functions for streaming fns from bitcode */
130 }
131
132 enum LLVMVisibility {
133 Default, /**< The GV is visible */
134 Hidden, /**< The GV is hidden */
135 Protected/**< The GV is protected */
136 }
137
138 enum LLVMCallConv {
139 C = 0,
140 Fast = 8,
141 Cold = 9,
142 X86Stdcall = 64,
143 X86Fastcall= 65
144 }
145
146 enum LLVMIntPredicate {
147 EQ = 32, /**< equal */
148 NE, /**< not equal */
149 UGT, /**< uint greater than */
150 UGE, /**< uint greater or equal */
151 ULT, /**< uint less than */
152 ULE, /**< uint less or equal */
153 SGT, /**< signed greater than */
154 SGE, /**< signed greater or equal */
155 SLT, /**< signed less than */
156 SLE /**< signed less or equal */
157 }
158
159 enum LLVMRealPredicate {
160 False, /**< Always false (always folded) */
161 OEQ, /**< True if ordered and equal */
162 OGT, /**< True if ordered and greater than */
163 OGE, /**< True if ordered and greater than or equal */
164 OLT, /**< True if ordered and less than */
165 OLE, /**< True if ordered and less than or equal */
166 ONE, /**< True if ordered and operands are unequal */
167 ORD, /**< True if ordered (no nans) */
168 UNO, /**< True if unordered: isnan(X) | isnan(Y) */
169 UEQ, /**< True if unordered or equal */
170 UGT, /**< True if unordered or greater than */
171 UGE, /**< True if unordered, greater than, or equal */
172 ULT, /**< True if unordered or less than */
173 ULE, /**< True if unordered, less than, or equal */
174 UNE, /**< True if unordered or not equal */
175 True /**< Always true (always folded) */
176 }
177
178 /*===-- Error handling ----------------------------------------------------===*/
179
180 void LLVMDisposeMessage(char *Message);
181
182
183 /*===-- Modules -----------------------------------------------------------===*/
184
185 /* Create and destroy modules. */
186 /** See llvm::Module::Module. */
187 LLVMModuleRef LLVMModuleCreateWithName(/*const*/ char *ModuleID);
188
189 /** See llvm::Module::~Module. */
190 void LLVMDisposeModule(LLVMModuleRef M);
191
192 /** Data layout. See Module::getDataLayout. */
193 /*const*/ char *LLVMGetDataLayout(LLVMModuleRef M);
194 void LLVMSetDataLayout(LLVMModuleRef M, /*const*/ char *Triple);
195
196 /** Target triple. See Module::getTargetTriple. */
197 /*const*/ char *LLVMGetTarget(LLVMModuleRef M);
198 void LLVMSetTarget(LLVMModuleRef M, /*const*/ char *Triple);
199
200 /** See Module::addTypeName. */
201 int LLVMAddTypeName(LLVMModuleRef M, /*const*/ char *Name, LLVMTypeRef Ty);
202 void LLVMDeleteTypeName(LLVMModuleRef M, /*const*/ char *Name);
203
204 /** See Module::dump. */
205 void LLVMDumpModule(LLVMModuleRef M);
206
207 /*===-- Types -------------------------------------------------------------===*/
208
209 /* LLVM types conform to the following hierarchy:
210 *
211 * types:
212 * integer type
213 * real type
214 * function type
215 * sequence types:
216 * array type
217 * pointer type
218 * vector type
219 * void type
220 * label type
221 * opaque type
222 */
223
224 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
225 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
226
227 /* Operations on integer types */
228 LLVMTypeRef LLVMInt1Type();
229 LLVMTypeRef LLVMInt8Type();
230 LLVMTypeRef LLVMInt16Type();
231 LLVMTypeRef LLVMInt32Type();
232 LLVMTypeRef LLVMInt64Type();
233 LLVMTypeRef LLVMIntType(uint NumBits);
234 uint LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
235
236 /* Operations on real types */
237 LLVMTypeRef LLVMFloatType();
238 LLVMTypeRef LLVMDoubleType();
239 LLVMTypeRef LLVMX86FP80Type();
240 LLVMTypeRef LLVMFP128Type();
241 LLVMTypeRef LLVMPPCFP128Type();
242
243 /* Operations on function types */
244 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
245 LLVMTypeRef *ParamTypes, uint ParamCount,
246 int IsVarArg);
247 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
248 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
249 uint LLVMCountParamTypes(LLVMTypeRef FunctionTy);
250 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
251
252 /* Operations on struct types */
253 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, uint ElementCount,
254 int Packed);
255 uint LLVMCountStructElementTypes(LLVMTypeRef StructTy);
256 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
257 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
258
259 /* Operations on array, pointer, and vector types (sequence types) */
260 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, uint ElementCount);
261 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, uint AddressSpace);
262 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, uint ElementCount);
263
264 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
265 uint LLVMGetArrayLength(LLVMTypeRef ArrayTy);
266 uint LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
267 uint LLVMGetVectorSize(LLVMTypeRef VectorTy);
268
269 /* Operations on other types */
270 LLVMTypeRef LLVMVoidType();
271 LLVMTypeRef LLVMLabelType();
272 LLVMTypeRef LLVMOpaqueType();
273
274 /* Operations on type handles */
275 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
276 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
277 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
278 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
279
280
281 /*===-- Values ------------------------------------------------------------===*/
282
283 /* The bulk of LLVM's object model consists of values, which comprise a very
284 * rich type hierarchy.
285 *
286 * values:
287 * constants:
288 * scalar constants
289 * composite contants
290 * globals:
291 * global variable
292 * function
293 * alias
294 * basic blocks
295 */
296
297 /* Operations on all values */
298 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
299 /*const*/ char *LLVMGetValueName(LLVMValueRef Val);
300 void LLVMSetValueName(LLVMValueRef Val, /*const*/ char *Name);
301 void LLVMDumpValue(LLVMValueRef Val);
302
303 /* Operations on constants of any type */
304 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
305 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
306 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
307 int LLVMIsConstant(LLVMValueRef Val);
308 int LLVMIsNull(LLVMValueRef Val);
309 int LLVMIsUndef(LLVMValueRef Val);
310
311 /* Operations on scalar constants */
312 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, ulong N,
313 int SignExtend);
314 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
315 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, /*const*/ char *Text);
316
317 /* Operations on composite constants */
318 LLVMValueRef LLVMConstString(/*const*/ char *Str, uint Length,
319 int DontNullTerminate);
320 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
321 LLVMValueRef *ConstantVals, uint Length);
322 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, uint Count,
323 int packed);
324 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, uint Size);
325
326 /* Constant expressions */
327 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
328 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
329 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
330 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
331 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
332 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
333 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
334 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
339 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
340 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
341 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
342 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
343 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
344 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
345 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
346 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
347 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
348 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
349 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
350 LLVMValueRef *ConstantIndices, uint NumIndices);
351 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
352 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
353 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
354 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
355 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
356 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
357 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
358 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
359 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
360 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
361 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
362 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
363 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
364 LLVMValueRef ConstantIfTrue,
365 LLVMValueRef ConstantIfFalse);
366 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
367 LLVMValueRef IndexConstant);
368 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
369 LLVMValueRef ElementValueConstant,
370 LLVMValueRef IndexConstant);
371 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
372 LLVMValueRef VectorBConstant,
373 LLVMValueRef MaskConstant);
374
375 /* Operations on global variables, functions, and aliases (globals) */
376 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
377 int LLVMIsDeclaration(LLVMValueRef Global);
378 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
379 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
380 /*const*/ char *LLVMGetSection(LLVMValueRef Global);
381 void LLVMSetSection(LLVMValueRef Global, /*const*/ char *Section);
382 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
383 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
384 uint LLVMGetAlignment(LLVMValueRef Global);
385 void LLVMSetAlignment(LLVMValueRef Global, uint Bytes);
386
387 /* Operations on global variables */
388 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, /*const*/ char *Name);
389 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, /*const*/ char *Name);
390 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
391 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
392 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
393 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
394 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
395 int LLVMHasInitializer(LLVMValueRef GlobalVar);
396 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
397 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
398 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
399 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
400 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
401 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
402
403 /* Operations on functions */
404 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, /*const*/ char *Name,
405 LLVMTypeRef FunctionTy);
406 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, /*const*/ char *Name);
407 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
408 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
409 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
410 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
411 void LLVMDeleteFunction(LLVMValueRef Fn);
412 uint LLVMGetIntrinsicID(LLVMValueRef Fn);
413 uint LLVMGetFunctionCallConv(LLVMValueRef Fn);
414 void LLVMSetFunctionCallConv(LLVMValueRef Fn, uint CC);
415 /*const*/ char *LLVMGetCollector(LLVMValueRef Fn);
416 void LLVMSetCollector(LLVMValueRef Fn, /*const*/ char *Coll);
417
418 /* Operations on parameters */
419 uint LLVMCountParams(LLVMValueRef Fn);
420 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
421 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, uint Index);
422 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
423 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
424 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
425 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
426 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
427 void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
428 void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
429 void LLVMSetParamAlignment(LLVMValueRef Arg, uint alignm);
430
431
432 /* Operations on basic blocks */
433 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
434 int LLVMValueIsBasicBlock(LLVMValueRef Val);
435 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
436 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
437 uint LLVMCountBasicBlocks(LLVMValueRef Fn);
438 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
439 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
440 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
441 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
442 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
443 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
444 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, /*const*/ char *Name);
445 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
446 /*const*/ char *Name);
447 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
448
449 /* Operations on instructions */
450 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
451 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
452 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
453 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
454 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
455
456 /* Operations on call sites */
457 void LLVMSetInstructionCallConv(LLVMValueRef Instr, uint CC);
458 uint LLVMGetInstructionCallConv(LLVMValueRef Instr);
459 void LLVMAddInstrParamAttr(LLVMValueRef Instr, uint index, LLVMParamAttr);
460 void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, uint index,
461 LLVMParamAttr);
462 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, uint index,
463 uint alignm);
464
465
466 /* Operations on phi nodes */
467 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
468 LLVMBasicBlockRef *IncomingBlocks, uint Count);
469 uint LLVMCountIncoming(LLVMValueRef PhiNode);
470 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, uint Index);
471 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, uint Index);
472
473 /*===-- Instruction builders ----------------------------------------------===*/
474
475 /* An instruction builder represents a point within a basic block, and is the
476 * exclusive means of building instructions using the C interface.
477 */
478
479 LLVMBuilderRef LLVMCreateBuilder();
480 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
481 LLVMValueRef Instr);
482 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
483 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
484 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
485 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
486
487 /* Terminators */
488 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
489 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
490 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
491 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
492 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
493 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
494 LLVMBasicBlockRef Else, uint NumCases);
495 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
496 LLVMValueRef *Args, uint NumArgs,
497 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
498 /*const*/ char *Name);
499 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
500 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
501
502 /* Add a case to the switch instruction */
503 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
504 LLVMBasicBlockRef Dest);
505
506 /* Arithmetic */
507 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
508 /*const*/ char *Name);
509 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
510 /*const*/ char *Name);
511 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
512 /*const*/ char *Name);
513 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
514 /*const*/ char *Name);
515 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
516 /*const*/ char *Name);
517 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
518 /*const*/ char *Name);
519 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
520 /*const*/ char *Name);
521 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
522 /*const*/ char *Name);
523 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
524 /*const*/ char *Name);
525 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
526 /*const*/ char *Name);
527 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
528 /*const*/ char *Name);
529 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
530 /*const*/ char *Name);
531 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
532 /*const*/ char *Name);
533 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
534 /*const*/ char *Name);
535 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
536 /*const*/ char *Name);
537 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, /*const*/ char *Name);
538 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, /*const*/ char *Name);
539
540 /* Memory */
541 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, /*const*/ char *Name);
542 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
543 LLVMValueRef Val, /*const*/ char *Name);
544 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, /*const*/ char *Name);
545 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
546 LLVMValueRef Val, /*const*/ char *Name);
547 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
548 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
549 /*const*/ char *Name);
550 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
551 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
552 LLVMValueRef *Indices, uint NumIndices,
553 /*const*/ char *Name);
554
555 /* Casts */
556 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
557 LLVMTypeRef DestTy, /*const*/ char *Name);
558 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
559 LLVMTypeRef DestTy, /*const*/ char *Name);
560 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
561 LLVMTypeRef DestTy, /*const*/ char *Name);
562 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
563 LLVMTypeRef DestTy, /*const*/ char *Name);
564 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
565 LLVMTypeRef DestTy, /*const*/ char *Name);
566 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
567 LLVMTypeRef DestTy, /*const*/ char *Name);
568 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
569 LLVMTypeRef DestTy, /*const*/ char *Name);
570 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
571 LLVMTypeRef DestTy, /*const*/ char *Name);
572 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
573 LLVMTypeRef DestTy, /*const*/ char *Name);
574 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
575 LLVMTypeRef DestTy, /*const*/ char *Name);
576 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
577 LLVMTypeRef DestTy, /*const*/ char *Name);
578 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
579 LLVMTypeRef DestTy, /*const*/ char *Name);
580
581 /* Comparisons */
582 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
583 LLVMValueRef LHS, LLVMValueRef RHS,
584 /*const*/ char *Name);
585 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
586 LLVMValueRef LHS, LLVMValueRef RHS,
587 /*const*/ char *Name);
588
589 /* Miscellaneous instructions */
590 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, /*const*/ char *Name);
591 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
592 LLVMValueRef *Args, uint NumArgs,
593 /*const*/ char *Name);
594 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
595 LLVMValueRef Then, LLVMValueRef Else,
596 /*const*/ char *Name);
597 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
598 /*const*/ char *Name);
599 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
600 LLVMValueRef Index, /*const*/ char *Name);
601 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
602 LLVMValueRef EltVal, LLVMValueRef Index,
603 /*const*/ char *Name);
604 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
605 LLVMValueRef V2, LLVMValueRef Mask,
606 /*const*/ char *Name);
607
608
609 /*===-- Module providers --------------------------------------------------===*/
610
611 /* Encapsulates the module M in a module provider, taking ownership of the
612 * module.
613 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
614 */
615 LLVMModuleProviderRef
616 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
617
618 /* Destroys the module provider MP as well as the contained module.
619 * See the destructor llvm::ModuleProvider::~ModuleProvider.
620 */
621 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
622
623
624 /*===-- Memory buffers ----------------------------------------------------===*/
625
626 int LLVMCreateMemoryBufferWithContentsOfFile(/*const*/ char *Path,
627 LLVMMemoryBufferRef *OutMemBuf,
628 char **OutMessage);
629 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
630 char **OutMessage);
631 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
632
633 /*===-- Pass Managers -----------------------------------------------------===*/
634
635 /** Constructs a new whole-module pass pipeline. This type of pipeline is
636 suitable for link-time optimization and whole-module transformations.
637 See llvm::PassManager::PassManager. */
638 LLVMPassManagerRef LLVMCreatePassManager();
639
640 /** Constructs a new function-by-function pass pipeline over the module
641 provider. It does not take ownership of the module provider. This type of
642 pipeline is suitable for code generation and JIT compilation tasks.
643 See llvm::FunctionPassManager::FunctionPassManager. */
644 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
645
646 /** Initializes, executes on the provided module, and finalizes all of the
647 passes scheduled in the pass manager. Returns 1 if any of the passes
648 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
649 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
650
651 /** Initializes all of the function passes scheduled in the function pass
652 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
653 See llvm::FunctionPassManager::doInitialization. */
654 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
655
656 /** Executes all of the function passes scheduled in the function pass manager
657 on the provided function. Returns 1 if any of the passes modified the
658 function, false otherwise.
659 See llvm::FunctionPassManager::run(Function&). */
660 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
661
662 /** Finalizes all of the function passes scheduled in in the function pass
663 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
664 See llvm::FunctionPassManager::doFinalization. */
665 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
666
667 /** Frees the memory of a pass pipeline. For function pipelines, does not free
668 the module provider.
669 See llvm::PassManagerBase::~PassManagerBase. */
670 void LLVMDisposePassManager(LLVMPassManagerRef PM);