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