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