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