e66894c1d56744d7ea6ac5de1fb67e37b4606736
[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   | Metadata
72 end
73
74 (** The linkage of a global value, accessed with {!linkage} and
75     {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
76 module Linkage : sig
77   type t =
78     External
79   | Available_externally
80   | Link_once
81   | Weak
82   | Appending
83   | Internal
84   | Dllimport
85   | Dllexport
86   | External_weak
87   | Ghost
88 end
89
90 (** The linker visibility of a global value, accessed with {!visibility} and
91     {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
92 module Visibility : sig
93   type t =
94     Default
95   | Hidden
96   | Protected
97 end
98
99 (** The following calling convention values may be accessed with
100     {!function_call_conv} and {!set_function_call_conv}. Calling
101     conventions are open-ended. *)
102 module CallConv : sig
103   val c : int             (** [c] is the C calling convention. *)
104   val fast : int          (** [fast] is the calling convention to allow LLVM
105                               maximum optimization opportunities. Use only with
106                               internal linkage. *)
107   val cold : int          (** [cold] is the calling convention for
108                               callee-save. *)
109   val x86_stdcall : int   (** [x86_stdcall] is the familiar stdcall calling
110                               convention from C. *)
111   val x86_fastcall : int  (** [x86_fastcall] is the familiar fastcall calling
112                               convention from C. *)
113 end
114
115 module Attribute : sig
116   type t =
117   | Zext
118   | Sext
119   | Noreturn
120   | Inreg
121   | Structret
122   | Nounwind
123   | Noalias
124   | Byval
125   | Nest
126   | Readnone
127   | Readonly
128 end
129
130 (** The predicate for an integer comparison ([icmp]) instruction.
131     See the [llvm::ICmpInst::Predicate] enumeration. *)
132 module Icmp : sig
133   type t =
134   | Eq
135   | Ne
136   | Ugt
137   | Uge
138   | Ult
139   | Ule
140   | Sgt
141   | Sge
142   | Slt
143   | Sle
144 end
145
146 (** The predicate for a floating-point comparison ([fcmp]) instruction.
147     See the [llvm::FCmpInst::Predicate] enumeration. *)
148 module Fcmp : sig
149   type t =
150   | False
151   | Oeq
152   | Ogt
153   | Oge
154   | Olt
155   | Ole
156   | One
157   | Ord
158   | Uno
159   | Ueq
160   | Ugt
161   | Uge
162   | Ult
163   | Ule
164   | Une
165   | True
166 end
167
168
169 (** {6 Iteration} *)
170
171 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
172     of [a]. [llpos] is used to specify positions in and for forward iteration
173     through the various value lists maintained by the LLVM IR. *)
174 type ('a, 'b) llpos =
175 | At_end of 'a
176 | Before of 'b
177
178 (** [After b] and [At_start a] specify positions from the end of the ['b] list
179     of [a]. [llrev_pos] is used for reverse iteration through the various value
180     lists maintained by the LLVM IR. *)
181 type ('a, 'b) llrev_pos =
182 | At_start of 'a
183 | After of 'b
184
185
186 (** {6 Exceptions} *)
187
188 exception IoError of string
189
190
191 (** {6 Modules} *)
192
193 (** [create_module id] creates a module with the supplied module ID. Modules are
194     not garbage collected; it is mandatory to call {!dispose_module} to free
195     memory. See the constructor [llvm::Module::Module]. *)
196 external create_module : string -> llmodule = "llvm_create_module"
197
198 (** [dispose_module m] destroys a module [m] and all of the IR objects it
199     contained. All references to subordinate objects are invalidated;
200     referencing them will invoke undefined behavior. See the destructor
201     [llvm::Module::~Module]. *)
202 external dispose_module : llmodule -> unit = "llvm_dispose_module"
203
204 (** [target_triple m] is the target specifier for the module [m], something like
205     [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
206 external target_triple: llmodule -> string
207                       = "llvm_target_triple"
208
209 (** [target_triple triple m] changes the target specifier for the module [m] to
210     the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
211 external set_target_triple: string -> llmodule -> unit
212                           = "llvm_set_target_triple"
213
214 (** [data_layout m] is the data layout specifier for the module [m], something
215     like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
216     method [llvm::Module::getDataLayout]. *)
217 external data_layout: llmodule -> string
218                     = "llvm_data_layout"
219
220 (** [set_data_layout s m] changes the data layout specifier for the module [m]
221     to the string [s]. See the method [llvm::Module::setDataLayout]. *)
222 external set_data_layout: string -> llmodule -> unit
223                         = "llvm_set_data_layout"
224
225 (** [define_type_name name ty m] adds a named type to the module's symbol table.
226     Returns [true] if successful. If such a name already exists, then no entry
227     is added and [false] is returned. See the [llvm::Module::addTypeName]
228     method. *)
229 external define_type_name : string -> lltype -> llmodule -> bool
230                           = "llvm_add_type_name"
231
232 (** [delete_type_name name] removes a type name from the module's symbol
233     table. *)
234 external delete_type_name : string -> llmodule -> unit
235                           = "llvm_delete_type_name"
236
237 (** [dump_module m] prints the .ll representation of the module [m] to standard
238     error. See the method [llvm::Module::dump]. *)
239 external dump_module : llmodule -> unit = "llvm_dump_module"
240
241
242 (** {6 Types} *)
243
244 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
245     See the method [llvm::Type::getTypeID]. *)
246 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
247
248 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
249 val string_of_lltype : lltype -> string
250
251 (** {7 Operations on integer types} *)
252
253 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
254 val i1_type : lltype
255
256 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
257 val i8_type : lltype
258
259 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
260 val i16_type : lltype
261
262 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
263 val i32_type : lltype
264
265 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
266 val i64_type : lltype
267
268 (** [integer_type n] returns an integer type of bitwidth [n].
269     See the method [llvm::IntegerType::get]. *)
270 external integer_type : int -> lltype = "llvm_integer_type"
271
272 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
273     See the method [llvm::IntegerType::getBitWidth]. *)
274 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
275
276
277 (** {7 Operations on real types} *)
278
279 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
280 val float_type : lltype
281
282 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
283 val double_type : lltype
284
285 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
286 val x86fp80_type : lltype
287
288 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
289 val fp128_type : lltype
290
291 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
292 val ppc_fp128_type : lltype
293
294
295 (** {7 Operations on function types} *)
296
297 (** [function_type ret_ty param_tys] returns the function type returning
298     [ret_ty] and taking [param_tys] as parameters.
299     See the method [llvm::FunctionType::get]. *)
300 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
301
302 (** [va_arg_function_type ret_ty param_tys] is just like
303     [function_type ret_ty param_tys] except that it returns the function type
304     which also takes a variable number of arguments.
305     See the method [llvm::FunctionType::get]. *)
306 external var_arg_function_type : lltype -> lltype array -> lltype
307                                = "llvm_var_arg_function_type"
308
309 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
310     otherwise. See the method [llvm::FunctionType::isVarArg]. *)
311 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
312
313 (** [return_type fty] gets the return type of the function type [fty].
314     See the method [llvm::FunctionType::getReturnType]. *)
315 external return_type : lltype -> lltype = "LLVMGetReturnType"
316
317 (** [param_types fty] gets the parameter types of the function type [fty].
318     See the method [llvm::FunctionType::getParamType]. *)
319 external param_types : lltype -> lltype array = "llvm_param_types"
320
321
322 (** {7 Operations on struct types} *)
323
324 (** [struct_type tys] returns the structure type containing in the types in the
325     array [tys]. See the method [llvm::StructType::get]. *)
326 external struct_type : lltype array -> lltype = "llvm_struct_type"
327
328 (** [packed_struct_type tys] returns the packed structure type containing in the
329     types in the array [tys]. See the method [llvm::StructType::get]. *)
330 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
331
332 (** [element_types sty] returns the constituent types of the struct type [sty].
333     See the method [llvm::StructType::getElementType]. *)
334 external element_types : lltype -> lltype array = "llvm_element_types"
335
336 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
337     [false] otherwise. See the method [llvm::StructType::isPacked]. *)
338 external is_packed : lltype -> bool = "llvm_is_packed"
339
340
341 (** {7 Operations on pointer, vector, and array types} *)
342
343 (** [array_type ty n] returns the array type containing [n] elements of type
344     [ty]. See the method [llvm::ArrayType::get]. *)
345 external array_type : lltype -> int -> lltype = "llvm_array_type"
346
347 (** [pointer_type ty] returns the pointer type referencing objects of type
348     [ty] in the default address space (0).
349     See the method [llvm::PointerType::getUnqual]. *)
350 external pointer_type : lltype -> lltype = "llvm_pointer_type"
351
352 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
353     of type [ty] in address space [as].
354     See the method [llvm::PointerType::get]. *)
355 external qualified_pointer_type : lltype -> int -> lltype
356                                 = "llvm_qualified_pointer_type"
357
358 (** [vector_type ty n] returns the array type containing [n] elements of the
359     primitive type [ty]. See the method [llvm::ArrayType::get]. *)
360 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
361
362 (** [element_type ty] returns the element type of the pointer, vector, or array
363     type [ty]. See the method [llvm::SequentialType::get]. *)
364 external element_type : lltype -> lltype = "LLVMGetElementType"
365
366 (** [element_type aty] returns the element count of the array type [aty].
367     See the method [llvm::ArrayType::getNumElements]. *)
368 external array_length : lltype -> int = "llvm_array_length"
369
370 (** [address_space pty] returns the address space qualifier of the pointer type
371     [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
372 external address_space : lltype -> int = "llvm_address_space"
373
374 (** [element_type ty] returns the element count of the vector type [ty].
375     See the method [llvm::VectorType::getNumElements]. *)
376 external vector_size : lltype -> int = "llvm_vector_size"
377
378
379 (** {7 Operations on other types} *)
380
381 (** [opaque_type ()] creates a new opaque type distinct from any other.
382     Opaque types are useful for building recursive types in combination with
383     {!refine_type}.
384     See [llvm::OpaqueType::get]. *)
385 external opaque_type : unit -> lltype = "llvm_opaque_type"
386
387 (** [void_type] is the type of a function which does not return any value.
388     See [llvm::Type::VoidTy]. *)
389 val void_type : lltype
390
391 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
392 val label_type : lltype
393
394 (** {7 Operations on type handles} *)
395
396 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
397     refined as a result of a call to {!refine_type}, the handle will be updated;
398     any bare [lltype] references will become invalid.
399     See the class [llvm::PATypeHolder]. *)
400 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
401
402 (** [type_of_handle tyh] resolves the type handle [tyh].
403     See the method [llvm::PATypeHolder::get()]. *)
404 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
405
406 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
407     concrete type [ty] in all users. Warning: This may invalidate {!lltype}
408     values! Use {!lltypehandle} to manipulate potentially abstract types. See
409     the method [llvm::Type::refineAbstractType]. *)
410 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
411
412
413 (* {6 Values} *)
414
415 (** [type_of v] returns the type of the value [v].
416     See the method [llvm::Value::getType]. *)
417 external type_of : llvalue -> lltype = "llvm_type_of"
418
419 (** [value_name v] returns the name of the value [v]. For global values, this is
420     the symbol name. For instructions and basic blocks, it is the SSA register
421     name. It is meaningless for constants.
422     See the method [llvm::Value::getName]. *)
423 external value_name : llvalue -> string = "llvm_value_name"
424
425 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
426     [llvm::Value::setName]. *)
427 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
428
429 (** [dump_value v] prints the .ll representation of the value [v] to standard
430     error. See the method [llvm::Value::dump]. *)
431 external dump_value : llvalue -> unit = "llvm_dump_value"
432
433
434 (** {7 Operations on constants of (mostly) any type} *)
435
436 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
437     otherwise. Similar to [llvm::isa<Constant>]. *)
438 external is_constant : llvalue -> bool = "llvm_is_constant"
439
440 (** [const_null ty] returns the constant null (zero) of the type [ty].
441     See the method [llvm::Constant::getNullValue]. *)
442 external const_null : lltype -> llvalue = "LLVMConstNull"
443
444 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
445     [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
446 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
447
448 (** [undef ty] returns the undefined value of the type [ty].
449     See the method [llvm::UndefValue::get]. *)
450 external undef : lltype -> llvalue = "LLVMGetUndef"
451
452 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
453     See the method [llvm::Constant::isNullValue]. *)
454 external is_null : llvalue -> bool = "llvm_is_null"
455
456 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
457     otherwise. Similar to [llvm::isa<UndefValue>]. *)
458 external is_undef : llvalue -> bool = "llvm_is_undef"
459
460
461 (** {7 Operations on scalar constants} *)
462
463 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
464     See the method [llvm::ConstantInt::get]. *)
465 external const_int : lltype -> int -> llvalue = "llvm_const_int"
466
467 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
468     [i]. See the method [llvm::ConstantInt::get]. *)
469 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
470                         = "llvm_const_of_int64"
471
472 (** [const_float ty n] returns the floating point constant of type [ty] and
473     value [n]. See the method [llvm::ConstantFP::get]. *)
474 external const_float : lltype -> float -> llvalue = "llvm_const_float"
475
476
477 (** {7 Operations on composite constants} *)
478
479 (** [const_string s] returns the constant [i8] array with the values of the
480     characters in the string [s]. The array is not null-terminated (but see
481     {!const_stringz}). This value can in turn be used as the initializer for a
482     global variable. See the method [llvm::ConstantArray::get]. *)
483 external const_string : string -> llvalue = "llvm_const_string"
484
485 (** [const_stringz s] returns the constant [i8] array with the values of the
486     characters in the string [s] and a null terminator. This value can in turn
487     be used as the initializer for a global variable.
488     See the method [llvm::ConstantArray::get]. *)
489 external const_stringz : string -> llvalue = "llvm_const_stringz"
490
491 (** [const_array ty elts] returns the constant array of type
492     [array_type ty (Array.length elts)] and containing the values [elts].
493     This value can in turn be used as the initializer for a global variable.
494     See the method [llvm::ConstantArray::get]. *)
495 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
496
497 (** [const_struct elts] returns the structured constant of type
498     [struct_type (Array.map type_of elts)] and containing the values [elts].
499     This value can in turn be used as the initializer for a global variable.
500     See the method [llvm::ConstantStruct::get]. *)
501 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
502
503 (** [const_packed_struct elts] returns the structured constant of type
504     {!packed_struct_type} [(Array.map type_of elts)] and containing the values
505     [elts]. This value can in turn be used as the initializer for a global
506     variable. See the method [llvm::ConstantStruct::get]. *)
507 external const_packed_struct : llvalue array -> llvalue
508                              = "llvm_const_packed_struct"
509
510 (** [const_vector elts] returns the vector constant of type
511     [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
512     values [elts]. See the method [llvm::ConstantVector::get]. *)
513 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
514
515
516 (** {7 Constant expressions} *)
517
518 (** [align_of ty] returns the alignof constant for the type [ty]. This is
519     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
520     (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
521     more readable.  See the method [llvm::ConstantExpr::getAlignOf]. *)
522 external align_of : lltype -> llvalue = "LLVMAlignOf"
523
524 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
525     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
526     (const_int i32_type 1)) i64_type], but considerably more readable.
527     See the method [llvm::ConstantExpr::getSizeOf]. *)
528 external size_of : lltype -> llvalue = "LLVMSizeOf"
529
530 (** [const_neg c] returns the arithmetic negation of the constant [c].
531     See the method [llvm::ConstantExpr::getNeg]. *)
532 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
533
534 (** [const_not c] returns the bitwise inverse of the constant [c].
535     See the method [llvm::ConstantExpr::getNot]. *)
536 external const_not : llvalue -> llvalue = "LLVMConstNot"
537
538 (** [const_add c1 c2] returns the constant sum of two constants.
539     See the method [llvm::ConstantExpr::getAdd]. *)
540 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
541
542 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
543     constants. See the method [llvm::ConstantExpr::getSub]. *)
544 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
545
546 (** [const_mul c1 c2] returns the constant product of two constants.
547     See the method [llvm::ConstantExpr::getMul]. *)
548 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
549
550 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
551     integer constants.
552     See the method [llvm::ConstantExpr::getUDiv]. *)
553 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
554
555 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
556     integer constants.
557     See the method [llvm::ConstantExpr::]. *)
558 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
559
560 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
561     point constants.
562     See the method [llvm::ConstantExpr::getFDiv]. *)
563 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
564
565 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
566     unsigned integer constants.
567     See the method [llvm::ConstantExpr::getURem]. *)
568 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
569
570 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
571     signed integer constants.
572     See the method [llvm::ConstantExpr::getSRem]. *)
573 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
574
575 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
576     signed floating point constants.
577     See the method [llvm::ConstantExpr::getFRem]. *)
578 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
579
580 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
581     constants.
582     See the method [llvm::ConstantExpr::getAnd]. *)
583 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
584
585 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
586     constants.
587     See the method [llvm::ConstantExpr::getOr]. *)
588 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
589
590 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
591     constants.
592     See the method [llvm::ConstantExpr::getXor]. *)
593 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
594
595 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
596     constants, [c1 pred c2].
597     See the method [llvm::ConstantExpr::getICmp]. *)
598 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
599                     = "llvm_const_icmp"
600
601 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
602     point constants, [c1 pred c2].
603     See the method [llvm::ConstantExpr::getFCmp]. *)
604 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
605                     = "llvm_const_fcmp"
606
607 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
608     constant integer [c2].
609     See the method [llvm::ConstantExpr::getShl]. *)
610 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
611
612 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
613     constant integer [c2] with zero extension.
614     See the method [llvm::ConstantExpr::getLShr]. *)
615 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
616
617 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
618     constant integer [c2] with sign extension.
619     See the method [llvm::ConstantExpr::getAShr]. *)
620 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
621
622 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
623     constant integers indices from the array [indices].
624     See the method [llvm::ConstantExpr::getGetElementPtr]. *)
625 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
626
627 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
628     to the smaller integer type [ty].
629     See the method [llvm::ConstantExpr::getTrunc]. *)
630 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
631
632 (** [const_sext c ty] returns the constant sign extension of integer constant
633     [c] to the larger integer type [ty].
634     See the method [llvm::ConstantExpr::getSExt]. *)
635 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
636
637 (** [const_zext c ty] returns the constant zero extension of integer constant
638     [c] to the larger integer type [ty].
639     See the method [llvm::ConstantExpr::getZExt]. *)
640 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
641
642 (** [const_fptrunc c ty] returns the constant truncation of floating point
643     constant [c] to the smaller floating point type [ty].
644     See the method [llvm::ConstantExpr::getFPTrunc]. *)
645 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
646
647 (** [const_fpext c ty] returns the constant extension of floating point constant
648     [c] to the larger floating point type [ty].
649     See the method [llvm::ConstantExpr::getFPExt]. *)
650 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
651
652 (** [const_uitofp c ty] returns the constant floating point conversion of
653     unsigned integer constant [c] to the floating point type [ty].
654     See the method [llvm::ConstantExpr::getUIToFP]. *)
655 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
656
657 (** [const_sitofp c ty] returns the constant floating point conversion of
658     signed integer constant [c] to the floating point type [ty].
659     See the method [llvm::ConstantExpr::getSIToFP]. *)
660 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
661
662 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
663     floating point constant [c] to integer type [ty].
664     See the method [llvm::ConstantExpr::getFPToUI]. *)
665 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
666
667 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
668     floating point constant [c] to integer type [ty].
669     See the method [llvm::ConstantExpr::getFPToSI]. *)
670 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
671
672 (** [const_ptrtoint c ty] returns the constant integer conversion of
673     pointer constant [c] to integer type [ty].
674     See the method [llvm::ConstantExpr::getPtrToInt]. *)
675 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
676
677 (** [const_inttoptr c ty] returns the constant pointer conversion of
678     integer constant [c] to pointer type [ty].
679     See the method [llvm::ConstantExpr::getIntToPtr]. *)
680 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
681
682 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
683     to type [ty] of equal size.
684     See the method [llvm::ConstantExpr::getBitCast]. *)
685 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
686
687 (** [const_select cond t f] returns the constant conditional which returns value
688     [t] if the boolean constant [cond] is true and the value [f] otherwise.
689     See the method [llvm::ConstantExpr::getSelect]. *)
690 external const_select : llvalue -> llvalue -> llvalue -> llvalue
691                       = "LLVMConstSelect"
692
693 (** [const_extractelement vec i] returns the constant [i]th element of
694     constant vector [vec]. [i] must be a constant [i32] value unsigned less than
695     the size of the vector.
696     See the method [llvm::ConstantExpr::getExtractElement]. *)
697 external const_extractelement : llvalue -> llvalue -> llvalue
698                               = "LLVMConstExtractElement"
699
700 (** [const_insertelement vec v i] returns the constant vector with the same
701     elements as constant vector [v] but the [i]th element replaced by the
702     constant [v]. [v] must be a constant value with the type of the vector
703     elements. [i] must be a constant [i32] value unsigned less than the size
704     of the vector.
705     See the method [llvm::ConstantExpr::getInsertElement]. *)
706 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
707                              = "LLVMConstInsertElement"
708
709 (** [const_shufflevector a b mask] returns a constant [shufflevector].
710     See the LLVM Language Reference for details on the [sufflevector]
711     instruction.
712     See the method [llvm::ConstantExpr::getShuffleVector]. *)
713 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
714                              = "LLVMConstShuffleVector"
715
716
717 (** {7 Operations on global variables, functions, and aliases (globals)} *)
718
719 (** [global_parent g] is the enclosing module of the global value [g].
720     See the method [llvm::GlobalValue::getParent]. *)
721 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
722
723 (** [is_declaration g] returns [true] if the global value [g] is a declaration
724     only. Returns [false] otherwise.
725     See the method [llvm::GlobalValue::isDeclaration]. *)
726 external is_declaration : llvalue -> bool = "llvm_is_declaration"
727
728 (** [linkage g] returns the linkage of the global value [g].
729     See the method [llvm::GlobalValue::getLinkage]. *)
730 external linkage : llvalue -> Linkage.t = "llvm_linkage"
731
732 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
733     See the method [llvm::GlobalValue::setLinkage]. *)
734 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
735
736 (** [section g] returns the linker section of the global value [g].
737     See the method [llvm::GlobalValue::getSection]. *)
738 external section : llvalue -> string = "llvm_section"
739
740 (** [set_section s g] sets the linker section of the global value [g] to [s].
741     See the method [llvm::GlobalValue::setSection]. *)
742 external set_section : string -> llvalue -> unit = "llvm_set_section"
743
744 (** [visibility g] returns the linker visibility of the global value [g].
745     See the method [llvm::GlobalValue::getVisibility]. *)
746 external visibility : llvalue -> Visibility.t = "llvm_visibility"
747
748 (** [set_visibility v g] sets the linker visibility of the global value [g] to
749     [v]. See the method [llvm::GlobalValue::setVisibility]. *)
750 external set_visibility : Visibility.t -> llvalue -> unit
751                         = "llvm_set_visibility"
752
753 (** [alignment g] returns the required alignment of the global value [g].
754     See the method [llvm::GlobalValue::getAlignment]. *)
755 external alignment : llvalue -> int = "llvm_alignment"
756
757 (** [set_alignment n g] sets the required alignment of the global value [g] to
758     [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
759 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
760
761
762 (** {7 Operations on global variables} *)
763
764 (** [declare_global ty name m] returns a new global variable of type [ty] and
765     with name [name] in module [m]. If such a global variable already exists,
766     it is returned. If the type of the existing global differs, then a bitcast
767     to [ty] is returned. *)
768 external declare_global : lltype -> string -> llmodule -> llvalue
769                         = "llvm_declare_global"
770
771 (** [define_global name init m] returns a new global with name [name] and
772     initializer [init] in module [m]. If the named global already exists, it is
773     renamed.
774     See the constructor of [llvm::GlobalVariable]. *)
775 external define_global : string -> llvalue -> llmodule -> llvalue
776                        = "llvm_define_global"
777
778 (** [lookup_global name m] returns [Some g] if a global variable with name
779     [name] exists in module [m]. If no such global exists, returns [None].
780     See the [llvm::GlobalVariable] constructor. *)
781 external lookup_global : string -> llmodule -> llvalue option
782                        = "llvm_lookup_global"
783
784 (** [delete_global gv] destroys the global variable [gv].
785     See the method [llvm::GlobalVariable::eraseFromParent]. *)
786 external delete_global : llvalue -> unit = "llvm_delete_global"
787
788 (** [global_begin m] returns the first position in the global variable list of
789     the module [m]. [global_begin] and [global_succ] can be used to iterate
790     over the global list in order.
791     See the method [llvm::Module::global_begin]. *)
792 external global_begin : llmodule -> (llmodule, llvalue) llpos
793                       = "llvm_global_begin"
794
795 (** [global_succ gv] returns the global variable list position succeeding
796     [Before gv].
797     See the method [llvm::Module::global_iterator::operator++]. *)
798 external global_succ : llvalue -> (llmodule, llvalue) llpos
799                      = "llvm_global_succ"
800
801 (** [iter_globals f m] applies function [f] to each of the global variables of
802     module [m] in order. Tail recursive. *)
803 val iter_globals : (llvalue -> unit) -> llmodule -> unit
804
805 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
806     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
807 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
808
809 (** [global_end m] returns the last position in the global variable list of the
810     module [m]. [global_end] and [global_pred] can be used to iterate over the
811     global list in reverse.
812     See the method [llvm::Module::global_end]. *)
813 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
814                     = "llvm_global_end"
815
816 (** [global_pred gv] returns the global variable list position preceding
817     [After gv].
818     See the method [llvm::Module::global_iterator::operator--]. *)
819 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
820                      = "llvm_global_pred"
821
822 (** [rev_iter_globals f m] applies function [f] to each of the global variables
823     of module [m] in reverse order. Tail recursive. *)
824 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
825
826 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
827     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
828 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
829
830 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
831     constant. Returns [false] otherwise.
832     See the method [llvm::GlobalVariable::isConstant]. *)
833 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
834
835 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
836     [c] is [true] and not if [c] is [false].
837     See the method [llvm::GlobalVariable::setConstant]. *)
838 external set_global_constant : bool -> llvalue -> unit
839                              = "llvm_set_global_constant"
840
841 (** [global_initializer gv] returns the initializer for the global variable
842     [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
843 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
844
845 (** [set_initializer c gv] sets the initializer for the global variable
846     [gv] to the constant [c].
847     See the method [llvm::GlobalVariable::setInitializer]. *)
848 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
849
850 (** [remove_initializer gv] unsets the initializer for the global variable
851     [gv].
852     See the method [llvm::GlobalVariable::setInitializer]. *)
853 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
854
855 (** [is_thread_local gv] returns [true] if the global variable [gv] is
856     thread-local and [false] otherwise.
857     See the method [llvm::GlobalVariable::isThreadLocal]. *)
858 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
859
860 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
861     [c] is [true] and not otherwise.
862     See the method [llvm::GlobalVariable::setThreadLocal]. *)
863 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
864
865
866 (** {7 Operations on functions} *)
867
868 (** [declare_function name ty m] returns a new function of type [ty] and
869     with name [name] in module [m]. If such a function already exists,
870     it is returned. If the type of the existing function differs, then a bitcast
871     to [ty] is returned. *)
872 external declare_function : string -> lltype -> llmodule -> llvalue
873                           = "llvm_declare_function"
874
875 (** [define_function name ty m] creates a new function with name [name] and
876     type [ty] in module [m]. If the named function already exists, it is
877     renamed. An entry basic block is created in the function.
878     See the constructor of [llvm::GlobalVariable]. *)
879 external define_function : string -> lltype -> llmodule -> llvalue
880                          = "llvm_define_function"
881
882 (** [lookup_function name m] returns [Some f] if a function with name
883     [name] exists in module [m]. If no such function exists, returns [None].
884     See the method [llvm::Module] constructor. *)
885 external lookup_function : string -> llmodule -> llvalue option
886                          = "llvm_lookup_function"
887
888 (** [delete_function f] destroys the function [f].
889     See the method [llvm::Function::eraseFromParent]. *)
890 external delete_function : llvalue -> unit = "llvm_delete_function"
891
892 (** [function_begin m] returns the first position in the function list of the
893     module [m]. [function_begin] and [function_succ] can be used to iterate over
894     the function list in order.
895     See the method [llvm::Module::begin]. *)
896 external function_begin : llmodule -> (llmodule, llvalue) llpos
897                         = "llvm_function_begin"
898
899 (** [function_succ gv] returns the function list position succeeding
900     [Before gv].
901     See the method [llvm::Module::iterator::operator++]. *)
902 external function_succ : llvalue -> (llmodule, llvalue) llpos
903                        = "llvm_function_succ"
904
905 (** [iter_functions f m] applies function [f] to each of the functions of module
906     [m] in order. Tail recursive. *)
907 val iter_functions : (llvalue -> unit) -> llmodule -> unit
908
909 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
910     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
911 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
912
913 (** [function_end m] returns the last position in the function list of
914     the module [m]. [function_end] and [function_pred] can be used to iterate
915     over the function list in reverse.
916     See the method [llvm::Module::end]. *)
917 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
918                       = "llvm_function_end"
919
920 (** [function_pred gv] returns the function list position preceding [After gv].
921     See the method [llvm::Module::iterator::operator--]. *)
922 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
923                        = "llvm_function_pred"
924
925 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
926     module [m] in reverse order. Tail recursive. *)
927 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
928
929 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
930     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
931 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
932
933 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
934     See the method [llvm::Function::isIntrinsic]. *)
935 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
936
937 (** [function_call_conv f] returns the calling convention of the function [f].
938     See the method [llvm::Function::getCallingConv]. *)
939 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
940
941 (** [set_function_call_conv cc f] sets the calling convention of the function
942     [f] to the calling convention numbered [cc].
943     See the method [llvm::Function::setCallingConv]. *)
944 external set_function_call_conv : int -> llvalue -> unit
945                                 = "llvm_set_function_call_conv"
946
947 (** [gc f] returns [Some name] if the function [f] has a garbage
948     collection algorithm specified and [None] otherwise.
949     See the method [llvm::Function::getGC]. *)
950 external gc : llvalue -> string option = "llvm_gc"
951
952 (** [set_gc gc f] sets the collection algorithm for the function [f] to
953     [gc]. See the method [llvm::Function::setGC]. *)
954 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
955
956 (** [add_function_attr f a] adds attribute [a] to the return type of function
957     [f]. *)
958 external add_function_attr : llvalue -> Attribute.t -> unit
959                            = "llvm_add_function_attr"
960
961 (** [remove_function_attr f a] removes attribute [a] from the return type of
962     function [f]. *)
963 external remove_function_attr : llvalue -> Attribute.t -> unit
964                               = "llvm_remove_function_attr"
965
966 (** {7 Operations on params} *)
967
968 (** [params f] returns the parameters of function [f].
969     See the method [llvm::Function::getArgumentList]. *)
970 external params : llvalue -> llvalue array = "llvm_params"
971
972 (** [param f n] returns the [n]th parameter of function [f].
973     See the method [llvm::Function::getArgumentList]. *)
974 external param : llvalue -> int -> llvalue = "llvm_param"
975
976 (** [param_parent p] returns the parent function that owns the parameter.
977     See the method [llvm::Argument::getParent]. *)
978 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
979
980 (** [param_begin f] returns the first position in the parameter list of the
981     function [f]. [param_begin] and [param_succ] can be used to iterate over
982     the parameter list in order.
983     See the method [llvm::Function::arg_begin]. *)
984 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
985
986 (** [param_succ bb] returns the parameter list position succeeding
987     [Before bb].
988     See the method [llvm::Function::arg_iterator::operator++]. *)
989 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
990
991 (** [iter_params f fn] applies function [f] to each of the parameters
992     of function [fn] in order. Tail recursive. *)
993 val iter_params : (llvalue -> unit) -> llvalue -> unit
994
995 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
996     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
997 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
998
999 (** [param_end f] returns the last position in the parameter list of
1000     the function [f]. [param_end] and [param_pred] can be used to iterate
1001     over the parameter list in reverse.
1002     See the method [llvm::Function::arg_end]. *)
1003 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1004
1005 (** [param_pred gv] returns the function list position preceding [After gv].
1006     See the method [llvm::Function::arg_iterator::operator--]. *)
1007 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1008                     = "llvm_param_pred"
1009
1010 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1011     of function [fn] in reverse order. Tail recursive. *)
1012 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1013
1014 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1015     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1016 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1017
1018 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1019 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1020
1021 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1022 external remove_param_attr : llvalue -> Attribute.t -> unit
1023                            = "llvm_remove_param_attr"
1024
1025 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1026 external set_param_alignment : llvalue -> int -> unit
1027                              = "llvm_set_param_alignment"
1028
1029 (** {7 Operations on basic blocks} *)
1030
1031 (** [basic_blocks fn] returns the basic blocks of the function [f].
1032     See the method [llvm::Function::getBasicBlockList]. *)
1033 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1034
1035 (** [entry_block fn] returns the entry basic block of the function [f].
1036     See the method [llvm::Function::getEntryBlock]. *)
1037 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1038
1039 (** [delete_block bb] deletes the basic block [bb].
1040     See the method [llvm::BasicBlock::eraseFromParent]. *)
1041 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1042
1043 (** [append_block name f] creates a new basic block named [name] at the end of
1044     function [f].
1045     See the constructor of [llvm::BasicBlock]. *)
1046 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1047
1048 (** [insert_block name bb] creates a new basic block named [name] before the
1049     basic block [bb].
1050     See the constructor of [llvm::BasicBlock]. *)
1051 external insert_block : string -> llbasicblock -> llbasicblock
1052                       = "llvm_insert_block"
1053
1054 (** [block_parent bb] returns the parent function that owns the basic block.
1055     See the method [llvm::BasicBlock::getParent]. *)
1056 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1057
1058 (** [block_begin f] returns the first position in the basic block list of the
1059     function [f]. [block_begin] and [block_succ] can be used to iterate over
1060     the basic block list in order.
1061     See the method [llvm::Function::begin]. *)
1062 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1063                      = "llvm_block_begin"
1064
1065 (** [block_succ bb] returns the basic block list position succeeding
1066     [Before bb].
1067     See the method [llvm::Function::iterator::operator++]. *)
1068 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1069                     = "llvm_block_succ"
1070
1071 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1072     of function [fn] in order. Tail recursive. *)
1073 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1074
1075 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1076     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1077 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1078
1079 (** [block_end f] returns the last position in the basic block list of
1080     the function [f]. [block_end] and [block_pred] can be used to iterate
1081     over the basic block list in reverse.
1082     See the method [llvm::Function::end]. *)
1083 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1084                    = "llvm_block_end"
1085
1086 (** [block_pred gv] returns the function list position preceding [After gv].
1087     See the method [llvm::Function::iterator::operator--]. *)
1088 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1089                     = "llvm_block_pred"
1090
1091 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1092     of function [fn] in reverse order. Tail recursive. *)
1093 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1094
1095 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1096     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1097 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1098
1099 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1100 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1101
1102 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1103     [false] otherwise.
1104     Similar to [llvm::isa<BasicBlock>]. *)
1105 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1106
1107 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1108 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1109
1110
1111 (** {7 Operations on instructions} *)
1112
1113 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1114     See the method [llvm::Instruction::getParent]. *)
1115 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1116
1117 (** [instr_begin bb] returns the first position in the instruction list of the
1118     basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1119     the instruction list in order.
1120     See the method [llvm::BasicBlock::begin]. *)
1121 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1122                      = "llvm_instr_begin"
1123
1124 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1125     See the method [llvm::BasicBlock::iterator::operator++]. *)
1126 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1127                      = "llvm_instr_succ"
1128
1129 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1130     block [bb] in order. Tail recursive. *)
1131 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1132
1133 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1134     [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1135 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1136
1137 (** [instr_end bb] returns the last position in the instruction list of the
1138     basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1139     the instruction list in reverse.
1140     See the method [llvm::BasicBlock::end]. *)
1141 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1142                      = "llvm_instr_end"
1143
1144 (** [instr_pred i] returns the instruction list position preceding [After i].
1145     See the method [llvm::BasicBlock::iterator::operator--]. *)
1146 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1147                      = "llvm_instr_pred"
1148
1149 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1150     [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1151 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1152
1153
1154 (** {7 Operations on call sites} *)
1155
1156 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1157     instruction [ci], which may be one of the values from the module
1158     {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1159     [llvm::InvokeInst::getCallingConv]. *)
1160 external instruction_call_conv: llvalue -> int
1161                               = "llvm_instruction_call_conv"
1162
1163 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1164     or invoke instruction [ci] to the integer [cc], which can be one of the
1165     values from the module {!CallConv}.
1166     See the method [llvm::CallInst::setCallingConv]
1167     and [llvm::InvokeInst::setCallingConv]. *)
1168 external set_instruction_call_conv: int -> llvalue -> unit
1169                                   = "llvm_set_instruction_call_conv"
1170
1171 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1172     parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1173     value. *)
1174 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1175   = "llvm_add_instruction_param_attr"
1176
1177 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1178     [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1179     return value. *)
1180 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1181   = "llvm_remove_instruction_param_attr"
1182
1183 (** {Operations on call instructions (only)} *)
1184
1185 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1186     eligible for tail call optimization, [false] otherwise.
1187     See the method [llvm::CallInst::isTailCall]. *)
1188 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1189
1190 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1191     call optimization if [tc] is [true], clears otherwise.
1192     See the method [llvm::CallInst::setTailCall]. *)
1193 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1194
1195 (** {7 Operations on phi nodes} *)
1196
1197 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1198     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1199 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1200                       = "llvm_add_incoming"
1201
1202 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1203     See the method [llvm::PHINode::getIncomingValue]. *)
1204 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1205
1206
1207
1208 (** {6 Instruction builders} *)
1209
1210 (** [builder ()] creates an instruction builder with no position. It is invalid
1211     to use this builder until its position is set with {!position_before} or
1212     {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
1213 external builder : unit -> llbuilder = "llvm_builder"
1214
1215 (** [builder_at ip] creates an instruction builder positioned at [ip].
1216     See the constructor for [llvm::LLVMBuilder]. *)
1217 val builder_at : (llbasicblock, llvalue) llpos -> llbuilder
1218
1219 (** [builder_before ins] creates an instruction builder positioned before the
1220     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1221 val builder_before : llvalue -> llbuilder
1222
1223 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1224     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1225 val builder_at_end : llbasicblock -> llbuilder
1226
1227 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1228     [ip].
1229     See the constructor for [llvm::LLVMBuilder]. *)
1230 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1231                           = "llvm_position_builder"
1232
1233 (** [position_before ins b] moves the instruction builder [b] to before the
1234     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1235 val position_before : llvalue -> llbuilder -> unit
1236
1237 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1238     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1239 val position_at_end : llbasicblock -> llbuilder -> unit
1240
1241 (** [insertion_block b] returns the basic block that the builder [b] is
1242     positioned to insert into. Raises [Not_Found] if the instruction builder is
1243     uninitialized.
1244     See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1245 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1246
1247
1248 (** {7 Terminators} *)
1249
1250 (** [build_ret_void b] creates a
1251     [ret void]
1252     instruction at the position specified by the instruction builder [b].
1253     See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1254 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1255
1256 (** [build_ret v b] creates a
1257     [ret %v]
1258     instruction at the position specified by the instruction builder [b].
1259     See the method [llvm::LLVMBuilder::CreateRet]. *)
1260 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1261
1262 (** [build_aggregate_ret vs b] creates a
1263     [ret {...} { %v1, %v2, ... } ]
1264     instruction at the position specified by the instruction builder [b].
1265     See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1266 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1267                              = "llvm_build_aggregate_ret"
1268
1269 (** [build_br bb b] creates a
1270     [b %bb]
1271     instruction at the position specified by the instruction builder [b].
1272     See the method [llvm::LLVMBuilder::CreateBr]. *)
1273 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1274
1275 (** [build_cond_br cond tbb fbb b] creates a
1276     [b %cond, %tbb, %fbb]
1277     instruction at the position specified by the instruction builder [b].
1278     See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1279 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1280                          llvalue = "llvm_build_cond_br"
1281
1282 (** [build_switch case elsebb count b] creates an empty
1283     [switch %case, %elsebb]
1284     instruction at the position specified by the instruction builder [b] with
1285     space reserved for [count] cases.
1286     See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1287 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1288                       = "llvm_build_switch"
1289
1290 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1291     when its input matches the constant [onval].
1292     See the method [llvm::SwitchInst::addCase]. **)
1293 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1294                   = "llvm_add_case"
1295
1296 (** [build_invoke fn args tobb unwindbb name b] creates an
1297     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1298     instruction at the position specified by the instruction builder [b].
1299     See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1300 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1301                         llbasicblock -> string -> llbuilder -> llvalue
1302                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1303
1304 (** [build_unwind b] creates an
1305     [unwind]
1306     instruction at the position specified by the instruction builder [b].
1307     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1308 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1309
1310 (** [build_unreachable b] creates an
1311     [unreachable]
1312     instruction at the position specified by the instruction builder [b].
1313     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1314 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1315
1316
1317 (** {7 Arithmetic} *)
1318
1319 (** [build_add x y name b] creates a
1320     [%name = add %x, %y]
1321     instruction at the position specified by the instruction builder [b].
1322     See the method [llvm::LLVMBuilder::CreateAdd]. *)
1323 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1324                    = "llvm_build_add"
1325
1326 (** [build_nswadd x y name b] creates a
1327     [%name = nsw add %x, %y]
1328     instruction at the position specified by the instruction builder [b].
1329     See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1330 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1331                       = "llvm_build_nsw_add"
1332
1333 (** [build_fadd x y name b] creates a
1334     [%name = fadd %x, %y]
1335     instruction at the position specified by the instruction builder [b].
1336     See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1337 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1338                     = "llvm_build_fadd"
1339
1340 (** [build_sub x y name b] creates a
1341     [%name = sub %x, %y]
1342     instruction at the position specified by the instruction builder [b].
1343     See the method [llvm::LLVMBuilder::CreateSub]. *)
1344 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1345                    = "llvm_build_sub"
1346
1347 (** [build_fsub x y name b] creates a
1348     [%name = fsub %x, %y]
1349     instruction at the position specified by the instruction builder [b].
1350     See the method [llvm::LLVMBuilder::CreateFSub]. *)
1351 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1352                     = "llvm_build_fsub"
1353
1354 (** [build_mul x y name b] creates a
1355     [%name = mul %x, %y]
1356     instruction at the position specified by the instruction builder [b].
1357     See the method [llvm::LLVMBuilder::CreateMul]. *)
1358 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1359                    = "llvm_build_mul"
1360
1361 (** [build_fmul x y name b] creates a
1362     [%name = fmul %x, %y]
1363     instruction at the position specified by the instruction builder [b].
1364     See the method [llvm::LLVMBuilder::CreateFMul]. *)
1365 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1366                     = "llvm_build_fmul"
1367
1368 (** [build_udiv x y name b] creates a
1369     [%name = udiv %x, %y]
1370     instruction at the position specified by the instruction builder [b].
1371     See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1372 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1373                     = "llvm_build_udiv"
1374
1375 (** [build_sdiv x y name b] creates a
1376     [%name = sdiv %x, %y]
1377     instruction at the position specified by the instruction builder [b].
1378     See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1379 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1380                     = "llvm_build_sdiv"
1381
1382 (** [build_exact_sdiv x y name b] creates a
1383     [%name = exact sdiv %x, %y]
1384     instruction at the position specified by the instruction builder [b].
1385     See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1386 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1387                           = "llvm_build_exact_sdiv"
1388
1389 (** [build_fdiv x y name b] creates a
1390     [%name = fdiv %x, %y]
1391     instruction at the position specified by the instruction builder [b].
1392     See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1393 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1394                     = "llvm_build_fdiv"
1395
1396 (** [build_urem x y name b] creates a
1397     [%name = urem %x, %y]
1398     instruction at the position specified by the instruction builder [b].
1399     See the method [llvm::LLVMBuilder::CreateURem]. *)
1400 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1401                     = "llvm_build_urem"
1402
1403 (** [build_SRem x y name b] creates a
1404     [%name = srem %x, %y]
1405     instruction at the position specified by the instruction builder [b].
1406     See the method [llvm::LLVMBuilder::CreateSRem]. *)
1407 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1408                     = "llvm_build_srem"
1409
1410 (** [build_frem x y name b] creates a
1411     [%name = frem %x, %y]
1412     instruction at the position specified by the instruction builder [b].
1413     See the method [llvm::LLVMBuilder::CreateFRem]. *)
1414 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1415                     = "llvm_build_frem"
1416
1417 (** [build_shl x y name b] creates a
1418     [%name = shl %x, %y]
1419     instruction at the position specified by the instruction builder [b].
1420     See the method [llvm::LLVMBuilder::CreateShl]. *)
1421 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1422                    = "llvm_build_shl"
1423
1424 (** [build_lshr x y name b] creates a
1425     [%name = lshr %x, %y]
1426     instruction at the position specified by the instruction builder [b].
1427     See the method [llvm::LLVMBuilder::CreateLShr]. *)
1428 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1429                     = "llvm_build_lshr"
1430
1431 (** [build_ashr x y name b] creates a
1432     [%name = ashr %x, %y]
1433     instruction at the position specified by the instruction builder [b].
1434     See the method [llvm::LLVMBuilder::CreateAShr]. *)
1435 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1436                     = "llvm_build_ashr"
1437
1438 (** [build_and x y name b] creates a
1439     [%name = and %x, %y]
1440     instruction at the position specified by the instruction builder [b].
1441     See the method [llvm::LLVMBuilder::CreateAnd]. *)
1442 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1443                    = "llvm_build_and"
1444
1445 (** [build_or x y name b] creates a
1446     [%name = or %x, %y]
1447     instruction at the position specified by the instruction builder [b].
1448     See the method [llvm::LLVMBuilder::CreateOr]. *)
1449 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1450                   = "llvm_build_or"
1451
1452 (** [build_xor x y name b] creates a
1453     [%name = xor %x, %y]
1454     instruction at the position specified by the instruction builder [b].
1455     See the method [llvm::LLVMBuilder::CreateXor]. *)
1456 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1457                    = "llvm_build_xor"
1458
1459 (** [build_neg x name b] creates a
1460     [%name = sub 0, %x]
1461     instruction at the position specified by the instruction builder [b].
1462     [-0.0] is used for floating point types to compute the correct sign.
1463     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1464 external build_neg : llvalue -> string -> llbuilder -> llvalue
1465                    = "llvm_build_neg"
1466
1467 (** [build_xor x name b] creates a
1468     [%name = xor %x, -1]
1469     instruction at the position specified by the instruction builder [b].
1470     [-1] is the correct "all ones" value for the type of [x].
1471     See the method [llvm::LLVMBuilder::CreateXor]. *)
1472 external build_not : llvalue -> string -> llbuilder -> llvalue
1473                    = "llvm_build_not"
1474
1475
1476 (** {7 Memory} *)
1477
1478 (** [build_malloc ty name b] creates a
1479     [%name = malloc %ty]
1480     instruction at the position specified by the instruction builder [b].
1481     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1482 external build_malloc : lltype -> string -> llbuilder -> llvalue
1483                       = "llvm_build_malloc"
1484
1485 (** [build_array_malloc ty n name b] creates a
1486     [%name = malloc %ty, %n]
1487     instruction at the position specified by the instruction builder [b].
1488     See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1489 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1490                               llvalue = "llvm_build_array_malloc"
1491
1492 (** [build_alloca ty name b] creates a
1493     [%name = alloca %ty]
1494     instruction at the position specified by the instruction builder [b].
1495     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1496 external build_alloca : lltype -> string -> llbuilder -> llvalue
1497                       = "llvm_build_alloca"
1498
1499 (** [build_array_alloca ty n name b] creates a
1500     [%name = alloca %ty, %n]
1501     instruction at the position specified by the instruction builder [b].
1502     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1503 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1504                               llvalue = "llvm_build_array_alloca"
1505
1506 (** [build_free v b] creates a
1507     [free %v]
1508     instruction at the position specified by the instruction builder [b].
1509     See the method [llvm::LLVMBuilder::CreateFree]. *)
1510 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1511
1512 (** [build_load v name b] creates a
1513     [%name = load %v]
1514     instruction at the position specified by the instruction builder [b].
1515     See the method [llvm::LLVMBuilder::CreateLoad]. *)
1516 external build_load : llvalue -> string -> llbuilder -> llvalue
1517                     = "llvm_build_load"
1518
1519 (** [build_store v p b] creates a
1520     [store %v, %p]
1521     instruction at the position specified by the instruction builder [b].
1522     See the method [llvm::LLVMBuilder::CreateStore]. *)
1523 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1524                      = "llvm_build_store"
1525
1526 (** [build_gep p indices name b] creates a
1527     [%name = getelementptr %p, indices...]
1528     instruction at the position specified by the instruction builder [b].
1529     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1530 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1531                    = "llvm_build_gep"
1532
1533 (** [build_in_bounds_gep p indices name b] creates a
1534     [%name = gelementptr inbounds %p, indices...]
1535     instruction at the position specified by the instruction builder [b].
1536     See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1537 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1538                                llvalue = "llvm_build_in_bounds_gep"
1539
1540 (** [build_struct_gep p idx name b] creates a
1541     [%name = getelementptr %p, 0, idx]
1542     instruction at the position specified by the instruction builder [b].
1543     See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1544 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1545                             llvalue = "llvm_build_struct_gep"
1546
1547 (** [build_global_string str name b] creates a series of instructions that adds
1548     a global string at the position specified by the instruction builder [b].
1549     See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1550 external build_global_string : string -> string -> llbuilder -> llvalue
1551                              = "llvm_build_global_string"
1552
1553 (** [build_global_stringptr str name b] creates a series of instructions that
1554     adds a global string pointer at the position specified by the instruction
1555                 builder [b].
1556     See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1557 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1558                                 = "llvm_build_global_stringptr"
1559
1560
1561 (** {7 Casts} *)
1562
1563 (** [build_trunc v ty name b] creates a
1564     [%name = trunc %p to %ty]
1565     instruction at the position specified by the instruction builder [b].
1566     See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1567 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1568                      = "llvm_build_trunc"
1569
1570 (** [build_zext v ty name b] creates a
1571     [%name = zext %p to %ty]
1572     instruction at the position specified by the instruction builder [b].
1573     See the method [llvm::LLVMBuilder::CreateZExt]. *)
1574 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1575                     = "llvm_build_zext"
1576
1577 (** [build_sext v ty name b] creates a
1578     [%name = sext %p to %ty]
1579     instruction at the position specified by the instruction builder [b].
1580     See the method [llvm::LLVMBuilder::CreateSExt]. *)
1581 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1582                     = "llvm_build_sext"
1583
1584 (** [build_fptoui v ty name b] creates a
1585     [%name = fptoui %p to %ty]
1586     instruction at the position specified by the instruction builder [b].
1587     See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1588 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1589                       = "llvm_build_fptoui"
1590
1591 (** [build_fptosi v ty name b] creates a
1592     [%name = fptosi %p to %ty]
1593     instruction at the position specified by the instruction builder [b].
1594     See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1595 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1596                       = "llvm_build_fptosi"
1597
1598 (** [build_uitofp v ty name b] creates a
1599     [%name = uitofp %p to %ty]
1600     instruction at the position specified by the instruction builder [b].
1601     See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1602 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1603                       = "llvm_build_uitofp"
1604
1605 (** [build_sitofp v ty name b] creates a
1606     [%name = sitofp %p to %ty]
1607     instruction at the position specified by the instruction builder [b].
1608     See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1609 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1610                       = "llvm_build_sitofp"
1611
1612 (** [build_fptrunc v ty name b] creates a
1613     [%name = fptrunc %p to %ty]
1614     instruction at the position specified by the instruction builder [b].
1615     See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1616 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1617                        = "llvm_build_fptrunc"
1618
1619 (** [build_fpext v ty name b] creates a
1620     [%name = fpext %p to %ty]
1621     instruction at the position specified by the instruction builder [b].
1622     See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1623 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1624                      = "llvm_build_fpext"
1625
1626 (** [build_ptrtoint v ty name b] creates a
1627     [%name = prtotint %p to %ty]
1628     instruction at the position specified by the instruction builder [b].
1629     See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1630 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1631                         = "llvm_build_prttoint"
1632
1633 (** [build_inttoptr v ty name b] creates a
1634     [%name = inttoptr %p to %ty]
1635     instruction at the position specified by the instruction builder [b].
1636     See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1637 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1638                         = "llvm_build_inttoptr"
1639
1640 (** [build_bitcast v ty name b] creates a
1641     [%name = bitcast %p to %ty]
1642     instruction at the position specified by the instruction builder [b].
1643     See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1644 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1645                        = "llvm_build_bitcast"
1646
1647 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1648     instruction at the position specified by the instruction builder [b].
1649     See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1650 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1651                                  llvalue = "llvm_build_zext_or_bitcast"
1652
1653 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1654     instruction at the position specified by the instruction builder [b].
1655     See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1656 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1657                                  llvalue = "llvm_build_sext_or_bitcast"
1658
1659 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1660     instruction at the position specified by the instruction builder [b].
1661     See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1662 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1663                                   llvalue = "llvm_build_trunc_or_bitcast"
1664
1665 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1666     instruction at the position specified by the instruction builder [b].
1667     See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1668 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1669                            = "llvm_build_pointercast"
1670
1671 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1672     instruction at the position specified by the instruction builder [b].
1673     See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1674 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1675                        = "llvm_build_intcast"
1676
1677 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1678     instruction at the position specified by the instruction builder [b].
1679     See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1680 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1681                       = "llvm_build_fpcast"
1682
1683
1684 (** {7 Comparisons} *)
1685
1686 (** [build_icmp pred x y name b] creates a
1687     [%name = icmp %pred %x, %y]
1688     instruction at the position specified by the instruction builder [b].
1689     See the method [llvm::LLVMBuilder::CreateICmp]. *)
1690 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1691                       llbuilder -> llvalue = "llvm_build_icmp"
1692
1693 (** [build_fcmp pred x y name b] creates a
1694     [%name = fcmp %pred %x, %y]
1695     instruction at the position specified by the instruction builder [b].
1696     See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1697 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1698                       llbuilder -> llvalue = "llvm_build_fcmp"
1699
1700
1701 (** {7 Miscellaneous instructions} *)
1702
1703 (** [build_phi incoming name b] creates a
1704     [%name = phi %incoming]
1705     instruction at the position specified by the instruction builder [b].
1706     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1707     See the method [llvm::LLVMBuilder::CreatePHI]. *)
1708 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1709                      llvalue = "llvm_build_phi"
1710
1711 (** [build_call fn args name b] creates a
1712     [%name = call %fn(args...)]
1713     instruction at the position specified by the instruction builder [b].
1714     See the method [llvm::LLVMBuilder::CreateCall]. *)
1715 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1716                     = "llvm_build_call"
1717
1718 (** [build_select cond thenv elsev name b] creates a
1719     [%name = select %cond, %thenv, %elsev]
1720     instruction at the position specified by the instruction builder [b].
1721     See the method [llvm::LLVMBuilder::CreateSelect]. *)
1722 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1723                         llvalue = "llvm_build_select"
1724
1725 (** [build_va_arg valist argty name b] creates a
1726     [%name = va_arg %valist, %argty]
1727     instruction at the position specified by the instruction builder [b].
1728     See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1729 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1730                       = "llvm_build_va_arg"
1731
1732 (** [build_extractelement vec i name b] creates a
1733     [%name = extractelement %vec, %i]
1734     instruction at the position specified by the instruction builder [b].
1735     See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1736 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1737                                 llvalue = "llvm_build_extractelement"
1738
1739 (** [build_insertelement vec elt i name b] creates a
1740     [%name = insertelement %vec, %elt, %i]
1741     instruction at the position specified by the instruction builder [b].
1742     See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1743 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1744                                llbuilder -> llvalue = "llvm_build_insertelement"
1745
1746 (** [build_shufflevector veca vecb mask name b] creates a
1747     [%name = shufflevector %veca, %vecb, %mask]
1748     instruction at the position specified by the instruction builder [b].
1749     See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1750 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1751                                llbuilder -> llvalue = "llvm_build_shufflevector"
1752
1753 (** [build_insertvalue agg idx name b] creates a
1754     [%name = extractvalue %agg, %idx]
1755     instruction at the position specified by the instruction builder [b].
1756     See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1757 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1758                             = "llvm_build_extractvalue"
1759
1760 (** [build_insertvalue agg val idx name b] creates a
1761     [%name = insertvalue %agg, %val, %idx]
1762     instruction at the position specified by the instruction builder [b].
1763     See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1764 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1765                              llvalue = "llvm_build_insertvalue"
1766
1767 (** [build_is_null val name b] creates a
1768     [%name = icmp eq %val, null]
1769     instruction at the position specified by the instruction builder [b].
1770     See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1771 external build_is_null : llvalue -> string -> llbuilder -> llvalue
1772                        = "llvm_build_is_null"
1773
1774 (** [build_is_not_null val name b] creates a
1775     [%name = icmp ne %val, null]
1776     instruction at the position specified by the instruction builder [b].
1777     See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1778 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1779                            = "llvm_build_is_not_null"
1780
1781 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1782     the difference between two pointer values at the position specified by the
1783                 instruction builder [b].
1784     See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1785 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1786                        = "llvm_build_ptrdiff"
1787
1788 (** {6 Module providers} *)
1789
1790 module ModuleProvider : sig
1791   (** [create_module_provider m] encapsulates [m] in a module provider and takes
1792       ownership of the module. See the constructor
1793       [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1794   external create : llmodule -> llmoduleprovider
1795                   = "LLVMCreateModuleProviderForExistingModule"
1796   
1797   (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1798       the contained module. *)
1799   external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1800 end
1801
1802
1803 (** {6 Memory buffers} *)
1804
1805 module MemoryBuffer : sig
1806   (** [of_file p] is the memory buffer containing the contents of the file at
1807       path [p]. If the file could not be read, then [IoError msg] is
1808       raised. *)
1809   external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1810   
1811   (** [stdin ()] is the memory buffer containing the contents of standard input.
1812       If standard input is empty, then [IoError msg] is raised. *)
1813   external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1814   
1815   (** Disposes of a memory buffer. *)
1816   external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1817 end
1818
1819
1820 (** {6 Pass Managers} *)
1821
1822 module PassManager : sig
1823   (**  *)
1824   type 'a t
1825   type any = [ `Module | `Function ]
1826   
1827   (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1828       type of pipeline is suitable for link-time optimization and whole-module
1829       transformations.
1830       See the constructor of [llvm::PassManager]. *)
1831   external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1832   
1833   (** [PassManager.create_function mp] constructs a new function-by-function
1834       pass pipeline over the module provider [mp]. It does not take ownership of
1835       [mp]. This type of pipeline is suitable for code generation and JIT
1836       compilation tasks.
1837       See the constructor of [llvm::FunctionPassManager]. *)
1838   external create_function : llmoduleprovider -> [ `Function ] t
1839                            = "LLVMCreateFunctionPassManager"
1840   
1841   (** [run_module m pm] initializes, executes on the module [m], and finalizes
1842       all of the passes scheduled in the pass manager [pm]. Returns [true] if
1843       any of the passes modified the module, [false] otherwise.
1844       See the [llvm::PassManager::run] method. *)
1845   external run_module : llmodule -> [ `Module ] t -> bool
1846                       = "llvm_passmanager_run_module"
1847   
1848   (** [initialize fpm] initializes all of the function passes scheduled in the
1849       function pass manager [fpm]. Returns [true] if any of the passes modified
1850       the module, [false] otherwise.
1851       See the [llvm::FunctionPassManager::doInitialization] method. *)
1852   external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1853   
1854   (** [run_function f fpm] executes all of the function passes scheduled in the
1855       function pass manager [fpm] over the function [f]. Returns [true] if any
1856       of the passes modified [f], [false] otherwise.
1857       See the [llvm::FunctionPassManager::run] method. *)
1858   external run_function : llvalue -> [ `Function ] t -> bool
1859                         = "llvm_passmanager_run_function"
1860   
1861   (** [finalize fpm] finalizes all of the function passes scheduled in in the
1862       function pass manager [fpm]. Returns [true] if any of the passes
1863       modified the module, [false] otherwise.
1864       See the [llvm::FunctionPassManager::doFinalization] method. *)
1865   external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1866   
1867   (** Frees the memory of a pass pipeline. For function pipelines, does not free
1868       the module provider.
1869       See the destructor of [llvm::BasePassManager]. *)
1870   external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"
1871 end