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