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