Delete a redundant binding, LLVMHasInitializer.
[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 (** [global_initializer gv] returns the initializer for the global variable
819     [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
820 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
821
822 (** [set_initializer c gv] sets the initializer for the global variable
823     [gv] to the constant [c].
824     See the method [llvm::GlobalVariable::setInitializer]. *)
825 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
826
827 (** [remove_initializer gv] unsets the initializer for the global variable
828     [gv].
829     See the method [llvm::GlobalVariable::setInitializer]. *)
830 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
831
832 (** [is_thread_local gv] returns [true] if the global variable [gv] is
833     thread-local and [false] otherwise.
834     See the method [llvm::GlobalVariable::isThreadLocal]. *)
835 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
836
837 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
838     [c] is [true] and not otherwise.
839     See the method [llvm::GlobalVariable::setThreadLocal]. *)
840 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
841
842
843 (** {7 Operations on functions} *)
844
845 (** [declare_function name ty m] returns a new function of type [ty] and
846     with name [name] in module [m]. If such a function already exists,
847     it is returned. If the type of the existing function differs, then a bitcast
848     to [ty] is returned. *)
849 external declare_function : string -> lltype -> llmodule -> llvalue
850                           = "llvm_declare_function"
851
852 (** [define_function name ty m] creates a new function with name [name] and
853     type [ty] in module [m]. If the named function already exists, it is
854     renamed. An entry basic block is created in the function.
855     See the constructor of [llvm::GlobalVariable]. *)
856 external define_function : string -> lltype -> llmodule -> llvalue
857                          = "llvm_define_function"
858
859 (** [lookup_function name m] returns [Some f] if a function with name
860     [name] exists in module [m]. If no such function exists, returns [None].
861     See the method [llvm::Module] constructor. *)
862 external lookup_function : string -> llmodule -> llvalue option
863                          = "llvm_lookup_function"
864
865 (** [delete_function f] destroys the function [f].
866     See the method [llvm::Function::eraseFromParent]. *)
867 external delete_function : llvalue -> unit = "llvm_delete_function"
868
869 (** [function_begin m] returns the first position in the function list of the
870     module [m]. [function_begin] and [function_succ] can be used to iterate over
871     the function list in order.
872     See the method [llvm::Module::begin]. *)
873 external function_begin : llmodule -> (llmodule, llvalue) llpos
874                         = "llvm_function_begin"
875
876 (** [function_succ gv] returns the function list position succeeding
877     [Before gv].
878     See the method [llvm::Module::iterator::operator++]. *)
879 external function_succ : llvalue -> (llmodule, llvalue) llpos
880                        = "llvm_function_succ"
881
882 (** [iter_functions f m] applies function [f] to each of the functions of module
883     [m] in order. Tail recursive. *)
884 val iter_functions : (llvalue -> unit) -> llmodule -> unit
885
886 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
887     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
888 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
889
890 (** [function_end m] returns the last position in the function list of
891     the module [m]. [function_end] and [function_pred] can be used to iterate
892     over the function list in reverse.
893     See the method [llvm::Module::end]. *)
894 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
895                       = "llvm_function_end"
896
897 (** [function_pred gv] returns the function list position preceding [After gv].
898     See the method [llvm::Module::iterator::operator--]. *)
899 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
900                        = "llvm_function_pred"
901
902 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
903     module [m] in reverse order. Tail recursive. *)
904 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
905
906 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
907     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
908 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
909
910 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
911     See the method [llvm::Function::isIntrinsic]. *)
912 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
913
914 (** [function_call_conv f] returns the calling convention of the function [f].
915     See the method [llvm::Function::getCallingConv]. *)
916 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
917
918 (** [set_function_call_conv cc f] sets the calling convention of the function
919     [f] to the calling convention numbered [cc].
920     See the method [llvm::Function::setCallingConv]. *)
921 external set_function_call_conv : int -> llvalue -> unit
922                                 = "llvm_set_function_call_conv"
923
924 (** [collector f] returns [Some name] if the function [f] has a garbage
925     collection algorithm specified and [None] otherwise.
926     See the method [llvm::Function::getCollector]. *)
927 external collector : llvalue -> string option = "llvm_collector"
928
929 (** [set_collector gc f] sets the collection algorithm for the function [f] to
930     [gc]. See the method [llvm::Function::setCollector]. *)
931 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
932
933
934 (** {7 Operations on params} *)
935
936 (** [params f] returns the parameters of function [f].
937     See the method [llvm::Function::getArgumentList]. *)
938 external params : llvalue -> llvalue array = "llvm_params"
939
940 (** [param f n] returns the [n]th parameter of function [f].
941     See the method [llvm::Function::getArgumentList]. *)
942 external param : llvalue -> int -> llvalue = "llvm_param"
943
944 (** [param_parent p] returns the parent function that owns the parameter.
945     See the method [llvm::Argument::getParent]. *)
946 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
947
948 (** [param_begin f] returns the first position in the parameter list of the
949     function [f]. [param_begin] and [param_succ] can be used to iterate over
950     the parameter list in order.
951     See the method [llvm::Function::arg_begin]. *)
952 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
953
954 (** [param_succ bb] returns the parameter list position succeeding
955     [Before bb].
956     See the method [llvm::Function::arg_iterator::operator++]. *)
957 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
958
959 (** [iter_params f fn] applies function [f] to each of the parameters
960     of function [fn] in order. Tail recursive. *)
961 val iter_params : (llvalue -> unit) -> llvalue -> unit
962
963 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
964     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
965 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
966
967 (** [param_end f] returns the last position in the parameter list of
968     the function [f]. [param_end] and [param_pred] can be used to iterate
969     over the parameter list in reverse.
970     See the method [llvm::Function::arg_end]. *)
971 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
972
973 (** [param_pred gv] returns the function list position preceding [After gv].
974     See the method [llvm::Function::arg_iterator::operator--]. *)
975 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
976                     = "llvm_param_pred"
977
978 (** [rev_iter_params f fn] applies function [f] to each of the parameters
979     of function [fn] in reverse order. Tail recursive. *)
980 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
981
982 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
983     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
984 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
985
986
987 (** {7 Operations on basic blocks} *)
988
989 (** [basic_blocks fn] returns the basic blocks of the function [f].
990     See the method [llvm::Function::getBasicBlockList]. *)
991 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
992
993 (** [entry_block fn] returns the entry basic block of the function [f].
994     See the method [llvm::Function::getEntryBlock]. *)
995 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
996
997 (** [delete_block bb] deletes the basic block [bb].
998     See the method [llvm::BasicBlock::eraseFromParent]. *)
999 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1000
1001 (** [append_block name f] creates a new basic block named [name] at the end of
1002     function [f].
1003     See the constructor of [llvm::BasicBlock]. *)
1004 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1005
1006 (** [insert_block name bb] creates a new basic block named [name] before the
1007     basic block [bb].
1008     See the constructor of [llvm::BasicBlock]. *)
1009 external insert_block : string -> llbasicblock -> llbasicblock
1010                       = "llvm_insert_block"
1011
1012 (** [block_parent bb] returns the parent function that owns the basic block.
1013     See the method [llvm::BasicBlock::getParent]. *)
1014 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1015
1016 (** [block_begin f] returns the first position in the basic block list of the
1017     function [f]. [block_begin] and [block_succ] can be used to iterate over
1018     the basic block list in order.
1019     See the method [llvm::Function::begin]. *)
1020 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1021                      = "llvm_block_begin"
1022
1023 (** [block_succ bb] returns the basic block list position succeeding
1024     [Before bb].
1025     See the method [llvm::Function::iterator::operator++]. *)
1026 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1027                     = "llvm_block_succ"
1028
1029 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1030     of function [fn] in order. Tail recursive. *)
1031 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1032
1033 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1034     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1035 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1036
1037 (** [block_end f] returns the last position in the basic block list of
1038     the function [f]. [block_end] and [block_pred] can be used to iterate
1039     over the basic block list in reverse.
1040     See the method [llvm::Function::end]. *)
1041 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1042                    = "llvm_block_end"
1043
1044 (** [block_pred gv] returns the function list position preceding [After gv].
1045     See the method [llvm::Function::iterator::operator--]. *)
1046 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1047                     = "llvm_block_pred"
1048
1049 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1050     of function [fn] in reverse order. Tail recursive. *)
1051 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1052
1053 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1054     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1055 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1056
1057 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1058 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1059
1060 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1061     [false] otherwise.
1062     Similar to [llvm::isa<BasicBlock>]. *)
1063 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1064
1065 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1066 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1067
1068
1069 (** {7 Operations on instructions} *)
1070
1071 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1072     See the method [llvm::Instruction::getParent]. *)
1073 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1074
1075 (** [instr_begin bb] returns the first position in the instruction list of the
1076     basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1077     the instruction list in order.
1078     See the method [llvm::BasicBlock::begin]. *)
1079 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1080                      = "llvm_instr_begin"
1081
1082 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1083     See the method [llvm::BasicBlock::iterator::operator++]. *)
1084 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1085                      = "llvm_instr_succ"
1086
1087 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1088     block [bb] in order. Tail recursive. *)
1089 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1090
1091 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1092     [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1093 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1094
1095 (** [instr_end bb] returns the last position in the instruction list of the
1096     basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1097     the instruction list in reverse.
1098     See the method [llvm::BasicBlock::end]. *)
1099 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1100                      = "llvm_instr_end"
1101
1102 (** [instr_pred i] returns the instruction list position preceding [After i].
1103     See the method [llvm::BasicBlock::iterator::operator--]. *)
1104 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1105                      = "llvm_instr_pred"
1106
1107 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1108     [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1109 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1110
1111
1112 (** {7 Operations on call sites} *)
1113
1114 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1115     instruction [ci], which may be one of the values from the module
1116     {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1117     [llvm::InvokeInst::getCallingConv]. *)
1118 external instruction_call_conv: llvalue -> int
1119                               = "llvm_instruction_call_conv"
1120
1121 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1122     or invoke instruction [ci] to the integer [cc], which can be one of the
1123     values from the module {!CallConv}.
1124     See the method [llvm::CallInst::setCallingConv]
1125     and [llvm::InvokeInst::setCallingConv]. *)
1126 external set_instruction_call_conv: int -> llvalue -> unit
1127                                   = "llvm_set_instruction_call_conv"
1128
1129
1130 (** {7 Operations on phi nodes} *)
1131
1132 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1133     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1134 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1135                       = "llvm_add_incoming"
1136
1137 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1138     See the method [llvm::PHINode::getIncomingValue]. *)
1139 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1140
1141
1142
1143 (** {6 Instruction builders} *)
1144
1145 (** [builder ()] creates an instruction builder with no position. It is invalid
1146     to use this builder until its position is set with {!position_before} or
1147     {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
1148 external builder : unit -> llbuilder = "llvm_builder"
1149
1150 (** [builder_at ip] creates an instruction builder positioned at [ip].
1151     See the constructor for [llvm::LLVMBuilder]. *)
1152 val builder_at : (llbasicblock, llvalue) llpos -> llbuilder
1153
1154 (** [builder_before ins] creates an instruction builder positioned before the
1155     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1156 val builder_before : llvalue -> llbuilder
1157
1158 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1159     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1160 val builder_at_end : llbasicblock -> llbuilder
1161
1162 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1163     [ip].
1164     See the constructor for [llvm::LLVMBuilder]. *)
1165 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1166                           = "llvm_position_builder"
1167
1168 (** [position_before ins b] moves the instruction builder [b] to before the
1169     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1170 val position_before : llvalue -> llbuilder -> unit
1171
1172 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1173     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1174 val position_at_end : llbasicblock -> llbuilder -> unit
1175
1176 (** [insertion_block b] returns the basic block that the builder [b] is
1177     positioned to insert into. Raises [Not_Found] if the instruction builder is
1178     uninitialized.
1179     See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1180 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1181
1182
1183 (** {7 Terminators} *)
1184
1185 (** [build_ret_void b] creates a
1186     [ret void]
1187     instruction at the position specified by the instruction builder [b].
1188     See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1189 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1190
1191 (** [build_ret v b] creates a
1192     [ret %v]
1193     instruction at the position specified by the instruction builder [b].
1194     See the method [llvm::LLVMBuilder::CreateRet]. *)
1195 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1196
1197 (** [build_br bb b] creates a
1198     [b %bb]
1199     instruction at the position specified by the instruction builder [b].
1200     See the method [llvm::LLVMBuilder::CreateBr]. *)
1201 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1202
1203 (** [build_cond_br cond tbb fbb b] creates a
1204     [b %cond, %tbb, %fbb]
1205     instruction at the position specified by the instruction builder [b].
1206     See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1207 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1208                          llvalue = "llvm_build_cond_br"
1209
1210 (** [build_switch case elsebb count b] creates an empty
1211     [switch %case, %elsebb]
1212     instruction at the position specified by the instruction builder [b] with
1213     space reserved for [count] cases.
1214     See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1215 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1216                       = "llvm_build_switch"
1217
1218 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1219     when its input matches the constant [onval].
1220     See the method [llvm::SwitchInst::addCase]. **)
1221 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1222                   = "llvm_add_case"
1223
1224 (** [build_invoke fn args tobb unwindbb name b] creates an
1225     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1226     instruction at the position specified by the instruction builder [b].
1227     See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1228 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1229                         llbasicblock -> string -> llbuilder -> llvalue
1230                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1231
1232 (** [build_unwind b] creates an
1233     [unwind]
1234     instruction at the position specified by the instruction builder [b].
1235     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1236 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1237
1238 (** [build_unreachable b] creates an
1239     [unreachable]
1240     instruction at the position specified by the instruction builder [b].
1241     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1242 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1243
1244
1245 (** {7 Arithmetic} *)
1246
1247 (** [build_add x y name b] creates a
1248     [%name = add %x, %y]
1249     instruction at the position specified by the instruction builder [b].
1250     See the method [llvm::LLVMBuilder::CreateAdd]. *)
1251 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1252                    = "llvm_build_add"
1253
1254 (** [build_sub x y name b] creates a
1255     [%name = sub %x, %y]
1256     instruction at the position specified by the instruction builder [b].
1257     See the method [llvm::LLVMBuilder::CreateSub]. *)
1258 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1259                    = "llvm_build_sub"
1260
1261 (** [build_mul x y name b] creates a
1262     [%name = mul %x, %y]
1263     instruction at the position specified by the instruction builder [b].
1264     See the method [llvm::LLVMBuilder::CreateMul]. *)
1265 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1266                    = "llvm_build_mul"
1267
1268 (** [build_udiv x y name b] creates a
1269     [%name = udiv %x, %y]
1270     instruction at the position specified by the instruction builder [b].
1271     See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1272 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1273                     = "llvm_build_udiv"
1274
1275 (** [build_sdiv x y name b] creates a
1276     [%name = sdiv %x, %y]
1277     instruction at the position specified by the instruction builder [b].
1278     See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1279 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1280                     = "llvm_build_sdiv"
1281
1282 (** [build_fdiv x y name b] creates a
1283     [%name = fdiv %x, %y]
1284     instruction at the position specified by the instruction builder [b].
1285     See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1286 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1287                     = "llvm_build_fdiv"
1288
1289 (** [build_urem x y name b] creates a
1290     [%name = urem %x, %y]
1291     instruction at the position specified by the instruction builder [b].
1292     See the method [llvm::LLVMBuilder::CreateURem]. *)
1293 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1294                     = "llvm_build_urem"
1295
1296 (** [build_SRem x y name b] creates a
1297     [%name = srem %x, %y]
1298     instruction at the position specified by the instruction builder [b].
1299     See the method [llvm::LLVMBuilder::CreateSRem]. *)
1300 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1301                     = "llvm_build_srem"
1302
1303 (** [build_frem x y name b] creates a
1304     [%name = frem %x, %y]
1305     instruction at the position specified by the instruction builder [b].
1306     See the method [llvm::LLVMBuilder::CreateFRem]. *)
1307 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1308                     = "llvm_build_frem"
1309
1310 (** [build_shl x y name b] creates a
1311     [%name = shl %x, %y]
1312     instruction at the position specified by the instruction builder [b].
1313     See the method [llvm::LLVMBuilder::CreateShl]. *)
1314 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1315                    = "llvm_build_shl"
1316
1317 (** [build_lshr x y name b] creates a
1318     [%name = lshr %x, %y]
1319     instruction at the position specified by the instruction builder [b].
1320     See the method [llvm::LLVMBuilder::CreateLShr]. *)
1321 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1322                     = "llvm_build_lshr"
1323
1324 (** [build_ashr x y name b] creates a
1325     [%name = ashr %x, %y]
1326     instruction at the position specified by the instruction builder [b].
1327     See the method [llvm::LLVMBuilder::CreateAShr]. *)
1328 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1329                     = "llvm_build_ashr"
1330
1331 (** [build_and x y name b] creates a
1332     [%name = and %x, %y]
1333     instruction at the position specified by the instruction builder [b].
1334     See the method [llvm::LLVMBuilder::CreateAnd]. *)
1335 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1336                    = "llvm_build_and"
1337
1338 (** [build_or x y name b] creates a
1339     [%name = or %x, %y]
1340     instruction at the position specified by the instruction builder [b].
1341     See the method [llvm::LLVMBuilder::CreateOr]. *)
1342 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1343                   = "llvm_build_or"
1344
1345 (** [build_xor x y name b] creates a
1346     [%name = xor %x, %y]
1347     instruction at the position specified by the instruction builder [b].
1348     See the method [llvm::LLVMBuilder::CreateXor]. *)
1349 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1350                    = "llvm_build_xor"
1351
1352 (** [build_neg x name b] creates a
1353     [%name = sub 0, %x]
1354     instruction at the position specified by the instruction builder [b].
1355     [-0.0] is used for floating point types to compute the correct sign.
1356     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1357 external build_neg : llvalue -> string -> llbuilder -> llvalue
1358                    = "llvm_build_neg"
1359
1360 (** [build_xor x name b] creates a
1361     [%name = xor %x, -1]
1362     instruction at the position specified by the instruction builder [b].
1363     [-1] is the correct "all ones" value for the type of [x].
1364     See the method [llvm::LLVMBuilder::CreateXor]. *)
1365 external build_not : llvalue -> string -> llbuilder -> llvalue
1366                    = "llvm_build_not"
1367
1368
1369 (** {7 Memory} *)
1370
1371 (** [build_malloc ty name b] creates a
1372     [%name = malloc %ty]
1373     instruction at the position specified by the instruction builder [b].
1374     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1375 external build_malloc : lltype -> string -> llbuilder -> llvalue
1376                       = "llvm_build_malloc"
1377
1378 (** [build_array_malloc ty n name b] creates a
1379     [%name = malloc %ty, %n]
1380     instruction at the position specified by the instruction builder [b].
1381     See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1382 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1383                               llvalue = "llvm_build_array_malloc"
1384
1385 (** [build_alloca ty name b] creates a
1386     [%name = alloca %ty]
1387     instruction at the position specified by the instruction builder [b].
1388     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1389 external build_alloca : lltype -> string -> llbuilder -> llvalue
1390                       = "llvm_build_alloca"
1391
1392 (** [build_array_alloca ty n name b] creates a
1393     [%name = alloca %ty, %n]
1394     instruction at the position specified by the instruction builder [b].
1395     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1396 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1397                               llvalue = "llvm_build_array_alloca"
1398
1399 (** [build_free v b] creates a
1400     [free %v]
1401     instruction at the position specified by the instruction builder [b].
1402     See the method [llvm::LLVMBuilder::CreateFree]. *)
1403 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1404
1405 (** [build_load v name b] creates a
1406     [%name = load %v]
1407     instruction at the position specified by the instruction builder [b].
1408     See the method [llvm::LLVMBuilder::CreateLoad]. *)
1409 external build_load : llvalue -> string -> llbuilder -> llvalue
1410                     = "llvm_build_load"
1411
1412 (** [build_store v p b] creates a
1413     [store %v, %p]
1414     instruction at the position specified by the instruction builder [b].
1415     See the method [llvm::LLVMBuilder::CreateStore]. *)
1416 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1417                      = "llvm_build_store"
1418
1419 (** [build_gep p indices name b] creates a
1420     [%name = gep %p, indices...]
1421     instruction at the position specified by the instruction builder [b].
1422     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1423 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1424                    = "llvm_build_gep"
1425
1426
1427 (** {7 Casts} *)
1428
1429 (** [build_trunc v ty name b] creates a
1430     [%name = trunc %p to %ty]
1431     instruction at the position specified by the instruction builder [b].
1432     See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1433 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1434                      = "llvm_build_trunc"
1435
1436 (** [build_zext v ty name b] creates a
1437     [%name = zext %p to %ty]
1438     instruction at the position specified by the instruction builder [b].
1439     See the method [llvm::LLVMBuilder::CreateZExt]. *)
1440 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1441                     = "llvm_build_zext"
1442
1443 (** [build_sext v ty name b] creates a
1444     [%name = sext %p to %ty]
1445     instruction at the position specified by the instruction builder [b].
1446     See the method [llvm::LLVMBuilder::CreateSExt]. *)
1447 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1448                     = "llvm_build_sext"
1449
1450 (** [build_fptoui v ty name b] creates a
1451     [%name = fptoui %p to %ty]
1452     instruction at the position specified by the instruction builder [b].
1453     See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1454 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1455                       = "llvm_build_fptoui"
1456
1457 (** [build_fptosi v ty name b] creates a
1458     [%name = fptosi %p to %ty]
1459     instruction at the position specified by the instruction builder [b].
1460     See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1461 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1462                       = "llvm_build_fptosi"
1463
1464 (** [build_uitofp v ty name b] creates a
1465     [%name = uitofp %p to %ty]
1466     instruction at the position specified by the instruction builder [b].
1467     See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1468 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1469                       = "llvm_build_uitofp"
1470
1471 (** [build_sitofp v ty name b] creates a
1472     [%name = sitofp %p to %ty]
1473     instruction at the position specified by the instruction builder [b].
1474     See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1475 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1476                       = "llvm_build_sitofp"
1477
1478 (** [build_fptrunc v ty name b] creates a
1479     [%name = fptrunc %p to %ty]
1480     instruction at the position specified by the instruction builder [b].
1481     See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1482 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1483                        = "llvm_build_fptrunc"
1484
1485 (** [build_fpext v ty name b] creates a
1486     [%name = fpext %p to %ty]
1487     instruction at the position specified by the instruction builder [b].
1488     See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1489 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1490                      = "llvm_build_fpext"
1491
1492 (** [build_ptrtoint v ty name b] creates a
1493     [%name = prtotint %p to %ty]
1494     instruction at the position specified by the instruction builder [b].
1495     See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1496 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1497                         = "llvm_build_prttoint"
1498
1499 (** [build_inttoptr v ty name b] creates a
1500     [%name = inttoptr %p to %ty]
1501     instruction at the position specified by the instruction builder [b].
1502     See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1503 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1504                         = "llvm_build_inttoptr"
1505
1506 (** [build_bitcast v ty name b] creates a
1507     [%name = bitcast %p to %ty]
1508     instruction at the position specified by the instruction builder [b].
1509     See the method [llvm::LLVMBuilder::CreateBitcast]. *)
1510 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1511                        = "llvm_build_bitcast"
1512
1513
1514 (** {7 Comparisons} *)
1515
1516 (** [build_icmp pred x y name b] creates a
1517     [%name = icmp %pred %x, %y]
1518     instruction at the position specified by the instruction builder [b].
1519     See the method [llvm::LLVMBuilder::CreateICmp]. *)
1520 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1521                       llbuilder -> llvalue = "llvm_build_icmp"
1522
1523 (** [build_fcmp pred x y name b] creates a
1524     [%name = fcmp %pred %x, %y]
1525     instruction at the position specified by the instruction builder [b].
1526     See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1527 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1528                       llbuilder -> llvalue = "llvm_build_fcmp"
1529
1530
1531 (** {7 Miscellaneous instructions} *)
1532
1533 (** [build_phi incoming name b] creates a
1534     [%name = phi %incoming]
1535     instruction at the position specified by the instruction builder [b].
1536     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1537     See the method [llvm::LLVMBuilder::CreatePHI]. *)
1538 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1539                      llvalue = "llvm_build_phi"
1540
1541 (** [build_call fn args name b] creates a
1542     [%name = call %fn(args...)]
1543     instruction at the position specified by the instruction builder [b].
1544     See the method [llvm::LLVMBuilder::CreateCall]. *)
1545 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1546                     = "llvm_build_call"
1547
1548 (** [build_select cond thenv elsev name b] creates a
1549     [%name = select %cond, %thenv, %elsev]
1550     instruction at the position specified by the instruction builder [b].
1551     See the method [llvm::LLVMBuilder::CreateSelect]. *)
1552 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1553                         llvalue = "llvm_build_select"
1554
1555 (** [build_va_arg valist argty name b] creates a
1556     [%name = va_arg %valist, %argty]
1557     instruction at the position specified by the instruction builder [b].
1558     See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1559 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1560                       = "llvm_build_va_arg"
1561
1562 (** [build_extractelement vec i name b] creates a
1563     [%name = extractelement %vec, %i]
1564     instruction at the position specified by the instruction builder [b].
1565     See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1566 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1567                                 llvalue = "llvm_build_extractelement"
1568
1569 (** [build_insertelement vec elt i name b] creates a
1570     [%name = insertelement %vec, %elt, %i]
1571     instruction at the position specified by the instruction builder [b].
1572     See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1573 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1574                                llbuilder -> llvalue = "llvm_build_insertelement"
1575
1576 (** [build_shufflevector veca vecb mask name b] creates a
1577     [%name = shufflevector %veca, %vecb, %mask]
1578     instruction at the position specified by the instruction builder [b].
1579     See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1580 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1581                                llbuilder -> llvalue = "llvm_build_shufflevector"
1582
1583
1584 (** {6 Module providers} *)
1585
1586 module ModuleProvider : sig
1587   (** [create_module_provider m] encapsulates [m] in a module provider and takes
1588       ownership of the module. See the constructor
1589       [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1590   external create : llmodule -> llmoduleprovider
1591                   = "LLVMCreateModuleProviderForExistingModule"
1592   
1593   (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1594       the contained module. *)
1595   external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1596 end
1597
1598
1599 (** {6 Memory buffers} *)
1600
1601 module MemoryBuffer : sig
1602   (** [of_file p] is the memory buffer containing the contents of the file at
1603       path [p]. If the file could not be read, then [IoError msg] is
1604       raised. *)
1605   external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1606   
1607   (** [stdin ()] is the memory buffer containing the contents of standard input.
1608       If standard input is empty, then [IoError msg] is raised. *)
1609   external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1610   
1611   (** Disposes of a memory buffer. *)
1612   external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1613 end
1614
1615
1616 (** {6 Pass Managers} *)
1617
1618 module PassManager : sig
1619   (**  *)
1620   type 'a t
1621   type any = [ `Module | `Function ]
1622   
1623   (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1624       type of pipeline is suitable for link-time optimization and whole-module
1625       transformations.
1626       See the constructor of [llvm::PassManager]. *)
1627   external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1628   
1629   (** [PassManager.create_function mp] constructs a new function-by-function
1630       pass pipeline over the module provider [mp]. It does not take ownership of
1631       [mp]. This type of pipeline is suitable for code generation and JIT
1632       compilation tasks.
1633       See the constructor of [llvm::FunctionPassManager]. *)
1634   external create_function : llmoduleprovider -> [ `Function ] t
1635                            = "LLVMCreateFunctionPassManager"
1636   
1637   (** [run_module m pm] initializes, executes on the module [m], and finalizes
1638       all of the passes scheduled in the pass manager [pm]. Returns [true] if
1639       any of the passes modified the module, [false] otherwise.
1640       See the [llvm::PassManager::run] method. *)
1641   external run_module : llmodule -> [ `Module ] t -> bool
1642                       = "llvm_passmanager_run_module"
1643   
1644   (** [initialize fpm] initializes all of the function passes scheduled in the
1645       function pass manager [fpm]. Returns [true] if any of the passes modified
1646       the module, [false] otherwise.
1647       See the [llvm::FunctionPassManager::doInitialization] method. *)
1648   external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1649   
1650   (** [run_function f fpm] executes all of the function passes scheduled in the
1651       function pass manager [fpm] over the function [f]. Returns [true] if any
1652       of the passes modified [f], [false] otherwise.
1653       See the [llvm::FunctionPassManager::run] method. *)
1654   external run_function : llvalue -> [ `Function ] t -> bool
1655                         = "llvm_passmanager_run_function"
1656   
1657   (** [finalize fpm] finalizes all of the function passes scheduled in in the
1658       function pass manager [fpm]. Returns [true] if any of the passes
1659       modified the module, [false] otherwise.
1660       See the [llvm::FunctionPassManager::doFinalization] method. *)
1661   external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1662   
1663   (** Frees the memory of a pass pipeline. For function pipelines, does not free
1664       the module provider.
1665       See the destructor of [llvm::BasePassManager]. *)
1666   external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"
1667 end