C and Ocaml bindings for address spaces, for that burgeoning market
[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] in the default address space (0).
262     See the method [llvm::PointerType::getUnqual]. **)
263 external pointer_type : lltype -> lltype = "llvm_pointer_type"
264
265 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
266     of type [ty] in address space [as].
267     See the method [llvm::PointerType::get]. **)
268 external qualified_pointer_type : lltype -> int -> lltype
269                                 = "llvm_qualified_pointer_type"
270
271 (** [vector_type ty n] returns the array type containing [n] elements of the
272     primitive type [ty]. See the method [llvm::ArrayType::get]. **)
273 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
274
275 (** [element_type ty] returns the element type of the pointer, vector, or array
276     type [ty]. See the method [llvm::SequentialType::get]. **)
277 external element_type : lltype -> lltype = "LLVMGetElementType"
278
279 (** [element_type aty] returns the element count of the array type [aty].
280     See the method [llvm::ArrayType::getNumElements]. **)
281 external array_length : lltype -> int = "llvm_array_length"
282
283 (** [address_space pty] returns the address space qualifier of the pointer type
284     [pty]. See the method [llvm::PointerType::getAddressSpace]. **)
285 external address_space : lltype -> int = "llvm_address_space"
286
287 (** [element_type ty] returns the element count of the vector type [ty].
288     See the method [llvm::VectorType::getNumElements]. **)
289 external vector_size : lltype -> int = "llvm_vector_size"
290
291 (*--... Operations on other types ..........................................--*)
292
293 (** [opaque_type ()] creates a new opaque type distinct from any other.
294     Opaque types are useful for building recursive types in combination with
295     [refine_type opaque_ty ty].
296     See [llvm::OpaqueType::get]. **)
297 external opaque_type : unit -> lltype = "llvm_opaque_type"
298
299 (** [void_type] is the type of a function which does not return any value.
300     See [llvm::Type::VoidTy]. **)
301 val void_type : lltype
302
303 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. **)
304 val label_type : lltype
305
306 (*--... Operations on type handles .........................................--*)
307
308 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
309     refined as a result of a call to [refine_type], the handle will be updated;
310     any bare [lltype] references will become invalid.
311     See the class [llvm::PATypeHolder]. **)
312 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
313
314 (** [type_of_handle tyh] resolves the type handle [tyh].
315     See the method [llvm::PATypeHolder::get()]. **)
316 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
317
318 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
319     concrete type [ty] in all users. Warning: This may invalidate [lltype]
320     values! Use [lltypehandle] to manipulate potentially abstract types. See the
321     method [llvm::Type::refineAbstractType]. **)
322 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
323
324
325 (*===-- Values ------------------------------------------------------------===*)
326
327 (** [type_of v] returns the type of the value [v].
328     See the method [llvm::Value::getType]. **)
329 external type_of : llvalue -> lltype = "llvm_type_of"
330
331 (** [value_name v] returns the name of the value [v]. For global values, this is
332     the symbol name. For instructions and basic blocks, it is the SSA register
333     name. It is meaningless for constants.
334     See the method [llvm::Value::getName]. **)
335 external value_name : llvalue -> string = "llvm_value_name"
336
337 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method 
338     [llvm::Value::setName]. **)
339 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
340
341 (** [dump_value v] prints the .ll representation of the value [v] to standard
342     error. See the method [llvm::Value::dump]. **)
343 external dump_value : llvalue -> unit = "llvm_dump_value"
344
345 (*--... Operations on constants of (mostly) any type .......................--*)
346
347 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
348     otherwise. Similar to [llvm::isa<Constant>]. **)
349 external is_constant : llvalue -> bool = "llvm_is_constant"
350
351 (** [const_null ty] returns the constant null (zero) of the type [ty].
352     See the method [llvm::Constant::getNullValue]. **)
353 external const_null : lltype -> llvalue = "LLVMConstNull"
354
355 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
356     [ty]. See the method [llvm::Constant::getAllOnesValue]. **)
357 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
358
359 (** [undef ty] returns the undefined value of the type [ty].
360     See the method [llvm::UndefValue::get]. **)
361 external undef : lltype -> llvalue = "LLVMGetUndef"
362
363 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
364     See the method [llvm::Constant::isNullValue]. **)
365 external is_null : llvalue -> bool = "llvm_is_null"
366
367 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
368     otherwise. Similar to [llvm::isa<UndefValue>]. **)
369 external is_undef : llvalue -> bool = "llvm_is_undef"
370
371 (*--... Operations on scalar constants .....................................--*)
372
373 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
374     See the method [llvm::ConstantInt::get]. **)
375 external const_int : lltype -> int -> llvalue = "llvm_const_int"
376
377 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
378     [i]. See the method [llvm::ConstantInt::get]. **)
379 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
380                         = "llvm_const_of_int64"
381
382 (** [const_float ty n] returns the floating point constant of type [ty] and
383     value [n]. See the method [llvm::ConstantInt::get]. **)
384 external const_float : lltype -> float -> llvalue = "llvm_const_float"
385
386 (*--... Operations on composite constants ..................................--*)
387
388 (** [const_string s] returns the constant [i8] array with the values of the
389     characters in the string [s]. The array is not null-terminated (but see
390     [const_stringz]). This value can in turn be used as the initializer for a
391     global variable. See the method [llvm::ConstantArray::get]. **)
392 external const_string : string -> llvalue = "llvm_const_string"
393
394 (** [const_stringz s] returns the constant [i8] array with the values of the
395     characters in the string [s] and a null terminator. This value can in turn
396     be used as the initializer for a global variable.
397     See the method [llvm::ConstantArray::get]. **)
398 external const_stringz : string -> llvalue = "llvm_const_stringz"
399
400 (** [const_array ty elts] returns the constant array of type
401     [array_type ty (Array.length elts)] and containing the values [elts].
402     This value can in turn be used as the initializer for a global variable.
403     See the method [llvm::ConstantArray::get]. **)
404 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
405
406 (** [const_struct elts] returns the structured constant of type
407     [struct_type (Array.map type_of elts)] and containing the values [elts].
408     This value can in turn be used as the initializer for a global variable.
409     See the method [llvm::ConstantStruct::get]. **)
410 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
411
412 (** [const_packed_struct elts] returns the structured constant of type
413     [packed_struct_type (Array.map type_of elts)] and containing the values
414     [elts]. This value can in turn be used as the initializer for a global
415     variable. See the method [llvm::ConstantStruct::get]. **)
416 external const_packed_struct : llvalue array -> llvalue
417                              = "llvm_const_packed_struct"
418
419 (** [const_vector elts] returns the vector constant of type
420     [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
421     values [elts]. See the method [llvm::ConstantVector::get]. **)
422 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
423
424 (*--... Constant expressions ...............................................--*)
425
426 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
427     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
428     (const_int i64_type 1)) i64_type], but considerably more readable.
429     See the method [llvm::ConstantExpr::getSizeOf]. **)
430 external size_of : lltype -> llvalue = "LLVMSizeOf"
431
432 (** [const_neg c] returns the arithmetic negation of the constant [c].
433     See the method [llvm::ConstantExpr::getNeg]. **)
434 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
435
436 (** [const_not c] returns the bitwise inverse of the constant [c].
437     See the method [llvm::ConstantExpr::getNot]. **)
438 external const_not : llvalue -> llvalue = "LLVMConstNot"
439
440 (** [const_add c1 c2] returns the constant sum of two constants.
441     See the method [llvm::ConstantExpr::getAdd]. **)
442 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
443
444 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
445     constants. See the method [llvm::ConstantExpr::getSub]. **)
446 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
447
448 (** [const_mul c1 c2] returns the constant product of two constants.
449     See the method [llvm::ConstantExpr::getMul]. **)
450 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
451
452 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
453     integer constants.
454     See the method [llvm::ConstantExpr::getUDiv]. **)
455 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
456
457 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
458     integer constants.
459     See the method [llvm::ConstantExpr::]. **)
460 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
461
462 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
463     point constants.
464     See the method [llvm::ConstantExpr::getFDiv]. **)
465 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
466
467 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
468     unsigned integer constants.
469     See the method [llvm::ConstantExpr::getURem]. **)
470 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
471
472 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
473     signed integer constants.
474     See the method [llvm::ConstantExpr::getSRem]. **)
475 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
476
477 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
478     signed floating point constants.
479     See the method [llvm::ConstantExpr::getFRem]. **)
480 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
481
482 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
483     constants.
484     See the method [llvm::ConstantExpr::getAnd]. **)
485 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
486
487 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
488     constants.
489     See the method [llvm::ConstantExpr::getOr]. **)
490 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
491
492 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
493     constants.
494     See the method [llvm::ConstantExpr::getXor]. **)
495 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
496
497 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
498     constants, [c1 pred c2].
499     See the method [llvm::ConstantExpr::getICmp]. **)
500 external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
501                     = "llvm_const_icmp"
502
503 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
504     point constants, [c1 pred c2].
505     See the method [llvm::ConstantExpr::getFCmp]. **)
506 external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
507                     = "llvm_const_fcmp"
508
509 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
510     constant integer [c2].
511     See the method [llvm::ConstantExpr::getShl]. **)
512 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
513
514 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
515     constant integer [c2] with zero extension.
516     See the method [llvm::ConstantExpr::getLShr]. **)
517 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
518
519 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
520     constant integer [c2] with sign extension.
521     See the method [llvm::ConstantExpr::getAShr]. **)
522 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
523
524 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
525     constant integers indices from the array [indices].
526     See the method [llvm::ConstantExpr::getGetElementPtr]. **)
527 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
528
529 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
530     to the smaller integer type [ty].
531     See the method [llvm::ConstantExpr::getTrunc]. **)
532 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
533
534 (** [const_sext c ty] returns the constant sign extension of integer constant
535     [c] to the larger integer type [ty].
536     See the method [llvm::ConstantExpr::getSExt]. **)
537 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
538
539 (** [const_zext c ty] returns the constant zero extension of integer constant
540     [c] to the larger integer type [ty].
541     See the method [llvm::ConstantExpr::getZExt]. **)
542 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
543
544 (** [const_fptrunc c ty] returns the constant truncation of floating point
545     constant [c] to the smaller floating point type [ty].
546     See the method [llvm::ConstantExpr::getFPTrunc]. **)
547 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
548
549 (** [const_fpext c ty] returns the constant extension of floating point constant
550     [c] to the larger floating point type [ty].
551     See the method [llvm::ConstantExpr::getFPExt]. **)
552 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
553
554 (** [const_uitofp c ty] returns the constant floating point conversion of
555     unsigned integer constant [c] to the floating point type [ty].
556     See the method [llvm::ConstantExpr::getUIToFP]. **)
557 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
558
559 (** [const_sitofp c ty] returns the constant floating point conversion of
560     signed integer constant [c] to the floating point type [ty].
561     See the method [llvm::ConstantExpr::getSIToFP]. **)
562 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
563
564 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
565     floating point constant [c] to integer type [ty].
566     See the method [llvm::ConstantExpr::getFPToUI]. **)
567 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
568
569 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
570     floating point constant [c] to integer type [ty].
571     See the method [llvm::ConstantExpr::getFPToSI]. **)
572 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
573
574 (** [const_ptrtoint c ty] returns the constant integer conversion of
575     pointer constant [c] to integer type [ty].
576     See the method [llvm::ConstantExpr::getPtrToInt]. **)
577 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
578
579 (** [const_inttoptr c ty] returns the constant pointer conversion of
580     integer constant [c] to pointer type [ty].
581     See the method [llvm::ConstantExpr::getIntToPtr]. **)
582 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
583
584 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
585     to type [ty] of equal size.
586     See the method [llvm::ConstantExpr::getBitCast]. **)
587 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
588
589 (** [const_select cond t f] returns the constant conditional which returns value
590     [t] if the boolean constant [cond] is true and the value [f] otherwise.
591     See the method [llvm::ConstantExpr::getSelect]. **)
592 external const_select : llvalue -> llvalue -> llvalue -> llvalue
593                       = "LLVMConstSelect"
594
595 (** [const_extractelement vec i] returns the constant [i]th element of
596     constant vector [vec]. [i] must be a constant [i32] value unsigned less than
597     the size of the vector.
598     See the method [llvm::ConstantExpr::getExtractElement]. **)
599 external const_extractelement : llvalue -> llvalue -> llvalue
600                               = "LLVMConstExtractElement"
601
602 (** [const_insertelement vec v i] returns the constant vector with the same
603     elements as constant vector [v] but the [i]th element replaced by the
604     constant [v]. [v] must be a constant value with the type of the vector
605     elements. [i] must be a constant [i32] value unsigned less than the size
606     of the vector.
607     See the method [llvm::ConstantExpr::getInsertElement]. **)
608 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
609                              = "LLVMConstInsertElement"
610
611 (** [const_shufflevector a b mask] returns a constant [shufflevector].
612     See the LLVM Language Reference for details on the [sufflevector]
613     instruction.
614     See the method [llvm::ConstantExpr::getShuffleVector]. **)
615 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
616                              = "LLVMConstShuffleVector"
617
618 (*--... Operations on global variables, functions, and aliases (globals) ...--*)
619
620 (** [is_declaration g] returns [true] if the global value [g] is a declaration
621     only. Returns [false] otherwise.
622     See the method [llvm::GlobalValue::isDeclaration]. **)
623 external is_declaration : llvalue -> bool = "llvm_is_declaration"
624
625 (** [linkage g] returns the linkage of the global value [g].
626     See the method [llvm::GlobalValue::getLinkage]. **)
627 external linkage : llvalue -> linkage = "llvm_linkage"
628
629 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
630     See the method [llvm::GlobalValue::setLinkage]. **)
631 external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
632
633 (** [section g] returns the linker section of the global value [g].
634     See the method [llvm::GlobalValue::getSection]. **)
635 external section : llvalue -> string = "llvm_section"
636
637 (** [set_section s g] sets the linker section of the global value [g] to [s].
638     See the method [llvm::GlobalValue::setSection]. **)
639 external set_section : string -> llvalue -> unit = "llvm_set_section"
640
641 (** [visibility g] returns the linker visibility of the global value [g].
642     See the method [llvm::GlobalValue::getVisibility]. **)
643 external visibility : llvalue -> visibility = "llvm_visibility"
644
645 (** [set_visibility v g] sets the linker visibility of the global value [g] to
646     [v]. See the method [llvm::GlobalValue::setVisibility]. **)
647 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
648
649 (** [alignment g] returns the required alignment of the global value [g].
650     See the method [llvm::GlobalValue::getAlignment]. **)
651 external alignment : llvalue -> int = "llvm_alignment"
652
653 (** [set_alignment n g] sets the required alignment of the global value [g] to
654     [n] bytes. See the method [llvm::GlobalValue::setAlignment]. **)
655 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
656
657 (*--... Operations on global variables .....................................--*)
658
659 (** [declare_global ty name m] returns a new global variable of type [ty] and
660     with name [name] in module [m]. If such a global variable already exists,
661     it is returned. If the type of the existing global differs, then a bitcast
662     to [ty] is returned. **)
663 external declare_global : lltype -> string -> llmodule -> llvalue
664                         = "llvm_declare_global"
665
666 (** [define_global name init m] returns a new global with name [name] and
667     initializer [init] in module [m]. If the named global already exists, it is
668     renamed.
669     See the constructor of [llvm::GlobalVariable]. **)
670 external define_global : string -> llvalue -> llmodule -> llvalue
671                        = "llvm_define_global"
672
673 (** [lookup_global name m] returns [Some g] if a global variable with name
674     [name] exists in module [m]. If no such global exists, returns [None].
675     See the [llvm::GlobalVariable] constructor. **)
676 external lookup_global : string -> llmodule -> llvalue option
677                        = "llvm_lookup_global"
678
679 (** [delete_global gv] destroys the global variable [gv].
680     See the method [llvm::GlobalVariable::eraseFromParent]. **)
681 external delete_global : llvalue -> unit = "llvm_delete_global"
682
683 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
684     constant. Returns [false] otherwise.
685     See the method [llvm::GlobalVariable::isConstant]. **)
686 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
687
688 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
689     [c] is [true] and not if [c] is [false].
690     See the method [llvm::GlobalVariable::setConstant]. **)
691 external set_global_constant : bool -> llvalue -> unit
692                              = "llvm_set_global_constant"
693
694 (** [has_initializer gv] returns [true] if the global variable [gv] has an
695     initializer and [false] otherwise.
696     See the method [llvm::GlobalVariable::hasInitializer]. **)
697 external has_initializer : llvalue -> bool = "llvm_has_initializer"
698
699 (** [global_initializer gv] returns the initializer for the global variable
700     [gv]. See the method [llvm::GlobalVariable::getInitializer]. **)
701 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
702
703 (** [set_initializer c gv] sets the initializer for the global variable
704     [gv] to the constant [c].
705     See the method [llvm::GlobalVariable::setInitializer]. **)
706 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
707
708 (** [remove_initializer gv] unsets the initializer for the global variable
709     [gv].
710     See the method [llvm::GlobalVariable::setInitializer]. **)
711 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
712
713 (** [is_thread_local gv] returns [true] if the global variable [gv] is
714     thread-local and [false] otherwise.
715     See the method [llvm::GlobalVariable::isThreadLocal]. **)
716 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
717
718 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
719     [c] is [true] and not otherwise.
720     See the method [llvm::GlobalVariable::setThreadLocal]. **)
721 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
722
723 (*--... Operations on functions ............................................--*)
724
725 (** [declare_function name ty m] returns a new function of type [ty] and
726     with name [name] in module [m]. If such a function already exists,
727     it is returned. If the type of the existing function differs, then a bitcast
728     to [ty] is returned. **)
729 external declare_function : string -> lltype -> llmodule -> llvalue
730                           = "llvm_declare_function"
731
732 (** [define_function name ty m] creates a new function with name [name] and
733     type [ty] in module [m]. If the named function already exists, it is
734     renamed. An entry basic block is created in the function.
735     See the constructor of [llvm::GlobalVariable]. **)
736 external define_function : string -> lltype -> llmodule -> llvalue
737                          = "llvm_define_function"
738
739 (** [lookup_function name m] returns [Some f] if a function with name
740     [name] exists in module [m]. If no such function exists, returns [None].
741     See the method [llvm::Module] constructor. **)
742 external lookup_function : string -> llmodule -> llvalue option
743                          = "llvm_lookup_function"
744
745 (** [delete_function f] destroys the function [f].
746     See the method [llvm::Function::eraseFromParent]. **)
747 external delete_function : llvalue -> unit = "llvm_delete_function"
748
749 (** [params f] returns the parameters of function [f].
750     See the method [llvm::Function::getArgumentList]. **)
751 external params : llvalue -> llvalue array = "llvm_params"
752
753 (** [param f n] returns the [n]th parameter of function [f].
754     See the method [llvm::Function::getArgumentList]. **)
755 external param : llvalue -> int -> llvalue = "llvm_param"
756
757 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
758     See the method [llvm::Function::isIntrinsic]. **)
759 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
760
761 (** [function_call_conv f] returns the calling convention of the function [f].
762     See the method [llvm::Function::getCallingConv]. **)
763 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
764
765 (** [set_function_call_conv cc f] sets the calling convention of the function
766     [f] to the calling convention numbered [cc].
767     See the method [llvm::Function::setCallingConv]. **)
768 external set_function_call_conv : int -> llvalue -> unit
769                                 = "llvm_set_function_call_conv"
770
771 (** [collector f] returns [Some name] if the function [f] has a garbage
772     collection algorithm specified and [None] otherwise.
773     See the method [llvm::Function::getCollector]. **)
774 external collector : llvalue -> string option = "llvm_collector"
775
776 (** [set_collector gc f] sets the collection algorithm for the function [f] to
777     [gc]. See the method [llvm::Function::setCollector]. **)
778 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
779
780 (*--... Operations on basic blocks .........................................--*)
781
782 (** [basic_blocks fn] returns the basic blocks of the function [f].
783     See the method [llvm::Function::getBasicBlockList]. **)
784 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
785
786 (** [entry_block fn] returns the entry basic block of the function [f].
787     See the method [llvm::Function::getEntryBlock]. **)
788 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
789
790 (** [delete_block bb] deletes the basic block [bb].
791     See the method [llvm::BasicBlock::eraseFromParent]. **)
792 external delete_block : llbasicblock -> unit = "llvm_delete_block"
793
794 (** [append_block name f] creates a new basic block named [name] at the end of
795     function [f].
796     See the constructor of [llvm::BasicBlock]. **)
797 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
798
799 (** [insert_block name bb] creates a new basic block named [name] before the
800     basic block [bb].
801     See the constructor of [llvm::BasicBlock]. **)
802 external insert_block : string -> llbasicblock -> llbasicblock
803                       = "llvm_insert_block"
804
805 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. **)
806 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
807
808 (** [value_is_block v] returns [true] if the value [v] is a basic block and
809     [false] otherwise.
810     Similar to [llvm::isa<BasicBlock>]. **)
811 external value_is_block : llvalue -> bool = "llvm_value_is_block"
812
813 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. **)
814 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
815
816 (*--... Operations on phi nodes ............................................--*)
817
818 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
819     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. **)
820 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
821                       = "llvm_add_incoming"
822
823 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
824     See the method [llvm::PHINode::getIncomingValue]. **)
825 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
826
827
828 (*===-- Instruction builders ----------------------------------------------===*)
829
830 (** [builder_before ins] creates an instruction builder positioned before the
831     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. **)
832 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
833
834 (** [builder_at_end bb] creates an instruction builder positioned at the end of
835     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. **)
836 external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
837
838 (** [position_before ins b] moves the instruction builder [b] to before the
839     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
840 external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
841
842 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
843     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
844 external position_at_end : llbasicblock -> llbuilder -> unit
845                          = "llvm_position_at_end"
846
847 (*--... Terminators ........................................................--*)
848
849 (** [build_ret_void b] creates a
850     [ret void]
851     instruction at the position specified by the instruction builder [b].
852     See the method [llvm::LLVMBuilder::CreateRetVoid]. **)
853 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
854
855 (** [build_ret v b] creates a
856     [ret %v]
857     instruction at the position specified by the instruction builder [b].
858     See the method [llvm::LLVMBuilder::CreateRet]. **)
859 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
860
861 (** [build_br bb b] creates a
862     [b %bb]
863     instruction at the position specified by the instruction builder [b].
864     See the method [llvm::LLVMBuilder::CreateBr]. **)
865 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
866
867 (** [build_cond_br cond tbb fbb b] creates a
868     [b %cond, %tbb, %fbb]
869     instruction at the position specified by the instruction builder [b].
870     See the method [llvm::LLVMBuilder::CreateCondBr]. **)
871 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
872                          llvalue = "llvm_build_cond_br"
873
874 (** [build_switch case elsebb b] creates an empty
875     [switch %case, %elsebb]
876     instruction at the position specified by the instruction builder [b].
877     See the method [llvm::LLVMBuilder::CreateSwitch]. **)
878 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
879                       = "llvm_build_switch"
880
881 (** [build_invoke fn args tobb unwindbb name b] creates an
882     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
883     instruction at the position specified by the instruction builder [b].
884     See the method [llvm::LLVMBuilder::CreateInvoke]. **)
885 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
886                         llbasicblock -> string -> llbuilder -> llvalue
887                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
888
889 (** [build_unwind b] creates an
890     [unwind]
891     instruction at the position specified by the instruction builder [b].
892     See the method [llvm::LLVMBuilder::CreateUnwind]. **)
893 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
894
895 (** [build_unreachable b] creates an
896     [unreachable]
897     instruction at the position specified by the instruction builder [b].
898     See the method [llvm::LLVMBuilder::CreateUnwind]. **)
899 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
900
901 (*--... Arithmetic .........................................................--*)
902
903 (** [build_add x y name b] creates a
904     [%name = add %x, %y]
905     instruction at the position specified by the instruction builder [b].
906     See the method [llvm::LLVMBuilder::CreateAdd]. **)
907 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
908                    = "llvm_build_add"
909
910 (** [build_sub x y name b] creates a
911     [%name = sub %x, %y]
912     instruction at the position specified by the instruction builder [b].
913     See the method [llvm::LLVMBuilder::CreateSub]. **)
914 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
915                    = "llvm_build_sub"
916
917 (** [build_mul x y name b] creates a
918     [%name = mul %x, %y]
919     instruction at the position specified by the instruction builder [b].
920     See the method [llvm::LLVMBuilder::CreateMul]. **)
921 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
922                    = "llvm_build_mul"
923
924 (** [build_udiv x y name b] creates a
925     [%name = udiv %x, %y]
926     instruction at the position specified by the instruction builder [b].
927     See the method [llvm::LLVMBuilder::CreateUDiv]. **)
928 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
929                     = "llvm_build_udiv"
930
931 (** [build_sdiv x y name b] creates a
932     [%name = sdiv %x, %y]
933     instruction at the position specified by the instruction builder [b].
934     See the method [llvm::LLVMBuilder::CreateSDiv]. **)
935 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
936                     = "llvm_build_sdiv"
937
938 (** [build_fdiv x y name b] creates a
939     [%name = fdiv %x, %y]
940     instruction at the position specified by the instruction builder [b].
941     See the method [llvm::LLVMBuilder::CreateFDiv]. **)
942 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
943                     = "llvm_build_fdiv"
944
945 (** [build_urem x y name b] creates a
946     [%name = urem %x, %y]
947     instruction at the position specified by the instruction builder [b].
948     See the method [llvm::LLVMBuilder::CreateURem]. **)
949 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
950                     = "llvm_build_urem"
951
952 (** [build_SRem x y name b] creates a
953     [%name = srem %x, %y]
954     instruction at the position specified by the instruction builder [b].
955     See the method [llvm::LLVMBuilder::CreateSRem]. **)
956 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
957                     = "llvm_build_srem"
958
959 (** [build_frem x y name b] creates a
960     [%name = frem %x, %y]
961     instruction at the position specified by the instruction builder [b].
962     See the method [llvm::LLVMBuilder::CreateFRem]. **)
963 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
964                     = "llvm_build_frem"
965
966 (** [build_shl x y name b] creates a
967     [%name = shl %x, %y]
968     instruction at the position specified by the instruction builder [b].
969     See the method [llvm::LLVMBuilder::CreateShl]. **)
970 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
971                    = "llvm_build_shl"
972
973 (** [build_lshr x y name b] creates a
974     [%name = lshr %x, %y]
975     instruction at the position specified by the instruction builder [b].
976     See the method [llvm::LLVMBuilder::CreateLShr]. **)
977 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
978                     = "llvm_build_lshr"
979
980 (** [build_ashr x y name b] creates a
981     [%name = ashr %x, %y]
982     instruction at the position specified by the instruction builder [b].
983     See the method [llvm::LLVMBuilder::CreateAShr]. **)
984 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
985                     = "llvm_build_ashr"
986
987 (** [build_and x y name b] creates a
988     [%name = and %x, %y]
989     instruction at the position specified by the instruction builder [b].
990     See the method [llvm::LLVMBuilder::CreateAnd]. **)
991 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
992                    = "llvm_build_and"
993
994 (** [build_or x y name b] creates a
995     [%name = or %x, %y]
996     instruction at the position specified by the instruction builder [b].
997     See the method [llvm::LLVMBuilder::CreateOr]. **)
998 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
999                   = "llvm_build_or"
1000
1001 (** [build_xor x y name b] creates a
1002     [%name = xor %x, %y]
1003     instruction at the position specified by the instruction builder [b].
1004     See the method [llvm::LLVMBuilder::CreateXor]. **)
1005 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1006                    = "llvm_build_xor"
1007
1008 (** [build_neg x name b] creates a
1009     [%name = sub 0, %x]
1010     instruction at the position specified by the instruction builder [b].
1011     [-0.0] is used for floating point types to compute the correct sign.
1012     See the method [llvm::LLVMBuilder::CreateNeg]. **)
1013 external build_neg : llvalue -> string -> llbuilder -> llvalue
1014                    = "llvm_build_neg"
1015
1016 (** [build_xor x name b] creates a
1017     [%name = xor %x, -1]
1018     instruction at the position specified by the instruction builder [b].
1019     [-1] is the correct "all ones" value for the type of [x].
1020     See the method [llvm::LLVMBuilder::CreateXor]. **)
1021 external build_not : llvalue -> string -> llbuilder -> llvalue
1022                    = "llvm_build_not"
1023
1024 (*--... Memory .............................................................--*)
1025
1026 (** [build_malloc ty name b] creates a
1027     [%name = malloc %ty]
1028     instruction at the position specified by the instruction builder [b].
1029     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1030 external build_malloc : lltype -> string -> llbuilder -> llvalue
1031                       = "llvm_build_malloc"
1032
1033 (** [build_array_malloc ty n name b] creates a
1034     [%name = malloc %ty, %n]
1035     instruction at the position specified by the instruction builder [b].
1036     See the method [llvm::LLVMBuilder::CreateMalloc]. **)
1037 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1038                               llvalue = "llvm_build_array_malloc"
1039
1040 (** [build_alloca ty name b] creates a
1041     [%name = alloca %ty]
1042     instruction at the position specified by the instruction builder [b].
1043     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1044 external build_alloca : lltype -> string -> llbuilder -> llvalue
1045                       = "llvm_build_alloca"
1046
1047 (** [build_array_alloca ty n name b] creates a
1048     [%name = alloca %ty, %n]
1049     instruction at the position specified by the instruction builder [b].
1050     See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1051 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1052                               llvalue = "llvm_build_array_alloca"
1053
1054 (** [build_free v b] creates a
1055     [free %v]
1056     instruction at the position specified by the instruction builder [b].
1057     See the method [llvm::LLVMBuilder::CreateFree]. **)
1058 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1059
1060 (** [build_load v name b] creates a
1061     [%name = load %v]
1062     instruction at the position specified by the instruction builder [b].
1063     See the method [llvm::LLVMBuilder::CreateLoad]. **)
1064 external build_load : llvalue -> string -> llbuilder -> llvalue
1065                     = "llvm_build_load"
1066
1067 (** [build_store v p b] creates a
1068     [store %v, %p]
1069     instruction at the position specified by the instruction builder [b].
1070     See the method [llvm::LLVMBuilder::CreateStore]. **)
1071 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1072                      = "llvm_build_store"
1073
1074 (** [build_store p indices name b] creates a
1075     [%name = gep %p, indices...]
1076     instruction at the position specified by the instruction builder [b].
1077     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. **)
1078 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1079                    = "llvm_build_gep"
1080
1081 (*--... Casts ..............................................................--*)
1082
1083 (** [build_trunc v ty name b] creates a
1084     [%name = trunc %p to %ty]
1085     instruction at the position specified by the instruction builder [b].
1086     See the method [llvm::LLVMBuilder::CreateTrunc]. **)
1087 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1088                      = "llvm_build_trunc"
1089
1090 (** [build_zext v ty name b] creates a
1091     [%name = zext %p to %ty]
1092     instruction at the position specified by the instruction builder [b].
1093     See the method [llvm::LLVMBuilder::CreateZExt]. **)
1094 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1095                     = "llvm_build_zext"
1096
1097 (** [build_sext v ty name b] creates a
1098     [%name = sext %p to %ty]
1099     instruction at the position specified by the instruction builder [b].
1100     See the method [llvm::LLVMBuilder::CreateSExt]. **)
1101 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1102                     = "llvm_build_sext"
1103
1104 (** [build_fptoui v ty name b] creates a
1105     [%name = fptoui %p to %ty]
1106     instruction at the position specified by the instruction builder [b].
1107     See the method [llvm::LLVMBuilder::CreateFPToUI]. **)
1108 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1109                       = "llvm_build_fptoui"
1110
1111 (** [build_fptosi v ty name b] creates a
1112     [%name = fptosi %p to %ty]
1113     instruction at the position specified by the instruction builder [b].
1114     See the method [llvm::LLVMBuilder::CreateFPToSI]. **)
1115 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1116                       = "llvm_build_fptosi"
1117
1118 (** [build_uitofp v ty name b] creates a
1119     [%name = uitofp %p to %ty]
1120     instruction at the position specified by the instruction builder [b].
1121     See the method [llvm::LLVMBuilder::CreateUIToFP]. **)
1122 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1123                       = "llvm_build_uitofp"
1124
1125 (** [build_sitofp v ty name b] creates a
1126     [%name = sitofp %p to %ty]
1127     instruction at the position specified by the instruction builder [b].
1128     See the method [llvm::LLVMBuilder::CreateSIToFP]. **)
1129 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1130                       = "llvm_build_sitofp"
1131
1132 (** [build_fptrunc v ty name b] creates a
1133     [%name = fptrunc %p to %ty]
1134     instruction at the position specified by the instruction builder [b].
1135     See the method [llvm::LLVMBuilder::CreateFPTrunc]. **)
1136 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1137                        = "llvm_build_fptrunc"
1138
1139 (** [build_fpext v ty name b] creates a
1140     [%name = fpext %p to %ty]
1141     instruction at the position specified by the instruction builder [b].
1142     See the method [llvm::LLVMBuilder::CreateFPExt]. **)
1143 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1144                      = "llvm_build_fpext"
1145
1146 (** [build_ptrtoint v ty name b] creates a
1147     [%name = prtotint %p to %ty]
1148     instruction at the position specified by the instruction builder [b].
1149     See the method [llvm::LLVMBuilder::CreatePtrToInt]. **)
1150 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1151                         = "llvm_build_prttoint"
1152
1153 (** [build_inttoptr v ty name b] creates a
1154     [%name = inttoptr %p to %ty]
1155     instruction at the position specified by the instruction builder [b].
1156     See the method [llvm::LLVMBuilder::CreateIntToPtr]. **)
1157 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1158                         = "llvm_build_inttoptr"
1159
1160 (** [build_bitcast v ty name b] creates a
1161     [%name = bitcast %p to %ty]
1162     instruction at the position specified by the instruction builder [b].
1163     See the method [llvm::LLVMBuilder::CreateBitcast]. **)
1164 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1165                        = "llvm_build_bitcast"
1166
1167 (*--... Comparisons ........................................................--*)
1168
1169 (** [build_icmp pred x y name b] creates a
1170     [%name = icmp %pred %x, %y]
1171     instruction at the position specified by the instruction builder [b].
1172     See the method [llvm::LLVMBuilder::CreateICmp]. **)
1173 external build_icmp : int_predicate -> llvalue -> llvalue -> string ->
1174                       llbuilder -> llvalue = "llvm_build_icmp"
1175
1176 (** [build_fcmp pred x y name b] creates a
1177     [%name = fcmp %pred %x, %y]
1178     instruction at the position specified by the instruction builder [b].
1179     See the method [llvm::LLVMBuilder::CreateFCmp]. **)
1180 external build_fcmp : real_predicate -> llvalue -> llvalue -> string ->
1181                       llbuilder -> llvalue = "llvm_build_fcmp"
1182
1183 (*--... Miscellaneous instructions .........................................--*)
1184
1185 (** [build_phi incoming name b] creates a
1186     [%name = phi %incoming]
1187     instruction at the position specified by the instruction builder [b].
1188     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1189     See the method [llvm::LLVMBuilder::CreatePHI]. **)
1190 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1191                      llvalue = "llvm_build_phi"
1192
1193 (** [build_call fn args name b] creates a
1194     [%name = call %fn(args...)]
1195     instruction at the position specified by the instruction builder [b].
1196     See the method [llvm::LLVMBuilder::CreateCall]. **)
1197 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1198                     = "llvm_build_call"
1199
1200 (** [build_select cond thenv elsev name b] creates a
1201     [%name = select %cond, %thenv, %elsev]
1202     instruction at the position specified by the instruction builder [b].
1203     See the method [llvm::LLVMBuilder::CreateSelect]. **)
1204 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1205                         llvalue = "llvm_build_select"
1206
1207 (** [build_va_arg valist argty name b] creates a
1208     [%name = va_arg %valist, %argty]
1209     instruction at the position specified by the instruction builder [b].
1210     See the method [llvm::LLVMBuilder::CreateVAArg]. **)
1211 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1212                       = "llvm_build_va_arg"
1213
1214 (** [build_extractelement vec i name b] creates a
1215     [%name = extractelement %vec, %i]
1216     instruction at the position specified by the instruction builder [b].
1217     See the method [llvm::LLVMBuilder::CreateExtractElement]. **)
1218 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1219                                 llvalue = "llvm_build_extractelement"
1220
1221 (** [build_insertelement vec elt i name b] creates a
1222     [%name = insertelement %vec, %elt, %i]
1223     instruction at the position specified by the instruction builder [b].
1224     See the method [llvm::LLVMBuilder::CreateInsertElement]. **)
1225 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1226                                llbuilder -> llvalue = "llvm_build_insertelement"
1227
1228 (** [build_shufflevector veca vecb mask name b] creates a
1229     [%name = shufflevector %veca, %vecb, %mask]
1230     instruction at the position specified by the instruction builder [b].
1231     See the method [llvm::LLVMBuilder::CreateShuffleVector]. **)
1232 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1233                                llbuilder -> llvalue = "llvm_build_shufflevector"
1234
1235
1236 (*===-- Module providers --------------------------------------------------===*)
1237
1238 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1239     ownership of the module. See the constructor 
1240     [llvm::ExistingModuleProvider::ExistingModuleProvider]. **)
1241 external create_module_provider : llmodule -> llmoduleprovider
1242                                 = "LLVMCreateModuleProviderForExistingModule"
1243
1244 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1245     the contained module. **)
1246 external dispose_module_provider : llmoduleprovider -> unit
1247                                  = "llvm_dispose_module_provider"