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