diff options
-rw-r--r-- | bindings/ocaml/analysis/llvm_analysis.ml | 5 | ||||
-rw-r--r-- | bindings/ocaml/analysis/llvm_analysis.mli | 12 | ||||
-rw-r--r-- | bindings/ocaml/bitwriter/llvm_bitwriter.mli | 3 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm.ml | 23 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm.mli | 832 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm_ocaml.c | 7 |
6 files changed, 826 insertions, 56 deletions
diff --git a/bindings/ocaml/analysis/llvm_analysis.ml b/bindings/ocaml/analysis/llvm_analysis.ml index a972aa0856..58f8a5b033 100644 --- a/bindings/ocaml/analysis/llvm_analysis.ml +++ b/bindings/ocaml/analysis/llvm_analysis.ml @@ -5,11 +5,6 @@ * This file was developed by Gordon Henriksen and is distributed under the * University of Illinois Open Source License. See LICENSE.TXT for details. * - *===----------------------------------------------------------------------=== - * - * This interface provides an ocaml API for LLVM IR analyses, the classes in - * the Analysis library. - * *===----------------------------------------------------------------------===*) diff --git a/bindings/ocaml/analysis/llvm_analysis.mli b/bindings/ocaml/analysis/llvm_analysis.mli index 59ff6c661c..fdaffb7142 100644 --- a/bindings/ocaml/analysis/llvm_analysis.mli +++ b/bindings/ocaml/analysis/llvm_analysis.mli @@ -13,12 +13,24 @@ *===----------------------------------------------------------------------===*) +(** [verify_module m] returns [None] if the module [m] is valid, and + [Some reason] if it is invalid. [reason] is a string containing a + human-readable validation report. See [llvm::verifyModule]. **) external verify_module : Llvm.llmodule -> string option = "llvm_verify_module" +(** [verify_function f] returns [None] if the function [f] is valid, and + [Some reason] if it is invalid. [reason] is a string containing a + human-readable validation report. See [llvm::verifyFunction]. **) external verify_function : Llvm.llvalue -> bool = "llvm_verify_function" +(** [verify_module m] returns if the module [m] is valid, but prints a + validation report to [stderr] and aborts the program if it is invalid. See + [llvm::verifyModule]. **) external assert_valid_module : Llvm.llmodule -> unit = "llvm_assert_valid_module" +(** [verify_function f] returns if the function [f] is valid, but prints a + validation report to [stderr] and aborts the program if it is invalid. See + [llvm::verifyFunction]. **) external assert_valid_function : Llvm.llvalue -> unit = "llvm_assert_valid_function" diff --git a/bindings/ocaml/bitwriter/llvm_bitwriter.mli b/bindings/ocaml/bitwriter/llvm_bitwriter.mli index 08e001bc91..76f4b4e719 100644 --- a/bindings/ocaml/bitwriter/llvm_bitwriter.mli +++ b/bindings/ocaml/bitwriter/llvm_bitwriter.mli @@ -13,6 +13,7 @@ *===----------------------------------------------------------------------===*) -(* Writes the bitcode for module the given path. Returns true if successful. *) +(** [write_bitcode_file m path] writes the bitcode for module [m] to the file at + [path]. Returns [true] if successful, [false] otherwise. **) external write_bitcode_file : Llvm.llmodule -> string -> bool = "llvm_write_bitcode_file" diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index e19228afac..a415b94594 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -5,21 +5,14 @@ * This file was developed by Gordon Henriksen and is distributed under the * University of Illinois Open Source License. See LICENSE.TXT for details. * - *===----------------------------------------------------------------------=== - * - * This interface provides an ocaml API for the LLVM intermediate - * representation, the classes in the VMCore library. - * *===----------------------------------------------------------------------===*) -(* These abstract types correlate directly to the LLVM VMCore classes. *) type llmodule type lltype type lltypehandle type llvalue -type llbasicblock (* These are actually values, but - benefit from type checking. *) +type llbasicblock type llbuilder type type_kind = @@ -93,19 +86,10 @@ type real_predicate = (*===-- Modules -----------------------------------------------------------===*) -(* Creates a module with the supplied module ID. Modules are not garbage - collected; it is mandatory to call dispose_module to free memory. *) external create_module : string -> llmodule = "llvm_create_module" - -(* Disposes a module. All references to subordinate objects are invalidated; - referencing them will invoke undefined behavior. *) external dispose_module : llmodule -> unit = "llvm_dispose_module" - -(* Adds a named type to the module's symbol table. Returns true if successful. - If such a name already exists, then no entry is added and returns false. *) external define_type_name : string -> lltype -> llmodule -> bool = "llvm_add_type_name" - external delete_type_name : string -> llmodule -> unit = "llvm_delete_type_name" @@ -113,8 +97,6 @@ external delete_type_name : string -> llmodule -> unit (*===-- Types -------------------------------------------------------------===*) external classify_type : lltype -> type_kind = "llvm_classify_type" -external refine_abstract_type : lltype -> lltype -> unit - = "llvm_refine_abstract_type" (*--... Operations on integer types ........................................--*) external _i1_type : unit -> lltype = "llvm_i1_type" @@ -146,7 +128,6 @@ let fp128_type = _fp128_type () let ppc_fp128_type = _ppc_fp128_type () (*--... Operations on function types .......................................--*) -(* FIXME: handle parameter attributes *) external function_type : lltype -> lltype array -> lltype = "llvm_function_type" external var_arg_function_type : lltype -> lltype array -> lltype = "llvm_var_arg_function_type" @@ -280,6 +261,7 @@ external define_global : string -> llvalue -> llmodule -> llvalue external lookup_global : string -> llmodule -> llvalue option = "llvm_lookup_global" external delete_global : llvalue -> unit = "llvm_delete_global" +external has_initializer : llvalue -> bool = "llvm_has_initializer" external global_initializer : llvalue -> llvalue = "LLVMGetInitializer" external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer" external remove_initializer : llvalue -> unit = "llvm_remove_initializer" @@ -457,6 +439,7 @@ let concat2 sep arr = !s let rec string_of_lltype ty = + (* FIXME: stop infinite recursion! :) *) match classify_type ty with Integer_type -> "i" ^ string_of_int (integer_bitwidth ty) | Pointer_type -> (string_of_lltype (element_type ty)) ^ "*" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index abb90f24c8..ac83e42809 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -14,14 +14,34 @@ (* These abstract types correlate directly to the LLVM VMCore classes. *) + +(** The top-level container for all other LLVM Intermediate Representation (IR) + objects. See the [llvm::Module] class. **) type llmodule -type lltype + +(** Each value in the LLVM IR has a type, an instance of [lltype]. See the + [llvm::Type] class. **) +type lltype + +(** When building recursive types using [refine_type], [lltype] values may + become invalid; use [lltypehandle] to resolve this problem. See the + [llvm::AbstractTypeHolder] class. **) type lltypehandle + +(** Any value in the LLVM IR. Functions, instructions, global variables, + constants, and much more are all [llvalues]. See the [llvm::Value] class. + This type covers a wide range of subclasses. **) type llvalue -type llbasicblock (* These are actually values, but - benefit from type checking. *) + +(** A basic block in LLVM IR. See the [llvm::BasicBlock] class. **) +type llbasicblock + +(** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder] + class. **) type llbuilder +(** The kind of an [lltype], the result of [classify_type ty]. See the + [llvm::Type::TypeID] enumeration. **) type type_kind = Void_type | Float_type @@ -34,10 +54,12 @@ type type_kind = | Function_type | Struct_type | Array_type -| Pointer_type +| Pointer_type | Opaque_type | Vector_type +(** The linkage of a global value, accessed with [linkage gv] and + [set_linkage l gv]. See [llvm::GlobalValue::LinkageTypes]. **) type linkage = External_linkage | Link_once_linkage @@ -49,17 +71,29 @@ type linkage = | External_weak_linkage | Ghost_linkage +(** The linker visibility of a global value, accessed with [visibility gv] and + [set_visibility v gv]. See [llvm::GlobalValue::VisibilityTypes]. **) type visibility = Default_visibility | Hidden_visibility | Protected_visibility -val ccc : int -val fastcc : int -val coldcc : int -val x86_stdcallcc : int -val x86_fastcallcc : int +(* The following calling convention values may be accessed with + [function_call_conv f] and [set_function_call_conv conv f]. Calling + conventions are open-ended. *) +val ccc : int (** [ccc] is the C calling convention. **) +val fastcc : int (** [fastcc] is the calling convention to allow LLVM + maximum optimization opportunities. Use only with + internal linkage. **) +val coldcc : int (** [coldcc] is the calling convention for + callee-save. **) +val x86_stdcallcc : int (** [x86_stdcallcc] is the familiar stdcall calling + convention from C. **) +val x86_fastcallcc : int (** [x86_fastcallcc] is the familiar fastcall calling + convention from C. **) +(** The predicate for an integer comparison ([icmp]) instruction. + See the [llvm::ICmpInst::Predicate] enumeration. **) type int_predicate = Icmp_eq | Icmp_ne @@ -72,6 +106,8 @@ type int_predicate = | Icmp_slt | Icmp_sle +(** The predicate for a floating-point comparison ([fcmp]) instruction. + See the [llvm::FCmpInst::Predicate] enumeration. **) type real_predicate = Fcmp_false | Fcmp_oeq @@ -93,332 +129,1082 @@ type real_predicate = (*===-- Modules -----------------------------------------------------------===*) -(* Creates a module with the supplied module ID. Modules are not garbage - collected; it is mandatory to call dispose_module to free memory. *) +(** [create_module id] creates a module with the supplied module ID. Modules are + not garbage collected; it is mandatory to call [dispose_module m] to free + memory. See the constructor [llvm::Module::Module]. *) external create_module : string -> llmodule = "llvm_create_module" -(* Disposes a module. All references to subordinate objects are invalidated; - referencing them will invoke undefined behavior. *) +(** [dispose_module m] destroys a module [m] and all of the IR objects it + contained. All references to subordinate objects are invalidated; + referencing them will invoke undefined behavior. See the destructor + [llvm::Module::~Module]. **) external dispose_module : llmodule -> unit = "llvm_dispose_module" -(* Adds a named type to the module's symbol table. Returns true if successful. - If such a name already exists, then no entry is added and returns false. *) +(** [define_type_name name ty m] adds a named type to the module's symbol table. + Returns [true] if successful. If such a name already exists, then no entry + is added and [false] is returned. See the [llvm::Module::addTypeName] + method. **) external define_type_name : string -> lltype -> llmodule -> bool = "llvm_add_type_name" +(** [delete_type_name name] removes a type name from the module's symbol + table. *) external delete_type_name : string -> llmodule -> unit = "llvm_delete_type_name" (*===-- Types -------------------------------------------------------------===*) + +(** [classify_type ty] returns the [type_kind] corresponding to the type [ty]. + See the method [llvm::Type::getTypeID]. **) external classify_type : lltype -> type_kind = "llvm_classify_type" -external refine_abstract_type : lltype -> lltype -> unit - = "llvm_refine_abstract_type" + +(** [string_of_lltype ty] returns a string describing the type [ty]. **) val string_of_lltype : lltype -> string (*--... Operations on integer types ........................................--*) -val i1_type : lltype -val i8_type : lltype + +(** The 1-bit integer type. See [llvm::Type::Int1Ty]. **) +val i1_type : lltype + +(** The 8-bit integer type. See [llvm::Type::Int8Ty]. **) +val i8_type : lltype + +(** The 16-bit integer type. See [llvm::Type::Int16Ty]. **) val i16_type : lltype + +(** The 32-bit integer type. See [llvm::Type::Int32Ty]. **) val i32_type : lltype + +(** The 64-bit integer type. See [llvm::Type::Int64Ty]. **) val i64_type : lltype + +(** [integer_type n] returns an integer type of bitwidth [n]. + See the method [llvm::IntegerType::get]. **) external integer_type : int -> lltype = "llvm_integer_type" + +(** [integer_bitwidth ty] returns the number of bits in the integer type [ty].. + See the method [llvm::IntegerType::getBitWidth]. **) external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth" (*--... Operations on real types ...........................................--*) + +(** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. **) val float_type : lltype + +(** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. **) val double_type : lltype + +(** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. **) val x86fp80_type : lltype + +(** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. **) val fp128_type : lltype + +(** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. **) val ppc_fp128_type : lltype (*--... Operations on function types .......................................--*) -(* FIXME: handle parameter attributes *) + +(** [function_type ret_ty param_tys] returns the function type returning + [ret_ty] and taking [param_tys] as parameters. + See the method [llvm::FunctionType::get]. **) external function_type : lltype -> lltype array -> lltype = "llvm_function_type" + +(** [va_arg_function_type ret_ty param_tys] is just like + [function_type ret_ty param_tys] except that it returns the function type + which also takes a variable number of arguments. + See the method [llvm::FunctionType::get]. **) external var_arg_function_type : lltype -> lltype array -> lltype = "llvm_var_arg_function_type" + +(** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false] + otherwise. See the method [llvm::FunctionType::isVarArg]. **) external is_var_arg : lltype -> bool = "llvm_is_var_arg" + +(** [return_type fty] gets the return type of the function type [fty]. + See the method [llvm::FunctionType::getReturnType]. **) external return_type : lltype -> lltype = "LLVMGetReturnType" + +(** [param_types fty] gets the parameter types of the function type [fty]. + See the method [llvm::FunctionType::getParamType]. **) external param_types : lltype -> lltype array = "llvm_param_types" (*--... Operations on struct types .........................................--*) + +(** [struct_type tys] returns the structure type containing in the types in the + array [tys]. See the method [llvm::StructType::get]. **) external struct_type : lltype array -> lltype = "llvm_struct_type" + +(** [struct_type tys] returns the packed structure type containing in the types + in the array [tys]. See the method [llvm::StructType::get]. **) external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type" + +(** [element_types sty] returns the constituent types of the struct type [sty]. + See the method [llvm::StructType::getElementType]. **) external element_types : lltype -> lltype array = "llvm_element_types" + +(** [is_packed sty] returns [true] if the structure type [sty] is packed, + [false] otherwise. See the method [llvm::StructType::isPacked]. **) external is_packed : lltype -> bool = "llvm_is_packed" (*--... Operations on pointer, vector, and array types .....................--*) + +(** [array_type ty n] returns the array type containing [n] elements of type + [ty]. See the method [llvm::ArrayType::get]. **) external array_type : lltype -> int -> lltype = "llvm_array_type" + +(** [pointer_type ty] returns the pointer type referencing objects of type + [ty]. See the method [llvm::PointerType::get]. **) external pointer_type : lltype -> lltype = "LLVMPointerType" + +(** [vector_type ty n] returns the array type containing [n] elements of the + primitive type [ty]. See the method [llvm::ArrayType::get]. **) external vector_type : lltype -> int -> lltype = "llvm_vector_type" +(** [element_type ty] returns the element type of the pointer, vector, or array + type [ty]. See the method [llvm::SequentialType::get]. **) external element_type : lltype -> lltype = "LLVMGetElementType" + +(** [element_type aty] returns the element count of the array type [aty]. + See the method [llvm::ArrayType::getNumElements]. **) external array_length : lltype -> int = "llvm_array_length" + +(** [element_type ty] returns the element count of the vector type [ty]. + See the method [llvm::VectorType::getNumElements]. **) external vector_size : lltype -> int = "llvm_vector_size" (*--... Operations on other types ..........................................--*) + +(** [opaque_type ()] creates a new opaque type distinct from any other. + Opaque types are useful for building recursive types in combination with + [refine_type opaque_ty ty]. + See [llvm::OpaqueType::get]. **) external opaque_type : unit -> lltype = "llvm_opaque_type" + +(** [void_type] is the type of a function which does not return any value. + See [llvm::Type::VoidTy]. **) val void_type : lltype + +(** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. **) val label_type : lltype (*--... Operations on type handles .........................................--*) + +(** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later + refined as a result of a call to [refine_type], the handle will be updated; + any bare [lltype] references will become invalid. + See the class [llvm::PATypeHolder]. **) external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type" + +(** [type_of_handle tyh] resolves the type handle [tyh]. + See the method [llvm::PATypeHolder::get()]. **) external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle" + +(** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the + concrete type [ty] in all users. Warning: This may invalidate [lltype] + values! Use [lltypehandle] to manipulate potentially abstract types. See the + method [llvm::Type::refineAbstractType]. **) external refine_type : lltype -> lltype -> unit = "llvm_refine_type" (*===-- Values ------------------------------------------------------------===*) + +(** [type_of v] returns the type of the value [v]. + See the method [llvm::Value::getType]. **) external type_of : llvalue -> lltype = "llvm_type_of" + +(** [value_name v] returns the name of the value [v]. For global values, this is + the symbol name. For instructions and basic blocks, it is the SSA register + name. It is meaningless for constants. + See the method [llvm::Value::getName]. **) external value_name : llvalue -> string = "llvm_value_name" + +(** [set_value_name n v] sets the name of the value [v] to [n]. See the method + [llvm::Value::setName]. **) external set_value_name : string -> llvalue -> unit = "llvm_set_value_name" + +(** [dump_value v] prints the .ll representation of the value [v] to standard + error. See the method [llvm::Value::dump]. **) external dump_value : llvalue -> unit = "llvm_dump_value" (*--... Operations on constants of (mostly) any type .......................--*) + +(** [is_constant v] returns [true] if the value [v] is a constant, [false] + otherwise. Similar to [llvm::isa<Constant>]. **) external is_constant : llvalue -> bool = "llvm_is_constant" + +(** [const_null ty] returns the constant null (zero) of the type [ty]. + See the method [llvm::Constant::getNullValue]. **) external const_null : lltype -> llvalue = "LLVMConstNull" + +(** [const_all_ones ty] returns the constant '-1' of the integer or vector type + [ty]. See the method [llvm::Constant::getAllOnesValue]. **) external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes" + +(** [undef ty] returns the undefined value of the type [ty]. + See the method [llvm::UndefValue::get]. **) external undef : lltype -> llvalue = "LLVMGetUndef" + +(** [is_null v] returns [true] if the value [v] is the null (zero) value. + See the method [llvm::Constant::isNullValue]. **) external is_null : llvalue -> bool = "llvm_is_null" + +(** [is_undef v] returns [true] if the value [v] is an undefined value, [false] + otherwise. Similar to [llvm::isa<UndefValue>]. **) external is_undef : llvalue -> bool = "llvm_is_undef" (*--... Operations on scalar constants .....................................--*) + +(** [const_int ty i] returns the integer constant of type [ty] and value [i]. + See the method [llvm::ConstantInt::get]. **) external const_int : lltype -> int -> llvalue = "llvm_const_int" + +(** [const_of_int64 ty i] returns the integer constant of type [ty] and value + [i]. See the method [llvm::ConstantInt::get]. **) external const_of_int64 : lltype -> Int64.t -> bool -> llvalue = "llvm_const_of_int64" + +(** [const_float ty n] returns the floating point constant of type [ty] and + value [n]. See the method [llvm::ConstantInt::get]. **) external const_float : lltype -> float -> llvalue = "llvm_const_float" (*--... Operations on composite constants ..................................--*) + +(** [const_string s] returns the constant [i8] array with the values of the + characters in the string [s]. The array is not null-terminated (but see + [const_stringz]). This value can in turn be used as the initializer for a + global variable. See the method [llvm::ConstantArray::get]. **) external const_string : string -> llvalue = "llvm_const_string" + +(** [const_stringz s] returns the constant [i8] array with the values of the + characters in the string [s] and a null terminator. This value can in turn + be used as the initializer for a global variable. + See the method [llvm::ConstantArray::get]. **) external const_stringz : string -> llvalue = "llvm_const_stringz" + +(** [const_array ty elts] returns the constant array of type + [array_type ty (Array.length elts)] and containing the values [elts]. + This value can in turn be used as the initializer for a global variable. + See the method [llvm::ConstantArray::get]. **) external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array" + +(** [const_struct elts] returns the structured constant of type + [struct_type (Array.map type_of elts)] and containing the values [elts]. + This value can in turn be used as the initializer for a global variable. + See the method [llvm::ConstantStruct::get]. **) external const_struct : llvalue array -> llvalue = "llvm_const_struct" + +(** [const_packed_struct elts] returns the structured constant of type + [packed_struct_type (Array.map type_of elts)] and containing the values + [elts]. This value can in turn be used as the initializer for a global + variable. See the method [llvm::ConstantStruct::get]. **) external const_packed_struct : llvalue array -> llvalue = "llvm_const_packed_struct" + +(** [const_vector elts] returns the vector constant of type + [vector_type (type_of elts.(0)) (Array.length elts)] and containing the + values [elts]. See the method [llvm::ConstantVector::get]. **) external const_vector : llvalue array -> llvalue = "llvm_const_vector" (*--... Constant expressions ...............................................--*) + +(** [size_of ty] returns the sizeof constant for the type [ty]. This is + equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty)) + (const_int i64_type 1)) i64_type], but considerably more readable. + See the method [llvm::ConstantExpr::getSizeOf]. **) external size_of : lltype -> llvalue = "LLVMSizeOf" + +(** [const_neg c] returns the arithmetic negation of the constant [c]. + See the method [llvm::ConstantExpr::getNeg]. **) external const_neg : llvalue -> llvalue = "LLVMConstNeg" + +(** [const_not c] returns the bitwise inverse of the constant [c]. + See the method [llvm::ConstantExpr::getNot]. **) external const_not : llvalue -> llvalue = "LLVMConstNot" + +(** [const_add c1 c2] returns the constant sum of two constants. + See the method [llvm::ConstantExpr::getAdd]. **) external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd" + +(** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two + constants. See the method [llvm::ConstantExpr::getSub]. **) external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub" + +(** [const_mul c1 c2] returns the constant product of two constants. + See the method [llvm::ConstantExpr::getMul]. **) external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul" + +(** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned + integer constants. + See the method [llvm::ConstantExpr::getUDiv]. **) external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv" + +(** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed + integer constants. + See the method [llvm::ConstantExpr::]. **) external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv" + +(** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating + point constants. + See the method [llvm::ConstantExpr::getFDiv]. **) external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv" + +(** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two + unsigned integer constants. + See the method [llvm::ConstantExpr::getURem]. **) external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem" + +(** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two + signed integer constants. + See the method [llvm::ConstantExpr::getSRem]. **) external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem" + +(** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two + signed floating point constants. + See the method [llvm::ConstantExpr::getFRem]. **) external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem" + +(** [const_and c1 c2] returns the constant bitwise [AND] of two integer + constants. + See the method [llvm::ConstantExpr::getAnd]. **) external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd" + +(** [const_or c1 c2] returns the constant bitwise [OR] of two integer + constants. + See the method [llvm::ConstantExpr::getOr]. **) external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr" + +(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer + constants. + See the method [llvm::ConstantExpr::getXor]. **) external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor" + +(** [const_icmp pred c1 c2] returns the constant comparison of two integer + constants, [c1 pred c2]. + See the method [llvm::ConstantExpr::getICmp]. **) external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue = "llvm_const_icmp" + +(** [const_fcmp pred c1 c2] returns the constant comparison of two floating + point constants, [c1 pred c2]. + See the method [llvm::ConstantExpr::getFCmp]. **) external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue = "llvm_const_fcmp" + +(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the + constant integer [c2]. + See the method [llvm::ConstantExpr::getShl]. **) external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl" + +(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the + constant integer [c2] with zero extension. + See the method [llvm::ConstantExpr::getLShr]. **) external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr" + +(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the + constant integer [c2] with sign extension. + See the method [llvm::ConstantExpr::getAShr]. **) external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr" + +(** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the + constant integers indices from the array [indices]. + See the method [llvm::ConstantExpr::getGetElementPtr]. **) external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep" + +(** [const_trunc c ty] returns the constant truncation of integer constant [c] + to the smaller integer type [ty]. + See the method [llvm::ConstantExpr::getTrunc]. **) external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc" + +(** [const_sext c ty] returns the constant sign extension of integer constant + [c] to the larger integer type [ty]. + See the method [llvm::ConstantExpr::getSExt]. **) external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt" + +(** [const_zext c ty] returns the constant zero extension of integer constant + [c] to the larger integer type [ty]. + See the method [llvm::ConstantExpr::getZExt]. **) external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt" + +(** [const_fptrunc c ty] returns the constant truncation of floating point + constant [c] to the smaller floating point type [ty]. + See the method [llvm::ConstantExpr::getFPTrunc]. **) external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc" + +(** [const_fpext c ty] returns the constant extension of floating point constant + [c] to the larger floating point type [ty]. + See the method [llvm::ConstantExpr::getFPExt]. **) external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt" + +(** [const_uitofp c ty] returns the constant floating point conversion of + unsigned integer constant [c] to the floating point type [ty]. + See the method [llvm::ConstantExpr::getUIToFP]. **) external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP" + +(** [const_sitofp c ty] returns the constant floating point conversion of + signed integer constant [c] to the floating point type [ty]. + See the method [llvm::ConstantExpr::getSIToFP]. **) external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP" + +(** [const_fptoui c ty] returns the constant unsigned integer conversion of + floating point constant [c] to integer type [ty]. + See the method [llvm::ConstantExpr::getFPToUI]. **) external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI" + +(** [const_fptoui c ty] returns the constant unsigned integer conversion of + floating point constant [c] to integer type [ty]. + See the method [llvm::ConstantExpr::getFPToSI]. **) external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI" + +(** [const_ptrtoint c ty] returns the constant integer conversion of + pointer constant [c] to integer type [ty]. + See the method [llvm::ConstantExpr::getPtrToInt]. **) external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt" + +(** [const_inttoptr c ty] returns the constant pointer conversion of + integer constant [c] to pointer type [ty]. + See the method [llvm::ConstantExpr::getIntToPtr]. **) external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr" + +(** [const_bitcast c ty] returns the constant bitwise conversion of constant [c] + to type [ty] of equal size. + See the method [llvm::ConstantExpr::getBitCast]. **) external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast" + +(** [const_select cond t f] returns the constant conditional which returns value + [t] if the boolean constant [cond] is true and the value [f] otherwise. + See the method [llvm::ConstantExpr::getSelect]. **) external const_select : llvalue -> llvalue -> llvalue -> llvalue = "LLVMConstSelect" + +(** [const_extractelement vec i] returns the constant [i]th element of + constant vector [vec]. [i] must be a constant [i32] value unsigned less than + the size of the vector. + See the method [llvm::ConstantExpr::getExtractElement]. **) external const_extractelement : llvalue -> llvalue -> llvalue = "LLVMConstExtractElement" + +(** [const_insertelement vec v i] returns the constant vector with the same + elements as constant vector [v] but the [i]th element replaced by the + constant [v]. [v] must be a constant value with the type of the vector + elements. [i] must be a constant [i32] value unsigned less than the size + of the vector. + See the method [llvm::ConstantExpr::getInsertElement]. **) external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue = "LLVMConstInsertElement" + +(** [const_shufflevector a b mask] returns a constant [shufflevector]. + See the LLVM Language Reference for details on the [sufflevector] + instruction. + See the method [llvm::ConstantExpr::getShuffleVector]. **) external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue = "LLVMConstShuffleVector" (*--... Operations on global variables, functions, and aliases (globals) ...--*) + +(** [is_declaration g] returns [true] if the global value [g] is a declaration + only. Returns [false] otherwise. + See the method [llvm::GlobalValue::isDeclaration]. **) external is_declaration : llvalue -> bool = "llvm_is_declaration" + +(** [linkage g] returns the linkage of the global value [g]. + See the method [llvm::GlobalValue::getLinkage]. **) external linkage : llvalue -> linkage = "llvm_linkage" + +(** [set_linkage l g] sets the linkage of the global value [g] to [l]. + See the method [llvm::GlobalValue::setLinkage]. **) external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage" + +(** [section g] returns the linker section of the global value [g]. + See the method [llvm::GlobalValue::getSection]. **) external section : llvalue -> string = "llvm_section" + +(** [set_section s g] sets the linker section of the global value [g] to [s]. + See the method [llvm::GlobalValue::setSection]. **) external set_section : string -> llvalue -> unit = "llvm_set_section" + +(** [visibility g] returns the linker visibility of the global value [g]. + See the method [llvm::GlobalValue::getVisibility]. **) external visibility : llvalue -> visibility = "llvm_visibility" + +(** [set_visibility v g] sets the linker visibility of the global value [g] to + [v]. See the method [llvm::GlobalValue::setVisibility]. **) external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility" + +(** [alignment g] returns the required alignment of the global value [g]. + See the method [llvm::GlobalValue::getAlignment]. **) external alignment : llvalue -> int = "llvm_alignment" + +(** [set_alignment n g] sets the required alignment of the global value [g] to + [n] bytes. See the method [llvm::GlobalValue::setAlignment]. **) external set_alignment : int -> llvalue -> unit = "llvm_set_alignment" -external is_global_constant : llvalue -> bool = "llvm_is_global_constant" -external set_global_constant : bool -> llvalue -> unit - = "llvm_set_global_constant" (*--... Operations on global variables .....................................--*) + +(** [declare_global ty name m] returns a new global variable of type [ty] and + with name [name] in module [m]. If such a global variable already exists, + it is returned. If the type of the existing global differs, then a bitcast + to [ty] is returned. **) external declare_global : lltype -> string -> llmodule -> llvalue = "llvm_declare_global" + +(** [define_global name init m] returns a new global with name [name] and + initializer [init] in module [m]. If the named global already exists, it is + renamed. + See the constructor of [llvm::GlobalVariable]. **) external define_global : string -> llvalue -> llmodule -> llvalue = "llvm_define_global" + +(** [lookup_global name m] returns [Some g] if a global variable with name + [name] exists in module [m]. If no such global exists, returns [None]. + See the [llvm::GlobalVariable] constructor. **) external lookup_global : string -> llmodule -> llvalue option = "llvm_lookup_global" + +(** [delete_global gv] destroys the global variable [gv]. + See the method [llvm::GlobalVariable::eraseFromParent]. **) external delete_global : llvalue -> unit = "llvm_delete_global" + +(** [is_global_constant gv] returns [true] if the global variabile [gv] is a + constant. Returns [false] otherwise. + See the method [llvm::GlobalVariable::isConstant]. **) +external is_global_constant : llvalue -> bool = "llvm_is_global_constant" + +(** [set_global_constant c gv] sets the global variable [gv] to be a constant if + [c] is [true] and not if [c] is [false]. + See the method [llvm::GlobalVariable::setConstant]. **) +external set_global_constant : bool -> llvalue -> unit + |