1 (*===-- llvm/llvm.mli - LLVM Ocaml Interface -------------------------------===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*)
12 This interface provides an ocaml API for the LLVM intermediate
13 representation, the classes in the VMCore library. *)
16 (** {6 Abstract types}
18 These abstract types correlate directly to the LLVM VMCore classes. *)
20 (** The top-level container for all other LLVM Intermediate Representation (IR)
21 objects. See the [llvm::Module] class. *)
24 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
25 [llvm::Type] class. *)
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. *)
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. *)
38 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
41 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
45 (** Used to provide a module to JIT or interpreter.
46 See the [llvm::ModuleProvider] class. *)
49 (** Used to efficiently handle large buffers of read-only binary data.
50 See the [llvm::MemoryBuffer] class. *)
53 (** The kind of an [lltype], the result of [classify_type ty]. See the
54 [llvm::Type::TypeID] enumeration. *)
73 (** The linkage of a global value, accessed with {!linkage} and
74 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
88 (** The linker visibility of a global value, accessed with {!visibility} and
89 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
90 module Visibility : sig
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
105 val cold : int (** [cold] is the calling convention for
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. *)
113 (** The predicate for an integer comparison ([icmp]) instruction.
114 See the [llvm::ICmpInst::Predicate] enumeration. *)
129 (** The predicate for a floating-point comparison ([fcmp]) instruction.
130 See the [llvm::FCmpInst::Predicate] enumeration. *)
152 (** {6 Exceptions} *)
154 exception IoError of string
159 (** [create_module id] creates a module with the supplied module ID. Modules are
160 not garbage collected; it is mandatory to call {!dispose_module} to free
161 memory. See the constructor [llvm::Module::Module]. *)
162 external create_module : string -> llmodule = "llvm_create_module"
164 (** [dispose_module m] destroys a module [m] and all of the IR objects it
165 contained. All references to subordinate objects are invalidated;
166 referencing them will invoke undefined behavior. See the destructor
167 [llvm::Module::~Module]. *)
168 external dispose_module : llmodule -> unit = "llvm_dispose_module"
170 (** [target_triple m] is the target specifier for the module [m], something like
171 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
172 external target_triple: llmodule -> string
173 = "llvm_target_triple"
175 (** [target_triple triple m] changes the target specifier for the module [m] to
176 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
177 external set_target_triple: string -> llmodule -> unit
178 = "llvm_set_target_triple"
180 (** [data_layout m] is the data layout specifier for the module [m], something
181 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
182 method [llvm::Module::getDataLayout]. *)
183 external data_layout: llmodule -> string
186 (** [set_data_layout s m] changes the data layout specifier for the module [m]
187 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
188 external set_data_layout: string -> llmodule -> unit
189 = "llvm_set_data_layout"
191 (** [define_type_name name ty m] adds a named type to the module's symbol table.
192 Returns [true] if successful. If such a name already exists, then no entry
193 is added and [false] is returned. See the [llvm::Module::addTypeName]
195 external define_type_name : string -> lltype -> llmodule -> bool
196 = "llvm_add_type_name"
198 (** [delete_type_name name] removes a type name from the module's symbol
200 external delete_type_name : string -> llmodule -> unit
201 = "llvm_delete_type_name"
206 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
207 See the method [llvm::Type::getTypeID]. *)
208 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
210 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
211 val string_of_lltype : lltype -> string
213 (** {7 Operations on integer types} *)
215 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
218 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
221 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
222 val i16_type : lltype
224 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
225 val i32_type : lltype
227 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
228 val i64_type : lltype
230 (** [integer_type n] returns an integer type of bitwidth [n].
231 See the method [llvm::IntegerType::get]. *)
232 external integer_type : int -> lltype = "llvm_integer_type"
234 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
235 See the method [llvm::IntegerType::getBitWidth]. *)
236 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
239 (** {7 Operations on real types} *)
241 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
242 val float_type : lltype
244 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
245 val double_type : lltype
247 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
248 val x86fp80_type : lltype
250 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
251 val fp128_type : lltype
253 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
254 val ppc_fp128_type : lltype
257 (** {7 Operations on function types} *)
259 (** [function_type ret_ty param_tys] returns the function type returning
260 [ret_ty] and taking [param_tys] as parameters.
261 See the method [llvm::FunctionType::get]. *)
262 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
264 (** [va_arg_function_type ret_ty param_tys] is just like
265 [function_type ret_ty param_tys] except that it returns the function type
266 which also takes a variable number of arguments.
267 See the method [llvm::FunctionType::get]. *)
268 external var_arg_function_type : lltype -> lltype array -> lltype
269 = "llvm_var_arg_function_type"
271 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
272 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
273 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
275 (** [return_type fty] gets the return type of the function type [fty].
276 See the method [llvm::FunctionType::getReturnType]. *)
277 external return_type : lltype -> lltype = "LLVMGetReturnType"
279 (** [param_types fty] gets the parameter types of the function type [fty].
280 See the method [llvm::FunctionType::getParamType]. *)
281 external param_types : lltype -> lltype array = "llvm_param_types"
284 (** {7 Operations on struct types} *)
286 (** [struct_type tys] returns the structure type containing in the types in the
287 array [tys]. See the method [llvm::StructType::get]. *)
288 external struct_type : lltype array -> lltype = "llvm_struct_type"
290 (** [struct_type tys] returns the packed structure type containing in the types
291 in the array [tys]. See the method [llvm::StructType::get]. *)
292 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
294 (** [element_types sty] returns the constituent types of the struct type [sty].
295 See the method [llvm::StructType::getElementType]. *)
296 external element_types : lltype -> lltype array = "llvm_element_types"
298 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
299 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
300 external is_packed : lltype -> bool = "llvm_is_packed"
303 (** {7 Operations on pointer, vector, and array types} *)
305 (** [array_type ty n] returns the array type containing [n] elements of type
306 [ty]. See the method [llvm::ArrayType::get]. *)
307 external array_type : lltype -> int -> lltype = "llvm_array_type"
309 (** [pointer_type ty] returns the pointer type referencing objects of type
310 [ty] in the default address space (0).
311 See the method [llvm::PointerType::getUnqual]. *)
312 external pointer_type : lltype -> lltype = "llvm_pointer_type"
314 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
315 of type [ty] in address space [as].
316 See the method [llvm::PointerType::get]. *)
317 external qualified_pointer_type : lltype -> int -> lltype
318 = "llvm_qualified_pointer_type"
320 (** [vector_type ty n] returns the array type containing [n] elements of the
321 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
322 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
324 (** [element_type ty] returns the element type of the pointer, vector, or array
325 type [ty]. See the method [llvm::SequentialType::get]. *)
326 external element_type : lltype -> lltype = "LLVMGetElementType"
328 (** [element_type aty] returns the element count of the array type [aty].
329 See the method [llvm::ArrayType::getNumElements]. *)
330 external array_length : lltype -> int = "llvm_array_length"
332 (** [address_space pty] returns the address space qualifier of the pointer type
333 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
334 external address_space : lltype -> int = "llvm_address_space"
336 (** [element_type ty] returns the element count of the vector type [ty].
337 See the method [llvm::VectorType::getNumElements]. *)
338 external vector_size : lltype -> int = "llvm_vector_size"
341 (** {7 Operations on other types} *)
343 (** [opaque_type ()] creates a new opaque type distinct from any other.
344 Opaque types are useful for building recursive types in combination with
345 {!refine_type} [opaque_ty ty].
346 See [llvm::OpaqueType::get]. *)
347 external opaque_type : unit -> lltype = "llvm_opaque_type"
349 (** [void_type] is the type of a function which does not return any value.
350 See [llvm::Type::VoidTy]. *)
351 val void_type : lltype
353 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
354 val label_type : lltype
356 (** {7 Operations on type handles} *)
358 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
359 refined as a result of a call to {!refine_type}, the handle will be updated;
360 any bare [lltype] references will become invalid.
361 See the class [llvm::PATypeHolder]. *)
362 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
364 (** [type_of_handle tyh] resolves the type handle [tyh].
365 See the method [llvm::PATypeHolder::get()]. *)
366 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
368 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
369 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
370 values! Use {!lltypehandle} to manipulate potentially abstract types. See
371 the method [llvm::Type::refineAbstractType]. *)
372 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
377 (** [type_of v] returns the type of the value [v].
378 See the method [llvm::Value::getType]. *)
379 external type_of : llvalue -> lltype = "llvm_type_of"
381 (** [value_name v] returns the name of the value [v]. For global values, this is
382 the symbol name. For instructions and basic blocks, it is the SSA register
383 name. It is meaningless for constants.
384 See the method [llvm::Value::getName]. *)
385 external value_name : llvalue -> string = "llvm_value_name"
387 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
388 [llvm::Value::setName]. *)
389 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
391 (** [dump_value v] prints the .ll representation of the value [v] to standard
392 error. See the method [llvm::Value::dump]. *)
393 external dump_value : llvalue -> unit = "llvm_dump_value"
396 (** {7 Operations on constants of (mostly) any type} *)
398 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
399 otherwise. Similar to [llvm::isa<Constant>]. *)
400 external is_constant : llvalue -> bool = "llvm_is_constant"
402 (** [const_null ty] returns the constant null (zero) of the type [ty].
403 See the method [llvm::Constant::getNullValue]. *)
404 external const_null : lltype -> llvalue = "LLVMConstNull"
406 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
407 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
408 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
410 (** [undef ty] returns the undefined value of the type [ty].
411 See the method [llvm::UndefValue::get]. *)
412 external undef : lltype -> llvalue = "LLVMGetUndef"
414 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
415 See the method [llvm::Constant::isNullValue]. *)
416 external is_null : llvalue -> bool = "llvm_is_null"
418 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
419 otherwise. Similar to [llvm::isa<UndefValue>]. *)
420 external is_undef : llvalue -> bool = "llvm_is_undef"
423 (** {7 Operations on scalar constants} *)
425 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
426 See the method [llvm::ConstantInt::get]. *)
427 external const_int : lltype -> int -> llvalue = "llvm_const_int"
429 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
430 [i]. See the method [llvm::ConstantInt::get]. *)
431 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
432 = "llvm_const_of_int64"
434 (** [const_float ty n] returns the floating point constant of type [ty] and
435 value [n]. See the method [llvm::ConstantInt::get]. *)
436 external const_float : lltype -> float -> llvalue = "llvm_const_float"
439 (** {7 Operations on composite constants} *)
441 (** [const_string s] returns the constant [i8] array with the values of the
442 characters in the string [s]. The array is not null-terminated (but see
443 {!const_stringz}). This value can in turn be used as the initializer for a
444 global variable. See the method [llvm::ConstantArray::get]. *)
445 external const_string : string -> llvalue = "llvm_const_string"
447 (** [const_stringz s] returns the constant [i8] array with the values of the
448 characters in the string [s] and a null terminator. This value can in turn
449 be used as the initializer for a global variable.
450 See the method [llvm::ConstantArray::get]. *)
451 external const_stringz : string -> llvalue = "llvm_const_stringz"
453 (** [const_array ty elts] returns the constant array of type
454 [array_type ty (Array.length elts)] and containing the values [elts].
455 This value can in turn be used as the initializer for a global variable.
456 See the method [llvm::ConstantArray::get]. *)
457 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
459 (** [const_struct elts] returns the structured constant of type
460 [struct_type (Array.map type_of elts)] and containing the values [elts].
461 This value can in turn be used as the initializer for a global variable.
462 See the method [llvm::ConstantStruct::get]. *)
463 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
465 (** [const_packed_struct elts] returns the structured constant of type
466 {!packed_struct_type} [(Array.map type_of elts)] and containing the values
467 [elts]. This value can in turn be used as the initializer for a global
468 variable. See the method [llvm::ConstantStruct::get]. *)
469 external const_packed_struct : llvalue array -> llvalue
470 = "llvm_const_packed_struct"
472 (** [const_vector elts] returns the vector constant of type
473 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
474 values [elts]. See the method [llvm::ConstantVector::get]. *)
475 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
478 (** {7 Constant expressions} *)
480 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
481 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
482 (const_int i64_type 1)) i64_type], but considerably more readable.
483 See the method [llvm::ConstantExpr::getSizeOf]. *)
484 external size_of : lltype -> llvalue = "LLVMSizeOf"
486 (** [const_neg c] returns the arithmetic negation of the constant [c].
487 See the method [llvm::ConstantExpr::getNeg]. *)
488 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
490 (** [const_not c] returns the bitwise inverse of the constant [c].
491 See the method [llvm::ConstantExpr::getNot]. *)
492 external const_not : llvalue -> llvalue = "LLVMConstNot"
494 (** [const_add c1 c2] returns the constant sum of two constants.
495 See the method [llvm::ConstantExpr::getAdd]. *)
496 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
498 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
499 constants. See the method [llvm::ConstantExpr::getSub]. *)
500 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
502 (** [const_mul c1 c2] returns the constant product of two constants.
503 See the method [llvm::ConstantExpr::getMul]. *)
504 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
506 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
508 See the method [llvm::ConstantExpr::getUDiv]. *)
509 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
511 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
513 See the method [llvm::ConstantExpr::]. *)
514 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
516 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
518 See the method [llvm::ConstantExpr::getFDiv]. *)
519 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
521 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
522 unsigned integer constants.
523 See the method [llvm::ConstantExpr::getURem]. *)
524 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
526 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
527 signed integer constants.
528 See the method [llvm::ConstantExpr::getSRem]. *)
529 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
531 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
532 signed floating point constants.
533 See the method [llvm::ConstantExpr::getFRem]. *)
534 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
536 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
538 See the method [llvm::ConstantExpr::getAnd]. *)
539 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
541 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
543 See the method [llvm::ConstantExpr::getOr]. *)
544 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
546 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
548 See the method [llvm::ConstantExpr::getXor]. *)
549 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
551 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
552 constants, [c1 pred c2].
553 See the method [llvm::ConstantExpr::getICmp]. *)
554 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
557 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
558 point constants, [c1 pred c2].
559 See the method [llvm::ConstantExpr::getFCmp]. *)
560 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
563 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
564 constant integer [c2].
565 See the method [llvm::ConstantExpr::getShl]. *)
566 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
568 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
569 constant integer [c2] with zero extension.
570 See the method [llvm::ConstantExpr::getLShr]. *)
571 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
573 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
574 constant integer [c2] with sign extension.
575 See the method [llvm::ConstantExpr::getAShr]. *)
576 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
578 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
579 constant integers indices from the array [indices].
580 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
581 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
583 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
584 to the smaller integer type [ty].
585 See the method [llvm::ConstantExpr::getTrunc]. *)
586 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
588 (** [const_sext c ty] returns the constant sign extension of integer constant
589 [c] to the larger integer type [ty].
590 See the method [llvm::ConstantExpr::getSExt]. *)
591 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
593 (** [const_zext c ty] returns the constant zero extension of integer constant
594 [c] to the larger integer type [ty].
595 See the method [llvm::ConstantExpr::getZExt]. *)
596 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
598 (** [const_fptrunc c ty] returns the constant truncation of floating point
599 constant [c] to the smaller floating point type [ty].
600 See the method [llvm::ConstantExpr::getFPTrunc]. *)
601 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
603 (** [const_fpext c ty] returns the constant extension of floating point constant
604 [c] to the larger floating point type [ty].
605 See the method [llvm::ConstantExpr::getFPExt]. *)
606 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
608 (** [const_uitofp c ty] returns the constant floating point conversion of
609 unsigned integer constant [c] to the floating point type [ty].
610 See the method [llvm::ConstantExpr::getUIToFP]. *)
611 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
613 (** [const_sitofp c ty] returns the constant floating point conversion of
614 signed integer constant [c] to the floating point type [ty].
615 See the method [llvm::ConstantExpr::getSIToFP]. *)
616 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
618 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
619 floating point constant [c] to integer type [ty].
620 See the method [llvm::ConstantExpr::getFPToUI]. *)
621 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
623 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
624 floating point constant [c] to integer type [ty].
625 See the method [llvm::ConstantExpr::getFPToSI]. *)
626 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
628 (** [const_ptrtoint c ty] returns the constant integer conversion of
629 pointer constant [c] to integer type [ty].
630 See the method [llvm::ConstantExpr::getPtrToInt]. *)
631 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
633 (** [const_inttoptr c ty] returns the constant pointer conversion of
634 integer constant [c] to pointer type [ty].
635 See the method [llvm::ConstantExpr::getIntToPtr]. *)
636 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
638 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
639 to type [ty] of equal size.
640 See the method [llvm::ConstantExpr::getBitCast]. *)
641 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
643 (** [const_select cond t f] returns the constant conditional which returns value
644 [t] if the boolean constant [cond] is true and the value [f] otherwise.
645 See the method [llvm::ConstantExpr::getSelect]. *)
646 external const_select : llvalue -> llvalue -> llvalue -> llvalue
649 (** [const_extractelement vec i] returns the constant [i]th element of
650 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
651 the size of the vector.
652 See the method [llvm::ConstantExpr::getExtractElement]. *)
653 external const_extractelement : llvalue -> llvalue -> llvalue
654 = "LLVMConstExtractElement"
656 (** [const_insertelement vec v i] returns the constant vector with the same
657 elements as constant vector [v] but the [i]th element replaced by the
658 constant [v]. [v] must be a constant value with the type of the vector
659 elements. [i] must be a constant [i32] value unsigned less than the size
661 See the method [llvm::ConstantExpr::getInsertElement]. *)
662 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
663 = "LLVMConstInsertElement"
665 (** [const_shufflevector a b mask] returns a constant [shufflevector].
666 See the LLVM Language Reference for details on the [sufflevector]
668 See the method [llvm::ConstantExpr::getShuffleVector]. *)
669 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
670 = "LLVMConstShuffleVector"
673 (** {7 Operations on global variables, functions, and aliases (globals)} *)
675 (** [is_declaration g] returns [true] if the global value [g] is a declaration
676 only. Returns [false] otherwise.
677 See the method [llvm::GlobalValue::isDeclaration]. *)
678 external is_declaration : llvalue -> bool = "llvm_is_declaration"
680 (** [linkage g] returns the linkage of the global value [g].
681 See the method [llvm::GlobalValue::getLinkage]. *)
682 external linkage : llvalue -> Linkage.t = "llvm_linkage"
684 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
685 See the method [llvm::GlobalValue::setLinkage]. *)
686 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
688 (** [section g] returns the linker section of the global value [g].
689 See the method [llvm::GlobalValue::getSection]. *)
690 external section : llvalue -> string = "llvm_section"
692 (** [set_section s g] sets the linker section of the global value [g] to [s].
693 See the method [llvm::GlobalValue::setSection]. *)
694 external set_section : string -> llvalue -> unit = "llvm_set_section"
696 (** [visibility g] returns the linker visibility of the global value [g].
697 See the method [llvm::GlobalValue::getVisibility]. *)
698 external visibility : llvalue -> Visibility.t = "llvm_visibility"
700 (** [set_visibility v g] sets the linker visibility of the global value [g] to
701 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
702 external set_visibility : Visibility.t -> llvalue -> unit
703 = "llvm_set_visibility"
705 (** [alignment g] returns the required alignment of the global value [g].
706 See the method [llvm::GlobalValue::getAlignment]. *)
707 external alignment : llvalue -> int = "llvm_alignment"
709 (** [set_alignment n g] sets the required alignment of the global value [g] to
710 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
711 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
714 (** {7 Operations on global variables} *)
716 (** [declare_global ty name m] returns a new global variable of type [ty] and
717 with name [name] in module [m]. If such a global variable already exists,
718 it is returned. If the type of the existing global differs, then a bitcast
719 to [ty] is returned. *)
720 external declare_global : lltype -> string -> llmodule -> llvalue
721 = "llvm_declare_global"
723 (** [define_global name init m] returns a new global with name [name] and
724 initializer [init] in module [m]. If the named global already exists, it is
726 See the constructor of [llvm::GlobalVariable]. *)
727 external define_global : string -> llvalue -> llmodule -> llvalue
728 = "llvm_define_global"
730 (** [lookup_global name m] returns [Some g] if a global variable with name
731 [name] exists in module [m]. If no such global exists, returns [None].
732 See the [llvm::GlobalVariable] constructor. *)
733 external lookup_global : string -> llmodule -> llvalue option
734 = "llvm_lookup_global"
736 (** [delete_global gv] destroys the global variable [gv].
737 See the method [llvm::GlobalVariable::eraseFromParent]. *)
738 external delete_global : llvalue -> unit = "llvm_delete_global"
740 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
741 constant. Returns [false] otherwise.
742 See the method [llvm::GlobalVariable::isConstant]. *)
743 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
745 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
746 [c] is [true] and not if [c] is [false].
747 See the method [llvm::GlobalVariable::setConstant]. *)
748 external set_global_constant : bool -> llvalue -> unit
749 = "llvm_set_global_constant"
751 (** [has_initializer gv] returns [true] if the global variable [gv] has an
752 initializer and [false] otherwise.
753 See the method [llvm::GlobalVariable::hasInitializer]. *)
754 external has_initializer : llvalue -> bool = "llvm_has_initializer"
756 (** [global_initializer gv] returns the initializer for the global variable
757 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
758 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
760 (** [set_initializer c gv] sets the initializer for the global variable
761 [gv] to the constant [c].
762 See the method [llvm::GlobalVariable::setInitializer]. *)
763 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
765 (** [remove_initializer gv] unsets the initializer for the global variable
767 See the method [llvm::GlobalVariable::setInitializer]. *)
768 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
770 (** [is_thread_local gv] returns [true] if the global variable [gv] is
771 thread-local and [false] otherwise.
772 See the method [llvm::GlobalVariable::isThreadLocal]. *)
773 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
775 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
776 [c] is [true] and not otherwise.
777 See the method [llvm::GlobalVariable::setThreadLocal]. *)
778 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
781 (** {7 Operations on functions} *)
783 (** [declare_function name ty m] returns a new function of type [ty] and
784 with name [name] in module [m]. If such a function already exists,
785 it is returned. If the type of the existing function differs, then a bitcast
786 to [ty] is returned. *)
787 external declare_function : string -> lltype -> llmodule -> llvalue
788 = "llvm_declare_function"
790 (** [define_function name ty m] creates a new function with name [name] and
791 type [ty] in module [m]. If the named function already exists, it is
792 renamed. An entry basic block is created in the function.
793 See the constructor of [llvm::GlobalVariable]. *)
794 external define_function : string -> lltype -> llmodule -> llvalue
795 = "llvm_define_function"
797 (** [lookup_function name m] returns [Some f] if a function with name
798 [name] exists in module [m]. If no such function exists, returns [None].
799 See the method [llvm::Module] constructor. *)
800 external lookup_function : string -> llmodule -> llvalue option
801 = "llvm_lookup_function"
803 (** [delete_function f] destroys the function [f].
804 See the method [llvm::Function::eraseFromParent]. *)
805 external delete_function : llvalue -> unit = "llvm_delete_function"
807 (** [params f] returns the parameters of function [f].
808 See the method [llvm::Function::getArgumentList]. *)
809 external params : llvalue -> llvalue array = "llvm_params"
811 (** [param f n] returns the [n]th parameter of function [f].
812 See the method [llvm::Function::getArgumentList]. *)
813 external param : llvalue -> int -> llvalue = "llvm_param"
815 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
816 See the method [llvm::Function::isIntrinsic]. *)
817 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
819 (** [function_call_conv f] returns the calling convention of the function [f].
820 See the method [llvm::Function::getCallingConv]. *)
821 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
823 (** [set_function_call_conv cc f] sets the calling convention of the function
824 [f] to the calling convention numbered [cc].
825 See the method [llvm::Function::setCallingConv]. *)
826 external set_function_call_conv : int -> llvalue -> unit
827 = "llvm_set_function_call_conv"
829 (** [collector f] returns [Some name] if the function [f] has a garbage
830 collection algorithm specified and [None] otherwise.
831 See the method [llvm::Function::getCollector]. *)
832 external collector : llvalue -> string option = "llvm_collector"
834 (** [set_collector gc f] sets the collection algorithm for the function [f] to
835 [gc]. See the method [llvm::Function::setCollector]. *)
836 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
839 (** {7 Operations on basic blocks} *)
841 (** [basic_blocks fn] returns the basic blocks of the function [f].
842 See the method [llvm::Function::getBasicBlockList]. *)
843 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
845 (** [entry_block fn] returns the entry basic block of the function [f].
846 See the method [llvm::Function::getEntryBlock]. *)
847 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
849 (** [delete_block bb] deletes the basic block [bb].
850 See the method [llvm::BasicBlock::eraseFromParent]. *)
851 external delete_block : llbasicblock -> unit = "llvm_delete_block"
853 (** [append_block name f] creates a new basic block named [name] at the end of
855 See the constructor of [llvm::BasicBlock]. *)
856 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
858 (** [insert_block name bb] creates a new basic block named [name] before the
860 See the constructor of [llvm::BasicBlock]. *)
861 external insert_block : string -> llbasicblock -> llbasicblock
862 = "llvm_insert_block"
864 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
865 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
867 (** [value_is_block v] returns [true] if the value [v] is a basic block and
869 Similar to [llvm::isa<BasicBlock>]. *)
870 external value_is_block : llvalue -> bool = "llvm_value_is_block"
872 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
873 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
876 (** {7 Operations on call sites} *)
878 (** [instruction_call_conv ci] is the calling convention for the call or invoke
879 instruction [ci], which may be one of the values from the module
880 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
881 [llvm::InvokeInst::getCallingConv]. *)
882 external instruction_call_conv: llvalue -> int
883 = "llvm_instruction_call_conv"
885 (** [set_inst_call_conv cc ci] sets the calling convention for the call or
886 invoke instruction [ci] to the integer [cc], which can be one of the values
887 from the module {!CallConv}. See the method [llvm::CallInst::setCallingConv]
888 and [llvm::InvokeInst::setCallingConv]. *)
889 external set_instruction_call_conv: int -> llvalue -> unit
890 = "llvm_set_instruction_call_conv"
893 (** {7 Operations on phi nodes} *)
895 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
896 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
897 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
898 = "llvm_add_incoming"
900 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
901 See the method [llvm::PHINode::getIncomingValue]. *)
902 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
906 (** {6 Instruction builders} *)
908 (** [builder] creates an instruction builder with no position. It is invalid to
909 use this builder until its position is set with {!position_before} or
910 {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
911 external builder: unit-> llbuilder
914 (** [builder_before ins] creates an instruction builder positioned before the
915 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
916 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
918 (** [builder_at_end bb] creates an instruction builder positioned at the end of
919 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
920 external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
922 (** [position_before ins b] moves the instruction builder [b] to before the
923 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
924 external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
926 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
927 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
928 external position_at_end : llbasicblock -> llbuilder -> unit
929 = "llvm_position_at_end"
932 (** {7 Terminators} *)
934 (** [build_ret_void b] creates a
936 instruction at the position specified by the instruction builder [b].
937 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
938 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
940 (** [build_ret v b] creates a
942 instruction at the position specified by the instruction builder [b].
943 See the method [llvm::LLVMBuilder::CreateRet]. *)
944 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
946 (** [build_br bb b] creates a
948 instruction at the position specified by the instruction builder [b].
949 See the method [llvm::LLVMBuilder::CreateBr]. *)
950 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
952 (** [build_cond_br cond tbb fbb b] creates a
953 [b %cond, %tbb, %fbb]
954 instruction at the position specified by the instruction builder [b].
955 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
956 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
957 llvalue = "llvm_build_cond_br"
959 (** [build_switch case elsebb b] creates an empty
960 [switch %case, %elsebb]
961 instruction at the position specified by the instruction builder [b].
962 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
963 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
964 = "llvm_build_switch"
966 (** [build_invoke fn args tobb unwindbb name b] creates an
967 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
968 instruction at the position specified by the instruction builder [b].
969 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
970 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
971 llbasicblock -> string -> llbuilder -> llvalue
972 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
974 (** [build_unwind b] creates an
976 instruction at the position specified by the instruction builder [b].
977 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
978 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
980 (** [build_unreachable b] creates an
982 instruction at the position specified by the instruction builder [b].
983 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
984 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
987 (** {7 Arithmetic} *)
989 (** [build_add x y name b] creates a
991 instruction at the position specified by the instruction builder [b].
992 See the method [llvm::LLVMBuilder::CreateAdd]. *)
993 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
996 (** [build_sub x y name b] creates a
998 instruction at the position specified by the instruction builder [b].
999 See the method [llvm::LLVMBuilder::CreateSub]. *)
1000 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1003 (** [build_mul x y name b] creates a
1004 [%name = mul %x, %y]
1005 instruction at the position specified by the instruction builder [b].
1006 See the method [llvm::LLVMBuilder::CreateMul]. *)
1007 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1010 (** [build_udiv x y name b] creates a
1011 [%name = udiv %x, %y]
1012 instruction at the position specified by the instruction builder [b].
1013 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1014 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1017 (** [build_sdiv x y name b] creates a
1018 [%name = sdiv %x, %y]
1019 instruction at the position specified by the instruction builder [b].
1020 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1021 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1024 (** [build_fdiv x y name b] creates a
1025 [%name = fdiv %x, %y]
1026 instruction at the position specified by the instruction builder [b].
1027 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1028 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1031 (** [build_urem x y name b] creates a
1032 [%name = urem %x, %y]
1033 instruction at the position specified by the instruction builder [b].
1034 See the method [llvm::LLVMBuilder::CreateURem]. *)
1035 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1038 (** [build_SRem x y name b] creates a
1039 [%name = srem %x, %y]
1040 instruction at the position specified by the instruction builder [b].
1041 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1042 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1045 (** [build_frem x y name b] creates a
1046 [%name = frem %x, %y]
1047 instruction at the position specified by the instruction builder [b].
1048 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1049 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1052 (** [build_shl x y name b] creates a
1053 [%name = shl %x, %y]
1054 instruction at the position specified by the instruction builder [b].
1055 See the method [llvm::LLVMBuilder::CreateShl]. *)
1056 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1059 (** [build_lshr x y name b] creates a
1060 [%name = lshr %x, %y]
1061 instruction at the position specified by the instruction builder [b].
1062 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1063 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1066 (** [build_ashr x y name b] creates a
1067 [%name = ashr %x, %y]
1068 instruction at the position specified by the instruction builder [b].
1069 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1070 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1073 (** [build_and x y name b] creates a
1074 [%name = and %x, %y]
1075 instruction at the position specified by the instruction builder [b].
1076 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1077 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1080 (** [build_or x y name b] creates a
1082 instruction at the position specified by the instruction builder [b].
1083 See the method [llvm::LLVMBuilder::CreateOr]. *)
1084 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1087 (** [build_xor x y name b] creates a
1088 [%name = xor %x, %y]
1089 instruction at the position specified by the instruction builder [b].
1090 See the method [llvm::LLVMBuilder::CreateXor]. *)
1091 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1094 (** [build_neg x name b] creates a
1096 instruction at the position specified by the instruction builder [b].
1097 [-0.0] is used for floating point types to compute the correct sign.
1098 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1099 external build_neg : llvalue -> string -> llbuilder -> llvalue
1102 (** [build_xor x name b] creates a
1103 [%name = xor %x, -1]
1104 instruction at the position specified by the instruction builder [b].
1105 [-1] is the correct "all ones" value for the type of [x].
1106 See the method [llvm::LLVMBuilder::CreateXor]. *)
1107 external build_not : llvalue -> string -> llbuilder -> llvalue
1113 (** [build_malloc ty name b] creates a
1114 [%name = malloc %ty]
1115 instruction at the position specified by the instruction builder [b].
1116 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1117 external build_malloc : lltype -> string -> llbuilder -> llvalue
1118 = "llvm_build_malloc"
1120 (** [build_array_malloc ty n name b] creates a
1121 [%name = malloc %ty, %n]
1122 instruction at the position specified by the instruction builder [b].
1123 See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1124 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1125 llvalue = "llvm_build_array_malloc"
1127 (** [build_alloca ty name b] creates a
1128 [%name = alloca %ty]
1129 instruction at the position specified by the instruction builder [b].
1130 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1131 external build_alloca : lltype -> string -> llbuilder -> llvalue
1132 = "llvm_build_alloca"
1134 (** [build_array_alloca ty n name b] creates a
1135 [%name = alloca %ty, %n]
1136 instruction at the position specified by the instruction builder [b].
1137 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1138 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1139 llvalue = "llvm_build_array_alloca"
1141 (** [build_free v b] creates a
1143 instruction at the position specified by the instruction builder [b].
1144 See the method [llvm::LLVMBuilder::CreateFree]. *)
1145 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1147 (** [build_load v name b] creates a
1149 instruction at the position specified by the instruction builder [b].
1150 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1151 external build_load : llvalue -> string -> llbuilder -> llvalue
1154 (** [build_store v p b] creates a
1156 instruction at the position specified by the instruction builder [b].
1157 See the method [llvm::LLVMBuilder::CreateStore]. *)
1158 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1159 = "llvm_build_store"
1161 (** [build_gep p indices name b] creates a
1162 [%name = gep %p, indices...]
1163 instruction at the position specified by the instruction builder [b].
1164 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1165 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1171 (** [build_trunc v ty name b] creates a
1172 [%name = trunc %p to %ty]
1173 instruction at the position specified by the instruction builder [b].
1174 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1175 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1176 = "llvm_build_trunc"
1178 (** [build_zext v ty name b] creates a
1179 [%name = zext %p to %ty]
1180 instruction at the position specified by the instruction builder [b].
1181 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1182 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1185 (** [build_sext v ty name b] creates a
1186 [%name = sext %p to %ty]
1187 instruction at the position specified by the instruction builder [b].
1188 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1189 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1192 (** [build_fptoui v ty name b] creates a
1193 [%name = fptoui %p to %ty]
1194 instruction at the position specified by the instruction builder [b].
1195 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1196 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1197 = "llvm_build_fptoui"
1199 (** [build_fptosi v ty name b] creates a
1200 [%name = fptosi %p to %ty]
1201 instruction at the position specified by the instruction builder [b].
1202 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1203 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1204 = "llvm_build_fptosi"
1206 (** [build_uitofp v ty name b] creates a
1207 [%name = uitofp %p to %ty]
1208 instruction at the position specified by the instruction builder [b].
1209 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1210 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1211 = "llvm_build_uitofp"
1213 (** [build_sitofp v ty name b] creates a
1214 [%name = sitofp %p to %ty]
1215 instruction at the position specified by the instruction builder [b].
1216 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1217 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1218 = "llvm_build_sitofp"
1220 (** [build_fptrunc v ty name b] creates a
1221 [%name = fptrunc %p to %ty]
1222 instruction at the position specified by the instruction builder [b].
1223 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1224 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1225 = "llvm_build_fptrunc"
1227 (** [build_fpext v ty name b] creates a
1228 [%name = fpext %p to %ty]
1229 instruction at the position specified by the instruction builder [b].
1230 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1231 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1232 = "llvm_build_fpext"
1234 (** [build_ptrtoint v ty name b] creates a
1235 [%name = prtotint %p to %ty]
1236 instruction at the position specified by the instruction builder [b].
1237 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1238 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1239 = "llvm_build_prttoint"
1241 (** [build_inttoptr v ty name b] creates a
1242 [%name = inttoptr %p to %ty]
1243 instruction at the position specified by the instruction builder [b].
1244 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1245 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1246 = "llvm_build_inttoptr"
1248 (** [build_bitcast v ty name b] creates a
1249 [%name = bitcast %p to %ty]
1250 instruction at the position specified by the instruction builder [b].
1251 See the method [llvm::LLVMBuilder::CreateBitcast]. *)
1252 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1253 = "llvm_build_bitcast"
1256 (** {7 Comparisons} *)
1258 (** [build_icmp pred x y name b] creates a
1259 [%name = icmp %pred %x, %y]
1260 instruction at the position specified by the instruction builder [b].
1261 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1262 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1263 llbuilder -> llvalue = "llvm_build_icmp"
1265 (** [build_fcmp pred x y name b] creates a
1266 [%name = fcmp %pred %x, %y]
1267 instruction at the position specified by the instruction builder [b].
1268 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1269 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1270 llbuilder -> llvalue = "llvm_build_fcmp"
1273 (** {7 Miscellaneous instructions} *)
1275 (** [build_phi incoming name b] creates a
1276 [%name = phi %incoming]
1277 instruction at the position specified by the instruction builder [b].
1278 [incoming] is a list of [({!llvalue}, {!llbasicblock})] tuples.
1279 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1280 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1281 llvalue = "llvm_build_phi"
1283 (** [build_call fn args name b] creates a
1284 [%name = call %fn(args...)]
1285 instruction at the position specified by the instruction builder [b].
1286 See the method [llvm::LLVMBuilder::CreateCall]. *)
1287 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1290 (** [build_select cond thenv elsev name b] creates a
1291 [%name = select %cond, %thenv, %elsev]
1292 instruction at the position specified by the instruction builder [b].
1293 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1294 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1295 llvalue = "llvm_build_select"
1297 (** [build_va_arg valist argty name b] creates a
1298 [%name = va_arg %valist, %argty]
1299 instruction at the position specified by the instruction builder [b].
1300 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1301 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1302 = "llvm_build_va_arg"
1304 (** [build_extractelement vec i name b] creates a
1305 [%name = extractelement %vec, %i]
1306 instruction at the position specified by the instruction builder [b].
1307 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1308 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1309 llvalue = "llvm_build_extractelement"
1311 (** [build_insertelement vec elt i name b] creates a
1312 [%name = insertelement %vec, %elt, %i]
1313 instruction at the position specified by the instruction builder [b].
1314 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1315 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1316 llbuilder -> llvalue = "llvm_build_insertelement"
1318 (** [build_shufflevector veca vecb mask name b] creates a
1319 [%name = shufflevector %veca, %vecb, %mask]
1320 instruction at the position specified by the instruction builder [b].
1321 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1322 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1323 llbuilder -> llvalue = "llvm_build_shufflevector"
1326 (** {6 Module providers} *)
1328 module ModuleProvider : sig
1329 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1330 ownership of the module. See the constructor
1331 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1332 external create : llmodule -> llmoduleprovider
1333 = "LLVMCreateModuleProviderForExistingModule"
1335 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1336 the contained module. *)
1337 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1341 (** {6 Memory buffers} *)
1343 module MemoryBuffer : sig
1344 (** [of_file p] is the memory buffer containing the contents of the file at
1345 path [p]. If the file could not be read, then [IoError msg] is
1347 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1349 (** [stdin ()] is the memory buffer containing the contents of standard input.
1350 If standard input is empty, then [IoError msg] is raised. *)
1351 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1353 (** Disposes of a memory buffer. *)
1354 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"