Add (very basic) bindings for ModuleProvider.
[oota-llvm.git] / bindings / ocaml / llvm / llvm.mli
1 (*===-- tools/ml/llvm.ml - LLVM Ocaml Interface ---------------------------===*
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 interface provides an ocaml API for the LLVM intermediate
11  * representation, the classes in the VMCore library.
12  *
13  *===----------------------------------------------------------------------===*)
14
15
16 (* These abstract types correlate directly to the LLVM VMCore classes. *)
17
18 (** The top-level container for all other LLVM Intermediate Representation (IR)
19     objects. See the [llvm::Module] class. **)
20 type llmodule
21
22 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
23     [llvm::Type] class. **)
24 type lltype 
25
26 (** When building recursive types using [refine_type], [lltype] values may
27     become invalid; use [lltypehandle] to resolve this problem. See the
28     [llvm::AbstractTypeHolder] class. **)
29 type lltypehandle
30
31 (** Any value in the LLVM IR. Functions, instructions, global variables,
32     constants, and much more are all [llvalues]. See the [llvm::Value] class.
33     This type covers a wide range of subclasses. **)
34 type llvalue
35
36 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. **)
37 type llbasicblock
38
39 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
40     class. **)
41 type llbuilder
42
43 (** Used to provide a module to JIT or interpreter. **)
44 type llmoduleprovider
45
46 (** The kind of an [lltype], the result of [classify_type ty]. See the 
47     [llvm::Type::TypeID] enumeration. **)
48 type type_kind =
49   Void_type
50 | Float_type
51 | Double_type
52 | X86fp80_type
53 | Fp128_type
54 | Ppc_fp128_type
55 | Label_type
56 | Integer_type
57 | Function_type
58 | Struct_type
59 | Array_type
60 | Pointer_type
61 | Opaque_type
62 | Vector_type
63
64 (** The linkage of a global value, accessed with [linkage gv] and
65     [set_linkage l gv]. See [llvm::GlobalValue::LinkageTypes]. **)
66 type linkage =
67   External_linkage
68 | Link_once_linkage
69 | Weak_linkage
70 | Appending_linkage
71 | Internal_linkage
72 | Dllimport_linkage
73 | Dllexport_linkage
74 | External_weak_linkage
75 | Ghost_linkage
76
77 (** The linker visibility of a global value, accessed with [visibility gv] and
78     [set_visibility v gv]. See [llvm::GlobalValue::VisibilityTypes]. **)
79 type visibility =
80   Default_visibility
81 | Hidden_visibility
82 | Protected_visibility
83
84 (* The following calling convention values may be accessed with
85    [function_call_conv f] and [set_function_call_conv conv f]. Calling
86    conventions are open-ended. *)
87 val ccc : int             (** [ccc] is the C calling convention. **)
88 val fastcc : int          (** [fastcc] is the calling convention to allow LLVM
89                               maximum optimization opportunities. Use only with
90                               internal linkage. **)
91 val coldcc : int          (** [coldcc] is the calling convention for
92                               callee-save. **)
93 val x86_stdcallcc : int   (** [x86_stdcallcc] is the familiar stdcall calling
94                               convention from C. **)
95 val x86_fastcallcc : int  (** [x86_fastcallcc] is the familiar fastcall calling
96                               convention from C. **)
97
98 (** The predicate for an integer comparison ([icmp]) instruction.
99     See the [llvm::ICmpInst::Predicate] enumeration. **)
100 type int_predicate =
101   Icmp_eq
102 | Icmp_ne
103 | Icmp_ugt
104 | Icmp_uge
105 | Icmp_ult
106 | Icmp_ule
107 | Icmp_sgt
108 | Icmp_sge
109 | Icmp_slt
110 | Icmp_sle
111
112 (** The predicate for a floating-point comparison ([fcmp]) instruction.
113     See the [llvm::FCmpInst::Predicate] enumeration. **)
114 type real_predicate =
115   Fcmp_false
116 | Fcmp_oeq
117 | Fcmp_ogt
118 | Fcmp_oge
119 | Fcmp_olt
120 | Fcmp_ole
121 | Fcmp_one
122 | Fcmp_ord
123 | Fcmp_uno
124 | Fcmp_ueq
125 | Fcmp_ugt
126 | Fcmp_uge
127 | Fcmp_ult
128 | Fcmp_ule
129 | Fcmp_une
130 | Fcmp_true
131
132
133 (*===-- Modules -----------------------------------------------------------===*)
134
135 (** [create_module id] creates a module with the supplied module ID. Modules are
136     not garbage collected; it is mandatory to call [dispose_module m] to free
137     memory. See the constructor [llvm::Module::Module]. *)
138 external create_module : string -> llmodule = "llvm_create_module"
139
140 (** [dispose_module m] destroys a module [m] and all of the IR objects it
141     contained. All references to subordinate objects are invalidated;
142     referencing them will invoke undefined behavior. See the destructor
143     [llvm::Module::~Module]. **)
144 external dispose_module : llmodule -> unit = "llvm_dispose_module"
145
146 (** [define_type_name name ty m] adds a named type to the module's symbol table.
147     Returns [true] if successful. If such a name already exists, then no entry
148     is added and [false] is returned. See the [llvm::Module::addTypeName]
149     method. **)
150 external define_type_name : string -> lltype -> llmodule -> bool
151                           = "llvm_add_type_name"
152
153 (** [delete_type_name name] removes a type name from the module's symbol
154     table. *)
155 external delete_type_name : string -> llmodule -> unit
156                           = "llvm_delete_type_name"
157
158
159 (*===-- Types -------------------------------------------------------------===*)
160
161 (** [classify_type ty] returns the [type_kind] corresponding to the type [ty].
162     See the method [llvm::Type::getTypeID]. **)
163 external classify_type : lltype -> type_kind = "llvm_classify_type"
164
165 (** [string_of_lltype ty] returns a string describing the type [ty]. **)
166 val string_of_lltype : lltype -> string
167
168 (*--... Operations on integer types ........................................--*)
169
170 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. **)
171 val i1_type : lltype 
172
173 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. **)
174 val i8_type : lltype 
175
176 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. **)
177 val i16_type : lltype
178
179 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. **)
180 val i32_type : lltype
181
182 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. **)
183 val i64_type : lltype
184
185 (** [integer_type n] returns an integer type of bitwidth [n].
186     See the method [llvm::IntegerType::get]. **)
187 external integer_type : int -> lltype = "llvm_integer_type"
188
189 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty]..
190     See the method [llvm::IntegerType::getBitWidth]. **)
191 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
192
193 (*--... Operations on real types ...........................................--*)
194
195 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. **)
196 val float_type : lltype
197
198 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. **)
199 val double_type : lltype
200
201 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. **)
202 val x86fp80_type : lltype
203
204 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. **)
205 val fp128_type : lltype
206
207 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. **)
208 val ppc_fp128_type : lltype
209
210 (*--... Operations on function types .......................................--*)
211
212 (** [function_type ret_ty param_tys] returns the function type returning
213     [ret_ty] and taking [param_tys] as parameters.
214     See the method [llvm::FunctionType::get]. **)
215 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
216
217 (** [va_arg_function_type ret_ty param_tys] is just like
218     [function_type ret_ty param_tys] except that it returns the function type
219     which also takes a variable number of arguments.
220     See the method [llvm::FunctionType::get]. **)
221 external var_arg_function_type : lltype -> lltype array -> lltype
222                                = "llvm_var_arg_function_type"
223
224 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
225     otherwise. See the method [llvm::FunctionType::isVarArg]. **)
226 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
227
228 (** [return_type fty] gets the return type of the function type [fty].
229     See the method [llvm::FunctionType::getReturnType]. **)
230 external return_type : lltype -> lltype = "LLVMGetReturnType"
231
232 (** [param_types fty] gets the parameter types of the function type [fty].
233     See the method [llvm::FunctionType::getParamType]. **)
234 external param_types : lltype -> lltype array = "llvm_param_types"
235
236 (*--... Operations on struct types .........................................--*)
237
238 (** [struct_type tys] returns the structure type containing in the types in the
239     array [tys]. See the method [llvm::StructType::get]. **)
240 external struct_type : lltype array -> lltype = "llvm_struct_type"
241
242 (** [struct_type tys] returns the packed structure type containing in the types
243     in the array [tys]. See the method [llvm::StructType::get]. **)
244 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
245
246 (** [element_types sty] returns the constituent types of the struct type [sty].
247     See the method [llvm::StructType::getElementType]. **)
248 external element_types : lltype -> lltype array = "llvm_element_types"
249
250 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
251     [false] otherwise. See the method [llvm::StructType::isPacked]. **)
252 external is_packed : lltype -> bool = "llvm_is_packed"
253
254 (*--... Operations on pointer, vector, and array types .....................--*)
255
256 (** [array_type ty n] returns the array type containing [n] elements of type
257     [ty]. See the method [llvm::ArrayType::get]. **)
258 external array_type : lltype -> int -> lltype = "llvm_array_type"
259
260 (** [pointer_type ty] returns the pointer type referencing objects of type
261     [ty]. See the method [llvm::PointerType::get]. **)
262 external pointer_type : lltype -> lltype = "LLVMPointerType"
263
264 (** [vector_type ty n] returns the array type containing [n] elements of the
265     primitive type [ty]. See the method [llvm::ArrayType::get]. **)
266 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
267
268 (** [element_type ty] returns the element type of the pointer, vector, or array
269     type [ty]. See the method [llvm::SequentialType::get]. **)
270 external element_type : lltype -> lltype = "LLVMGetElementType"
271
272 (** [element_type aty] returns the element count of the array type [aty].
273     See the method [llvm::ArrayType::getNumElements]. **)
274 external array_length : lltype -> int = "llvm_array_length"
275
276 (** [element_type ty] returns the element count of the vector type [ty].
277     See the method [llvm::VectorType::getNumElements]. **)
278 external vector_size : lltype -> int = "llvm_vector_size"
279
280 (*--... Operations on other types ..........................................--*)
281
282 (** [opaque_type ()] creates a new opaque type distinct from any other.
283     Opaque types are useful for building recursive types in combination with
284     [refine_type opaque_ty ty].
285     See [llvm::OpaqueType::get]. **)
286 external opaque_type : unit -> lltype = "llvm_opaque_type"
287
288 (** [void_type] is the type of a function which does not return any value.
289     See [llvm::Type::VoidTy]. **)
290 val void_type : lltype
291
292 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. **)
293 val label_type : lltype
294
295 (*--... Operations on type handles .........................................--*)
296
297 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
298     refined as a result of a call to [refine_type], the handle will be updated;
299     any bare [lltype] references will become invalid.
300     See the class [llvm::PATypeHolder]. **)
301 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
302
303 (** [type_of_handle tyh] resolves the type handle [tyh].
304     See the method [llvm::PATypeHolder::get()]. **)
305 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
306
307 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
308     concrete type [ty] in all users. Warning: This may invalidate [lltype]
309     values! Use [lltypehandle] to manipulate potentially abstract types. See the
310     method [llvm::Type::refineAbstractType]. **)
311 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
312
313
314 (*===-- Values ------------------------------------------------------------===*)
315
316 (** [type_of v] returns the type of the value [v].
317     See the method [llvm::Value::getType]. **)
318 external type_of : llvalue -> lltype = "llvm_type_of"
319
320 (** [value_name v] returns the name of the value [v]. For global values, this is
321     the symbol name. For instructions and basic blocks, it is the SSA register
322     name. It is meaningless for constants.
323     See the method [llvm::Value::getName]. **)
324 external value_name : llvalue -> string = "llvm_value_name"
325
326 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method 
327     [llvm::Value::setName]. **)
328 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
329
330 (** [dump_value v] prints the .ll representation of the value [v] to standard
331     error. See the method [llvm::Value::dump]. **)
332 external dump_value : llvalue -> unit = "llvm_dump_value"
333
334 (*--... Operations on constants of (mostly) any type .......................--*)
335
336 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
337     otherwise. Similar to [llvm::isa<Constant>]. **)
338 external is_constant : llvalue -> bool = "llvm_is_constant"
339
340 (** [const_null ty] returns the constant null (zero) of the type [ty].
341     See the method [llvm::Constant::getNullValue]. **)
342 external const_null : lltype -> llvalue = "LLVMConstNull"
343
344 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
345     [ty]. See the method [llvm::Constant::getAllOnesValue]. **)
346 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
347
348 (** [undef ty] returns the undefined value of the type [ty].
349     See the method [llvm::UndefValue::get]. **)
350 external undef : lltype -> llvalue = "LLVMGetUndef"
351
352 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
353     See the method [llvm::Constant::isNullValue]. **)
354 external is_null : llvalue -> bool = "llvm_is_null"
355
356 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
357     otherwise. Similar to [llvm::isa<UndefValue>]. **)
358 external is_undef : llvalue -> bool = "llvm_is_undef"
359
360 (*--... Operations on scalar constants .....................................--*)
361
362 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
363     See the method [llvm::ConstantInt::get]. **)
364 external const_int : lltype -> int -> llvalue = "llvm_const_int"
365
366 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
367     [i]. See the method [llvm::ConstantInt::get]. **)
368 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
369                         = "llvm_const_of_int64"
370
371 (** [const_float ty n] returns the floating point constant of type [ty] and
372     value [n]. See the method [llvm::ConstantInt::get]. **)
373 external const_float : lltype -> float -> llvalue = "llvm_const_float"
374
375 (*--... Operations on composite constants ..................................--*)
376
377 (** [const_string s] returns the constant [i8] array with the values of the
378     characters in the string [s]. The array is not null-terminated (but see
379     [const_stringz]). This value can in turn be used as the initializer for a
380     global variable. See the method [llvm::ConstantArray::get]. **)
381 external const_string : string -> llvalue = "llvm_const_string"
382
383 (** [const_stringz s] returns the constant [i8] array with the values of the
384     characters in the string [s] and a null terminator. This value can in turn
385     be used as the initializer for a global variable.
386     See the method [llvm::ConstantArray::get]. **)
387 external const_stringz : string -> llvalue = "llvm_const_stringz"
388
389 (** [const_array ty elts] returns the constant array of type
390     [array_type ty (Array.length elts)] and containing the values [elts].
391     This value can in turn be used as the initializer for a global variable.
392     See the method [llvm::ConstantArray::get]. **)
393 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
394
395 (** [const_struct elts] returns the structured constant of type
396     [struct_type (Array.map type_of elts)] and containing the values [elts].
397     This value can in turn be used as the initializer for a global variable.
398     See the method [llvm::ConstantStruct::get]. **)
399 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
400
401 (** [const_packed_struct elts] returns the structured constant of type
402     [packed_struct_type (Array.map type_of elts)] and containing the values
403     [elts]. This value can in turn be used as the initializer for a global
404     variable. See the method [llvm::ConstantStruct::get]. **)
405 external const_packed_struct : llvalue array -> llvalue
406                              = "llvm_const_packed_struct"
407
408 (** [const_vector elts] returns the vector constant of type
409     [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
410     values [elts]. See the method [llvm::ConstantVector::get]. **)
411 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
412
413 (*--... Constant expressions ...............................................--*)
414
415 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
416     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
417     (const_int i64_type 1)) i64_type], but considerably more readable.
418     See the method [llvm::ConstantExpr::getSizeOf]. **)
419 external size_of : lltype -> llvalue = "LLVMSizeOf"
420
421 (** [const_neg c] returns the arithmetic negation of the constant [c].
422     See the method [llvm::ConstantExpr::getNeg]. **)
423 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
424
425 (** [const_not c] returns the bitwise inverse of the constant [c].
426     See the method [llvm::ConstantExpr::getNot]. **)
427 external const_not : llvalue -> llvalue = "LLVMConstNot"
428
429 (** [const_add c1 c2] returns the constant sum of two constants.
430     See the method [llvm::ConstantExpr::getAdd]. **)
431 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
432
433 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
434     constants. See the method [llvm::ConstantExpr::getSub]. **)
435 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
436
437 (** [const_mul c1 c2] returns the constant product of two constants.
438     See the method [llvm::ConstantExpr::getMul]. **)
439 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
440
441 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
442     integer constants.
443     See the method [llvm::ConstantExpr::getUDiv]. **)
444 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
445
446 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
447     integer constants.
448     See the method [llvm::ConstantExpr::]. **)
449 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
450
451 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
452     point constants.
453     See the method [llvm::ConstantExpr::getFDiv]. **)
454 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
455
456 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
457     unsigned integer constants.
458     See the method [llvm::ConstantExpr::getURem]. **)
459 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
460
461 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
462     signed integer constants.
463     See the method [llvm::ConstantExpr::getSRem]. **)
464 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
465
466 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
467     signed floating point constants.
468     See the method [llvm::ConstantExpr::getFRem]. **)
469 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
470
471 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
472     constants.
473     See the method [llvm::ConstantExpr::getAnd]. **)
474 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
475
476 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
477     constants.
478     See the method [llvm::ConstantExpr::getOr]. **)
479 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
480
481 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
482     constants.
483     See the method [llvm::ConstantExpr::getXor]. **)
484 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
485
486 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
487     constants, [c1 pred c2].
488     See the method [llvm::ConstantExpr::getICmp]. **)
489 external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
490                     = "llvm_const_icmp"
491
492 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
493     point constants, [c1 pred c2].
494     See the method [llvm::ConstantExpr::getFCmp]. **)
495 external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
496                     = "llvm_const_fcmp"
497
498 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
499     constant integer [c2].
500     See the method [llvm::ConstantExpr::getShl]. **)
501 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
502
503 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
504     constant integer [c2] with zero extension.
505     See the method [llvm::ConstantExpr::getLShr]. **)
506 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
507
508 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
509     constant integer [c2] with sign extension.
510     See the method [llvm::ConstantExpr::getAShr]. **)
511 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
512
513 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
514     constant integers indices from the array [indices].
515     See the method [llvm::ConstantExpr::getGetElementPtr]. **)
516 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
517
518 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
519     to the smaller integer type [ty].
520     See the method [llvm::ConstantExpr::getTrunc]. **)
521 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
522
523 (** [const_sext c ty] returns the constant sign extension of integer constant
524     [c] to the larger integer type [ty].
525     See the method [llvm::ConstantExpr::getSExt]. **)
526 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
527
528 (** [const_zext c ty] returns the constant zero extension of integer constant
529     [c] to the larger integer type [ty].
530     See the method [llvm::ConstantExpr::getZExt]. **)
531 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
532
533 (** [const_fptrunc c ty] returns the constant truncation of floating point
534     constant [c] to the smaller floating point type [ty].
535     See the method [llvm::ConstantExpr::getFPTrunc]. **)
536 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
537
538 (** [const_fpext c ty] returns the constant extension of floating point constant
539     [c] to the larger floating point type [ty].
540     See the method [llvm::ConstantExpr::getFPExt]. **)
541 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
542
543 (** [const_uitofp c ty] returns the constant floating point conversion of
544     unsigned integer constant [c] to the floating point type [ty].
545     See the method [llvm::ConstantExpr::getUIToFP]. **)
546 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
547
548 (** [const_sitofp c ty] returns the constant floating point conversion of
549     signed integer constant [c] to the floating point type [ty].
550     See the method [llvm::ConstantExpr::getSIToFP]. **)
551 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
552
553 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
554     floating point constant [c] to integer type [ty].
555     See the method [llvm::ConstantExpr::getFPToUI]. **)
556 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
557
558 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
559     floating point constant [c] to integer type [ty].
560     See the method [llvm::ConstantExpr::getFPToSI]. **)
561 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
562
563 (** [const_ptrtoint c ty] returns the constant integer conversion of
564     pointer constant [c] to integer type [ty].
565     See the method [llvm::ConstantExpr::getPtrToInt]. **)
566 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
567
568 (** [const_inttoptr c ty] returns the constant pointer conversion of
569     integer constant [c] to pointer type [ty].
570     See the method [llvm::ConstantExpr::getIntToPtr]. **)
571 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
572
573 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
574     to type [ty] of equal size.
575     See the method [llvm::ConstantExpr::getBitCast]. **)
576 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
577
578 (** [const_select cond t f] returns the constant conditional which returns value
579     [t] if the boolean constant [cond] is true and the value [f] otherwise.
580     See the method [llvm::ConstantExpr::getSelect]. **)
581 external const_select : llvalue -> llvalue -> llvalue -> llvalue
582                       = "LLVMConstSelect"
583
584 (** [const_extractelement vec i] returns the constant [i]th element of
585     constant vector [vec]. [i] must be a constant [i32] value unsigned less than
586     the size of the vector.
587     See the method [llvm::ConstantExpr::getExtractElement]. **)
588 external const_extractelement : llvalue -> llvalue -> llvalue
589                               = "LLVMConstExtractElement"
590
591 (** [const_insertelement vec v i] returns the constant vector with the same
592     elements as constant vector [v] but the [i]th element replaced by the
593     constant [v]. [v] must be a constant value with the type of the vector
594     elements. [i] must be a constant [i32] value unsigned less than the size
595     of the vector.
596     See the method [llvm::ConstantExpr::getInsertElement]. **)
597 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
598                              = "LLVMConstInsertElement"
599
600 (** [const_shufflevector a b mask] returns a constant [shufflevector].
601     See the LLVM Language Reference for details on the [sufflevector]
602     instruction.
603     See the method [llvm::ConstantExpr::getShuffleVector]. **)
604 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
605                              = "LLVMConstShuffleVector"
606
607 (*--... Operations on global variables, functions, and aliases (globals) ...--*)
608
609 (** [is_declaration g] returns [true] if the global value [g] is a declaration
610     only. Returns [false] otherwise.
611     See the method [llvm::GlobalValue::isDeclaration]. **)
612 external is_declaration : llvalue -> bool = "llvm_is_declaration"
613
614 (** [linkage g] returns the linkage of the global value [g].
615     See the method [llvm::GlobalValue::getLinkage]. **)
616 external linkage : llvalue -> linkage = "llvm_linkage"
617
618 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
619     See the method [llvm::GlobalValue::setLinkage]. **)
620 external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
621
622 (** [section g] returns the linker section of the global value [g].
623     See the method [llvm::GlobalValue::getSection]. **)
624 external section : llvalue -> string = "llvm_section"
625
626 (** [set_section s g] sets the linker section of the global value [g] to [s].
627     See the method [llvm::GlobalValue::setSection]. **)
628 external set_section : string -> llvalue -> unit = "llvm_set_section"
629
630 (** [visibility g] returns the linker visibility of the global value [g].
631     See the method [llvm::GlobalValue::getVisibility]. **)
632 external visibility : llvalue -> visibility = "llvm_visibility"
633
634 (** [set_visibility v g] sets the linker visibility of the global value [g] to
635     [v]. See the method [llvm::GlobalValue::setVisibility]. **)
636 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
637
638 (** [alignment g] returns the required alignment of the global value [g].
639     See the method [llvm::GlobalValue::getAlignment]. **)
640 external alignment : llvalue -> int = "llvm_alignment"
641
642 (** [set_alignment n g] sets the required alignment of the global value [g] to
643     [n] bytes. See the method [llvm::GlobalValue::setAlignment]. **)
644 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
645
646 (*--... Operations on global variables .....................................--*)
647
648 (** [declare_global ty name m] returns a new global variable of type [ty] and
649     with name [name] in module [m]. If such a global variable already exists,
650     it is returned. If the type of the existing global differs, then a bitcast
651     to [ty] is returned. **)
652 external declare_global : lltype -> string -> llmodule -> llvalue
653                         = "llvm_declare_global"
654
655 (** [define_global name init m] returns a new global with name [name] and
656     initializer [init] in module [m]. If the named global already exists, it is
657     renamed.
658     See the constructor of [llvm::GlobalVariable]. **)
659 external define_global : string -> llvalue -> llmodule -> llvalue
660                        = "llvm_define_global"
661
662 (** [lookup_global name m] returns [Some g] if a global variable with name
663     [name] exists in module [m]. If no such global exists, returns [None].
664     See the [llvm::GlobalVariable] constructor. **)
665 external lookup_global : string -> llmodule -> llvalue option
666                        = "llvm_lookup_global"
667
668 (** [delete_global gv] destroys the global variable [gv].
669     See the method [llvm::GlobalVariable::eraseFromParent]. **)
670 external delete_global : llvalue -> unit = "llvm_delete_global"
671
672 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
673     constant. Returns [false] otherwise.
674     See the method [llvm::GlobalVariable::isConstant]. **)
675 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
676
677 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
678     [c] is [true] and not if [c] is [false].
679     See the method [llvm::GlobalVariable::setConstant]. **)
680 external set_global_constant : bool -> llvalue -> unit
681                              = "llvm_set_global_constant"
682
683 (** [has_initializer gv] returns [true] if the global variable [gv] has an
684     initializer and [false] otherwise.
685     See the method [llvm::GlobalVariable::hasInitializer]. **)
686 external has_initializer : llvalue -> bool = "llvm_has_initializer"
687
688 (** [global_initializer gv] returns the initializer for the global variable
689     [gv]. See the method [llvm::GlobalVariable::getInitializer]. **)
690 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
691
692 (** [set_initializer c gv] sets the initializer for the global variable
693     [gv] to the constant [c].
694     See the method [llvm::GlobalVariable::setInitializer]. **)
695 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
696
697 (** [remove_initializer gv] unsets the initializer for the global variable
698     [gv].
699     See the method [llvm::GlobalVariable::setInitializer]. **)
700 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
701
702 (** [is_thread_local gv] returns [true] if the global variable [gv] is
703     thread-local and [false] otherwise.
704     See the method [llvm::GlobalVariable::isThreadLocal]. **)
705 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
706
707 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
708     [c] is [true] and not otherwise.
709     See the method [llvm::GlobalVariable::setThreadLocal]. **)
710 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
711
712 (*--... Operations on functions ............................................--*)
713
714 (** [declare_function name ty m] returns a new function of type [ty] and
715     with name [name] in module [m]. If such a function already exists,
716     it is returned. If the type of the existing function differs, then a bitcast
717     to [ty] is returned. **)
718 external declare_function : string -> lltype -> llmodule -> llvalue
719                           = "llvm_declare_function"
720
721 (** [define_function name ty m] creates a new function with name [name] and
722     type [ty] in module [m]. If the named function already exists, it is
723     renamed. An entry basic block is created in the function.
724     See the constructor of [llvm::GlobalVariable]. **)
725 external define_function : string -> lltype -> llmodule -> llvalue
726                          = "llvm_define_function"
727
728 (** [lookup_function name m] returns [Some f] if a function with name
729     [name] exists in module [m]. If no such function exists, returns [None].
730     See the method [llvm::Module] constructor. **)
731 external lookup_function : string -> llmodule -> llvalue option
732                          = "llvm_lookup_function"
733
734 (** [delete_function f] destroys the function [f].
735     See the method [llvm::Function::eraseFromParent]. **)
736 external delete_function : llvalue -> unit = "llvm_delete_function"
737
738 (** [params f] returns the parameters of function [f].
739     See the method [llvm::Function::getArgumentList]. **)
740 external params : llvalue -> llvalue array = "llvm_params"
741
742 (** [param f n] returns the [n]th parameter of function [f].
743     See the method [llvm::Function::getArgumentList]. **)
744 external param : llvalue -> int -> llvalue = "llvm_param"
745
746 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
747     See the method [llvm::Function::isIntrinsic]. **)
748 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
749
750 (** [function_call_conv f] returns the calling convention of the function [f].
751     See the method [llvm::Function::getCallingConv]. **)
752 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
753
754 (** [set_function_call_conv cc f] sets the calling convention of the function
755     [f] to the calling convention numbered [cc].
756     See the method [llvm::Function::setCallingConv]. **)
757 external set_function_call_conv : int -> llvalue -> unit
758                                 = "llvm_set_function_call_conv"
759
760 (** [collector f] returns [Some name] if the function [f] has a garbage
761     collection algorithm specified and [None] otherwise.
762     See the method [llvm::Function::getCollector]. **)
763 external collector : llvalue -> string option = "llvm_collector"
764
765 (** [set_collector gc f] sets the collection algorithm for the function [f] to
766     [gc]. See the method [llvm::Function::setCollector]. **)
767 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
768
769 (*--... Operations on basic blocks .........................................--*)
770
771 (** [basic_blocks fn] returns the basic blocks of the function [f].
772     See the method [llvm::Function::getBasicBlockList]. **)
773 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
774
775 (** [entry_block fn] returns the entry basic block of the function [f].
776     See the method [llvm::Function::getEntryBlock]. **)
777 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
778
779 (** [delete_block bb] deletes the basic block [bb].
780     See the method [llvm::BasicBlock::eraseFromParent]. **)
781 external delete_block : llbasicblock -> unit = "llvm_delete_block"
782
783 (** [append_block name f] creates a new basic block named [name] at the end of
784     function [f].
785     See the constructor of [llvm::BasicBlock]. **)
786 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
787
788 (** [insert_block name bb] creates a new basic block named [name] before the
789     basic block [bb].
790     See the constructor of [llvm::BasicBlock]. **)
791 external insert_block : string -> llbasicblock -> llbasicblock
792                       = "llvm_insert_block"
793
794 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. **)
795 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
796
797 (** [value_is_block v] returns [true] if the value [v] is a basic block and
798     [false] otherwise.
799     Similar to [llvm::isa<BasicBlock>]. **)
800 external value_is_block : llvalue -> bool = "llvm_value_is_block"
801
802 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. **)
803 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
804
805 (*--... Operations on phi nodes ............................................--*)
806
807 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
808     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. **)
809 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
810                       = "llvm_add_incoming"
811
812 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
813     See the method [llvm::PHINode::getIncomingValue]. **)
814 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
815
816
817 (*===-- Instruction builders ----------------------------------------------===*)
818
819 (** [builder_before ins] creates an instruction builder positioned before the
820     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. **)
821 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
822
823 (** [builder_at_end bb] creates an instruction builder positioned at the end of
824     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. **)
825 external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
826
827 (** [position_before ins b] moves the instruction builder [b] to before the
828     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
829 external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
830
831 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
832     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
833 external position_at_end : llbasicblock -> llbuilder -> unit
834                          = "llvm_position_at_end"
835
836 (*--... Terminators ........................................................--*)
837
838 (** [build_ret_void b] creates a
839     [ret void]
840     instruction at the position specified by the instruction builder [b].
841     See the method [llvm::LLVMBuilder::CreateRetVoid]. **)
842 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
843
844 (** [build_ret v b] creates a
845     [ret %v]
846     instruction at the position specified by the instruction builder [b].
847     See the method [llvm::LLVMBuilder::CreateRet]. **)
848 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
849
850 (** [build_br bb b] creates a
851     [b %bb]
852     instruction at the position specified by the instruction builder [b].
853     See the method [llvm::LLVMBuilder::CreateBr]. **)
854 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
855
856 (** [build_cond_br cond tbb fbb b] creates a
857     [b %cond, %tbb, %fbb]
858     instruction at the position specified by the instruction builder [b].
859     See the method [llvm::LLVMBuilder::CreateCondBr]. **)
860 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
861                          llvalue = "llvm_build_cond_br"
862
863 (** [build_switch case elsebb b] creates an empty
864     [switch %case, %elsebb]
865     instruction at the position specified by the instruction builder [b].
866     See the method [llvm::LLVMBuilder::CreateSwitch]. **)
867 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
868                       = "llvm_build_switch"
869
870 (** [build_invoke fn args tobb unwindbb name b] creates an
871     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
872     instruction at the position specified by the instruction builder [b].
873     See the method [llvm::LLVMBuilder::CreateInvoke]. **)
874 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
875                         llbasicblock -> string -> llbuilder -> llvalue
876                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
877
878 (** [build_unwind b] creates an
879     [unwind]
880     instruction at the position specified by the instruction builder [b].
881     See the method [llvm::LLVMBuilder::CreateUnwind]. **)
882 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
883
884 (** [build_unreachable b] creates an
885     [unreachable]
886     instruction at the position specified by the instruction builder [b].
887     See the method [llvm::LLVMBuilder::CreateUnwind]. **)
888 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
889
890 (*--... Arithmetic .........................................................--*)
891
892 (** [build_add x y name b] creates a
893     [%name = add %x, %y]
894     instruction at the position specified by the instruction builder [b].
895     See the method [llvm::LLVMBuilder::CreateAdd]. **)
896 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
897                    = "llvm_build_add"
898
899 (** [build_sub x y name b] creates a
900     [%name = sub %x, %y]
901     instruction at the position specified by the instruction builder [b].
902     See the method [llvm::LLVMBuilder::CreateSub]. **)
903 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
904                    = "llvm_build_sub"
905
906 (** [build_mul x y name b] creates a
907     [%name = mul %x, %y]
908     instruction at the position specified by the instruction builder [b].
909     See the method [llvm::LLVMBuilder::CreateMul]. **)
910 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
911                    = "llvm_build_mul"
912
913 (** [build_udiv x y name b] creates a
914     [%name = udiv %x, %y]
915     instruction at the position specified by the instruction builder [b].
916     See the method [llvm::LLVMBuilder::CreateUDiv]. **)
917 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
918                     = "llvm_build_udiv"
919
920 (** [build_sdiv x y name b] creates a
921     [%name = sdiv %x, %y]
922     instruction at the position specified by the instruction builder [b].
923     See the method [llvm::LLVMBuilder::CreateSDiv]. **)
924 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
925                     = "llvm_build_sdiv"
926
927 (** [build_fdiv x y name b] creates a
928     [%name = fdiv %x, %y]
929     instruction at the position specified by the instruction builder [b].
930     See the method [llvm::LLVMBuilder::CreateFDiv]. **)
931 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
932                     = "llvm_build_fdiv"
933
934 (** [build_urem x y name b] creates a
935     [%name = urem %x, %y]
936     instruction at the position specified by the instruction builder [b].
937     See the method [llvm::LLVMBuilder::CreateURem]. **)
938 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
939                     = "llvm_build_urem"
940
941 (** [build_SRem x y name b] creates a
942     [%name = srem %x, %y]
943     instruction at the position specified by the instruction builder [b].
944     See the method [llvm::LLVMBuilder::CreateSRem]. **)
945 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
946                     = "llvm_build_srem"
947
948 (** [build_frem x y name b] creates a
949     [%name = frem %x, %y]
950     instruction at the position specified by the instruction builder [b].
951     See the method [llvm::LLVMBuilder::CreateFRem]. **)
952 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
953                     = "llvm_build_frem"
954
955 (** [build_shl x y name b] creates a
956     [%name = shl %x, %y]
957     instruction at the position specified by the instruction builder [b].
958     See the method [llvm::LLVMBuilder::CreateShl]. **)
959 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
960                    = "llvm_build_shl"
961
962 (** [build_lshr x y name b] creates a
963     [%name = lshr %x, %y]
964     instruction at the position specified by the instruction builder [b].
965     See the method [llvm::LLVMBuilder::CreateLShr]. **)
966 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
967                     = "llvm_build_lshr"
968
969 (** [build_ashr x y name b] creates a
970     [%name = ashr %x, %y]
971     instruction at the position specified by the instruction builder [b].
972     See the method [llvm::LLVMBuilder::CreateAShr]. **)
973 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
974                     = "llvm_build_ashr"
975
976 (** [build_and x y name b] creates a
977     [%name = and %x, %y]
978     instruction at the position specified by the instruction builder [b].
979     See the method [llvm::LLVMBuilder::CreateAnd]. **)
980 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
981                    = "llvm_build_and"
982
983 (** [build_or x y name b] creates a
984     [%name = or %x, %y]
985     instruction at the position specified by the instruction builder [b].
986     See the method [llvm::LLVMBuilder::CreateOr]. **)
987 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
988                   = "llvm_build_or"
989
990 (** [build_xor x y name b] creates a
991     [%name = xor %x, %y]
992     instruction at the position specified by the instruction builder [b].
993     See the method [llvm::LLVMBuilder::CreateXor]. **)
994 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
995                    = "llvm_build_xor"
996
997 (** [build_neg x name b] creates a
998     [%name = sub 0, %x]
999     instruction at the position specified by the instruction builder [b].
1000     [-0.0] is used for floating point types to compute the correct sign.
1001     See the method [llvm::LLVMBuilder::CreateNeg]. **)
1002 external build_neg : llvalue -> string -> llbuilder -> llvalue
1003                    = "llvm_build_neg"
1004
1005 (** [build_xor x name b] creates a
1006     [%name = xor %x, -1]
1007     instruction at the position specified by the instruction builder [b].
1008     [-1] is the correct "all ones" value for the type of [x].
1009     See the method [llvm::LLVMBuilder::CreateXor]. **)
1010 external build_not : llvalue -> string -> llbuilder -> llvalue
1011                    = "llvm_build_not"
1012
1013 (*--... Memory .............................................................--*)
1014
1015 (** [build_malloc ty name b] creates a
1016     [%name = malloc %ty]
1017     instruction at the position specified by the instruction builder [b].
1018     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1019 external build_malloc : lltype -> string -> llbuilder -> llvalue
1020                       = "llvm_build_malloc"
1021
1022 (** [build_array_malloc ty n name b] creates a
1023     [%name = malloc %ty, %n]
1024     instruction at the position specified by the instruction builder [b].
1025     See the method [llvm::LLVMBuilder::CreateMalloc]. **)
1026 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1027                               llvalue = "llvm_build_array_malloc"
1028
1029 (** [build_alloca ty name b] creates a
1030     [%name = alloca %ty]
1031     instruction at the position specified by the instruction builder [b].
1032     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1033 external build_alloca : lltype -> string -> llbuilder -> llvalue
1034                       = "llvm_build_alloca"
1035
1036 (** [build_array_alloca ty n name b] creates a
1037     [%name = alloca %ty, %n]
1038     instruction at the position specified by the instruction builder [b].
1039     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1040 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1041                               llvalue = "llvm_build_array_alloca"
1042
1043 (** [build_free v b] creates a
1044     [free %v]
1045     instruction at the position specified by the instruction builder [b].
1046     See the method [llvm::LLVMBuilder::CreateFree]. **)
1047 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1048
1049 (** [build_load v name b] creates a
1050     [%name = load %v]
1051     instruction at the position specified by the instruction builder [b].
1052     See the method [llvm::LLVMBuilder::CreateLoad]. **)
1053 external build_load : llvalue -> string -> llbuilder -> llvalue
1054                     = "llvm_build_load"
1055
1056 (** [build_store v p b] creates a
1057     [store %v, %p]
1058     instruction at the position specified by the instruction builder [b].
1059     See the method [llvm::LLVMBuilder::CreateStore]. **)
1060 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1061                      = "llvm_build_store"
1062
1063 (** [build_store p indices name b] creates a
1064     [%name = gep %p, indices...]
1065     instruction at the position specified by the instruction builder [b].
1066     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. **)
1067 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1068                    = "llvm_build_gep"
1069
1070 (*--... Casts ..............................................................--*)
1071
1072 (** [build_trunc v ty name b] creates a
1073     [%name = trunc %p to %ty]
1074     instruction at the position specified by the instruction builder [b].
1075     See the method [llvm::LLVMBuilder::CreateTrunc]. **)
1076 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1077                      = "llvm_build_trunc"
1078
1079 (** [build_zext v ty name b] creates a
1080     [%name = zext %p to %ty]
1081     instruction at the position specified by the instruction builder [b].
1082     See the method [llvm::LLVMBuilder::CreateZExt]. **)
1083 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1084                     = "llvm_build_zext"
1085
1086 (** [build_sext v ty name b] creates a
1087     [%name = sext %p to %ty]
1088     instruction at the position specified by the instruction builder [b].
1089     See the method [llvm::LLVMBuilder::CreateSExt]. **)
1090 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1091                     = "llvm_build_sext"
1092
1093 (** [build_fptoui v ty name b] creates a
1094     [%name = fptoui %p to %ty]
1095     instruction at the position specified by the instruction builder [b].
1096     See the method [llvm::LLVMBuilder::CreateFPToUI]. **)
1097 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1098                       = "llvm_build_fptoui"
1099
1100 (** [build_fptosi v ty name b] creates a
1101     [%name = fptosi %p to %ty]
1102     instruction at the position specified by the instruction builder [b].
1103     See the method [llvm::LLVMBuilder::CreateFPToSI]. **)
1104 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1105                       = "llvm_build_fptosi"
1106
1107 (** [build_uitofp v ty name b] creates a
1108     [%name = uitofp %p to %ty]
1109     instruction at the position specified by the instruction builder [b].
1110     See the method [llvm::LLVMBuilder::CreateUIToFP]. **)
1111 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1112                       = "llvm_build_uitofp"
1113
1114 (** [build_sitofp v ty name b] creates a
1115     [%name = sitofp %p to %ty]
1116     instruction at the position specified by the instruction builder [b].
1117     See the method [llvm::LLVMBuilder::CreateSIToFP]. **)
1118 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1119                       = "llvm_build_sitofp"
1120
1121 (** [build_fptrunc v ty name b] creates a
1122     [%name = fptrunc %p to %ty]
1123     instruction at the position specified by the instruction builder [b].
1124     See the method [llvm::LLVMBuilder::CreateFPTrunc]. **)
1125 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1126                        = "llvm_build_fptrunc"
1127
1128 (** [build_fpext v ty name b] creates a
1129     [%name = fpext %p to %ty]
1130     instruction at the position specified by the instruction builder [b].
1131     See the method [llvm::LLVMBuilder::CreateFPExt]. **)
1132 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1133                      = "llvm_build_fpext"
1134
1135 (** [build_ptrtoint v ty name b] creates a
1136     [%name = prtotint %p to %ty]
1137     instruction at the position specified by the instruction builder [b].
1138     See the method [llvm::LLVMBuilder::CreatePtrToInt]. **)
1139 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1140                         = "llvm_build_prttoint"
1141
1142 (** [build_inttoptr v ty name b] creates a
1143     [%name = inttoptr %p to %ty]
1144     instruction at the position specified by the instruction builder [b].
1145     See the method [llvm::LLVMBuilder::CreateIntToPtr]. **)
1146 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1147                         = "llvm_build_inttoptr"
1148
1149 (** [build_bitcast v ty name b] creates a
1150     [%name = bitcast %p to %ty]
1151     instruction at the position specified by the instruction builder [b].
1152     See the method [llvm::LLVMBuilder::CreateBitcast]. **)
1153 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1154                        = "llvm_build_bitcast"
1155
1156 (*--... Comparisons ........................................................--*)
1157
1158 (** [build_icmp pred x y name b] creates a
1159     [%name = icmp %pred %x, %y]
1160     instruction at the position specified by the instruction builder [b].
1161     See the method [llvm::LLVMBuilder::CreateICmp]. **)
1162 external build_icmp : int_predicate -> llvalue -> llvalue -> string ->
1163                       llbuilder -> llvalue = "llvm_build_icmp"
1164
1165 (** [build_fcmp pred x y name b] creates a
1166     [%name = fcmp %pred %x, %y]
1167     instruction at the position specified by the instruction builder [b].
1168     See the method [llvm::LLVMBuilder::CreateFCmp]. **)
1169 external build_fcmp : real_predicate -> llvalue -> llvalue -> string ->
1170                       llbuilder -> llvalue = "llvm_build_fcmp"
1171
1172 (*--... Miscellaneous instructions .........................................--*)
1173
1174 (** [build_phi incoming name b] creates a
1175     [%name = phi %incoming]
1176     instruction at the position specified by the instruction builder [b].
1177     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1178     See the method [llvm::LLVMBuilder::CreatePHI]. **)
1179 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1180                      llvalue = "llvm_build_phi"
1181
1182 (** [build_call fn args name b] creates a
1183     [%name = call %fn(args...)]
1184     instruction at the position specified by the instruction builder [b].
1185     See the method [llvm::LLVMBuilder::CreateCall]. **)
1186 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1187                     = "llvm_build_call"
1188
1189 (** [build_select cond thenv elsev name b] creates a
1190     [%name = select %cond, %thenv, %elsev]
1191     instruction at the position specified by the instruction builder [b].
1192     See the method [llvm::LLVMBuilder::CreateSelect]. **)
1193 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1194                         llvalue = "llvm_build_select"
1195
1196 (** [build_va_arg valist argty name b] creates a
1197     [%name = va_arg %valist, %argty]
1198     instruction at the position specified by the instruction builder [b].
1199     See the method [llvm::LLVMBuilder::CreateVAArg]. **)
1200 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1201                       = "llvm_build_va_arg"
1202
1203 (** [build_extractelement vec i name b] creates a
1204     [%name = extractelement %vec, %i]
1205     instruction at the position specified by the instruction builder [b].
1206     See the method [llvm::LLVMBuilder::CreateExtractElement]. **)
1207 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1208                                 llvalue = "llvm_build_extractelement"
1209
1210 (** [build_insertelement vec elt i name b] creates a
1211     [%name = insertelement %vec, %elt, %i]
1212     instruction at the position specified by the instruction builder [b].
1213     See the method [llvm::LLVMBuilder::CreateInsertElement]. **)
1214 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1215                                llbuilder -> llvalue = "llvm_build_insertelement"
1216
1217 (** [build_shufflevector veca vecb mask name b] creates a
1218     [%name = shufflevector %veca, %vecb, %mask]
1219     instruction at the position specified by the instruction builder [b].
1220     See the method [llvm::LLVMBuilder::CreateShuffleVector]. **)
1221 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1222                                llbuilder -> llvalue = "llvm_build_shufflevector"
1223
1224
1225 (*===-- Module providers --------------------------------------------------===*)
1226
1227 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1228     ownership of the module. See the constructor 
1229     [llvm::ExistingModuleProvider::ExistingModuleProvider]. **)
1230 external create_module_provider : llmodule -> llmoduleprovider
1231                                 = "LLVMCreateModuleProviderForExistingModule"
1232
1233 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1234     the contained module. **)
1235 external dispose_module_provider : llmoduleprovider -> unit
1236                                  = "llvm_dispose_module_provider"