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