1 (*===-- tools/ml/llvm.ml - LLVM Ocaml Interface ---------------------------===*
3 * The LLVM Compiler Infrastructure
5 * This file was developed by Gordon Henriksen and is distributed under the
6 * University of Illinois Open Source License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===
10 * This interface provides an ocaml API for the LLVM intermediate
11 * representation, the classes in the VMCore library.
13 *===----------------------------------------------------------------------===*)
16 (* These abstract types correlate directly to the LLVM VMCore classes. *)
18 (** The top-level container for all other LLVM Intermediate Representation (IR)
19 objects. See the [llvm::Module] class. **)
22 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
23 [llvm::Type] class. **)
26 (** When building recursive types using [refine_type], [lltype] values may
27 become invalid; use [lltypehandle] to resolve this problem. See the
28 [llvm::AbstractTypeHolder] class. **)
31 (** Any value in the LLVM IR. Functions, instructions, global variables,
32 constants, and much more are all [llvalues]. See the [llvm::Value] class.
33 This type covers a wide range of subclasses. **)
36 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. **)
39 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
43 (** Used to provide a module to JIT or interpreter.
44 See the [llvm::ModuleProvider] class. **)
47 (** Used to efficiently handle large buffers of read-only binary data.
48 See the [llvm::MemoryBuffer] class. **)
51 (** The kind of an [lltype], the result of [classify_type ty]. See the
52 [llvm::Type::TypeID] enumeration. **)
69 (** The linkage of a global value, accessed with [linkage gv] and
70 [set_linkage l gv]. See [llvm::GlobalValue::LinkageTypes]. **)
79 | External_weak_linkage
82 (** The linker visibility of a global value, accessed with [visibility gv] and
83 [set_visibility v gv]. See [llvm::GlobalValue::VisibilityTypes]. **)
87 | Protected_visibility
89 (* The following calling convention values may be accessed with
90 [function_call_conv f] and [set_function_call_conv conv f]. Calling
91 conventions are open-ended. *)
92 val ccc : int (** [ccc] is the C calling convention. **)
93 val fastcc : int (** [fastcc] is the calling convention to allow LLVM
94 maximum optimization opportunities. Use only with
96 val coldcc : int (** [coldcc] is the calling convention for
98 val x86_stdcallcc : int (** [x86_stdcallcc] is the familiar stdcall calling
99 convention from C. **)
100 val x86_fastcallcc : int (** [x86_fastcallcc] is the familiar fastcall calling
101 convention from C. **)
103 (** The predicate for an integer comparison ([icmp]) instruction.
104 See the [llvm::ICmpInst::Predicate] enumeration. **)
117 (** The predicate for a floating-point comparison ([fcmp]) instruction.
118 See the [llvm::FCmpInst::Predicate] enumeration. **)
119 type real_predicate =
137 exception IoError of string
140 (*===-- Modules -----------------------------------------------------------===*)
142 (** [create_module id] creates a module with the supplied module ID. Modules are
143 not garbage collected; it is mandatory to call [dispose_module m] to free
144 memory. See the constructor [llvm::Module::Module]. *)
145 external create_module : string -> llmodule = "llvm_create_module"
147 (** [dispose_module m] destroys a module [m] and all of the IR objects it
148 contained. All references to subordinate objects are invalidated;
149 referencing them will invoke undefined behavior. See the destructor
150 [llvm::Module::~Module]. **)
151 external dispose_module : llmodule -> unit = "llvm_dispose_module"
153 (** [define_type_name name ty m] adds a named type to the module's symbol table.
154 Returns [true] if successful. If such a name already exists, then no entry
155 is added and [false] is returned. See the [llvm::Module::addTypeName]
157 external define_type_name : string -> lltype -> llmodule -> bool
158 = "llvm_add_type_name"
160 (** [delete_type_name name] removes a type name from the module's symbol
162 external delete_type_name : string -> llmodule -> unit
163 = "llvm_delete_type_name"
166 (*===-- Types -------------------------------------------------------------===*)
168 (** [classify_type ty] returns the [type_kind] corresponding to the type [ty].
169 See the method [llvm::Type::getTypeID]. **)
170 external classify_type : lltype -> type_kind = "llvm_classify_type"
172 (** [string_of_lltype ty] returns a string describing the type [ty]. **)
173 val string_of_lltype : lltype -> string
175 (*--... Operations on integer types ........................................--*)
177 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. **)
180 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. **)
183 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. **)
184 val i16_type : lltype
186 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. **)
187 val i32_type : lltype
189 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. **)
190 val i64_type : lltype
192 (** [integer_type n] returns an integer type of bitwidth [n].
193 See the method [llvm::IntegerType::get]. **)
194 external integer_type : int -> lltype = "llvm_integer_type"
196 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty]..
197 See the method [llvm::IntegerType::getBitWidth]. **)
198 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
200 (*--... Operations on real types ...........................................--*)
202 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. **)
203 val float_type : lltype
205 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. **)
206 val double_type : lltype
208 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. **)
209 val x86fp80_type : lltype
211 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. **)
212 val fp128_type : lltype
214 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. **)
215 val ppc_fp128_type : lltype
217 (*--... Operations on function types .......................................--*)
219 (** [function_type ret_ty param_tys] returns the function type returning
220 [ret_ty] and taking [param_tys] as parameters.
221 See the method [llvm::FunctionType::get]. **)
222 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
224 (** [va_arg_function_type ret_ty param_tys] is just like
225 [function_type ret_ty param_tys] except that it returns the function type
226 which also takes a variable number of arguments.
227 See the method [llvm::FunctionType::get]. **)
228 external var_arg_function_type : lltype -> lltype array -> lltype
229 = "llvm_var_arg_function_type"
231 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
232 otherwise. See the method [llvm::FunctionType::isVarArg]. **)
233 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
235 (** [return_type fty] gets the return type of the function type [fty].
236 See the method [llvm::FunctionType::getReturnType]. **)
237 external return_type : lltype -> lltype = "LLVMGetReturnType"
239 (** [param_types fty] gets the parameter types of the function type [fty].
240 See the method [llvm::FunctionType::getParamType]. **)
241 external param_types : lltype -> lltype array = "llvm_param_types"
243 (*--... Operations on struct types .........................................--*)
245 (** [struct_type tys] returns the structure type containing in the types in the
246 array [tys]. See the method [llvm::StructType::get]. **)
247 external struct_type : lltype array -> lltype = "llvm_struct_type"
249 (** [struct_type tys] returns the packed structure type containing in the types
250 in the array [tys]. See the method [llvm::StructType::get]. **)
251 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
253 (** [element_types sty] returns the constituent types of the struct type [sty].
254 See the method [llvm::StructType::getElementType]. **)
255 external element_types : lltype -> lltype array = "llvm_element_types"
257 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
258 [false] otherwise. See the method [llvm::StructType::isPacked]. **)
259 external is_packed : lltype -> bool = "llvm_is_packed"
261 (*--... Operations on pointer, vector, and array types .....................--*)
263 (** [array_type ty n] returns the array type containing [n] elements of type
264 [ty]. See the method [llvm::ArrayType::get]. **)
265 external array_type : lltype -> int -> lltype = "llvm_array_type"
267 (** [pointer_type ty] returns the pointer type referencing objects of type
268 [ty] in the default address space (0).
269 See the method [llvm::PointerType::getUnqual]. **)
270 external pointer_type : lltype -> lltype = "llvm_pointer_type"
272 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
273 of type [ty] in address space [as].
274 See the method [llvm::PointerType::get]. **)
275 external qualified_pointer_type : lltype -> int -> lltype
276 = "llvm_qualified_pointer_type"
278 (** [vector_type ty n] returns the array type containing [n] elements of the
279 primitive type [ty]. See the method [llvm::ArrayType::get]. **)
280 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
282 (** [element_type ty] returns the element type of the pointer, vector, or array
283 type [ty]. See the method [llvm::SequentialType::get]. **)
284 external element_type : lltype -> lltype = "LLVMGetElementType"
286 (** [element_type aty] returns the element count of the array type [aty].
287 See the method [llvm::ArrayType::getNumElements]. **)
288 external array_length : lltype -> int = "llvm_array_length"
290 (** [address_space pty] returns the address space qualifier of the pointer type
291 [pty]. See the method [llvm::PointerType::getAddressSpace]. **)
292 external address_space : lltype -> int = "llvm_address_space"
294 (** [element_type ty] returns the element count of the vector type [ty].
295 See the method [llvm::VectorType::getNumElements]. **)
296 external vector_size : lltype -> int = "llvm_vector_size"
298 (*--... Operations on other types ..........................................--*)
300 (** [opaque_type ()] creates a new opaque type distinct from any other.
301 Opaque types are useful for building recursive types in combination with
302 [refine_type opaque_ty ty].
303 See [llvm::OpaqueType::get]. **)
304 external opaque_type : unit -> lltype = "llvm_opaque_type"
306 (** [void_type] is the type of a function which does not return any value.
307 See [llvm::Type::VoidTy]. **)
308 val void_type : lltype
310 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. **)
311 val label_type : lltype
313 (*--... Operations on type handles .........................................--*)
315 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
316 refined as a result of a call to [refine_type], the handle will be updated;
317 any bare [lltype] references will become invalid.
318 See the class [llvm::PATypeHolder]. **)
319 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
321 (** [type_of_handle tyh] resolves the type handle [tyh].
322 See the method [llvm::PATypeHolder::get()]. **)
323 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
325 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
326 concrete type [ty] in all users. Warning: This may invalidate [lltype]
327 values! Use [lltypehandle] to manipulate potentially abstract types. See the
328 method [llvm::Type::refineAbstractType]. **)
329 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
332 (*===-- Values ------------------------------------------------------------===*)
334 (** [type_of v] returns the type of the value [v].
335 See the method [llvm::Value::getType]. **)
336 external type_of : llvalue -> lltype = "llvm_type_of"
338 (** [value_name v] returns the name of the value [v]. For global values, this is
339 the symbol name. For instructions and basic blocks, it is the SSA register
340 name. It is meaningless for constants.
341 See the method [llvm::Value::getName]. **)
342 external value_name : llvalue -> string = "llvm_value_name"
344 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
345 [llvm::Value::setName]. **)
346 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
348 (** [dump_value v] prints the .ll representation of the value [v] to standard
349 error. See the method [llvm::Value::dump]. **)
350 external dump_value : llvalue -> unit = "llvm_dump_value"
352 (*--... Operations on constants of (mostly) any type .......................--*)
354 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
355 otherwise. Similar to [llvm::isa<Constant>]. **)
356 external is_constant : llvalue -> bool = "llvm_is_constant"
358 (** [const_null ty] returns the constant null (zero) of the type [ty].
359 See the method [llvm::Constant::getNullValue]. **)
360 external const_null : lltype -> llvalue = "LLVMConstNull"
362 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
363 [ty]. See the method [llvm::Constant::getAllOnesValue]. **)
364 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
366 (** [undef ty] returns the undefined value of the type [ty].
367 See the method [llvm::UndefValue::get]. **)
368 external undef : lltype -> llvalue = "LLVMGetUndef"
370 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
371 See the method [llvm::Constant::isNullValue]. **)
372 external is_null : llvalue -> bool = "llvm_is_null"
374 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
375 otherwise. Similar to [llvm::isa<UndefValue>]. **)
376 external is_undef : llvalue -> bool = "llvm_is_undef"
378 (*--... Operations on scalar constants .....................................--*)
380 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
381 See the method [llvm::ConstantInt::get]. **)
382 external const_int : lltype -> int -> llvalue = "llvm_const_int"
384 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
385 [i]. See the method [llvm::ConstantInt::get]. **)
386 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
387 = "llvm_const_of_int64"
389 (** [const_float ty n] returns the floating point constant of type [ty] and
390 value [n]. See the method [llvm::ConstantInt::get]. **)
391 external const_float : lltype -> float -> llvalue = "llvm_const_float"
393 (*--... Operations on composite constants ..................................--*)
395 (** [const_string s] returns the constant [i8] array with the values of the
396 characters in the string [s]. The array is not null-terminated (but see
397 [const_stringz]). This value can in turn be used as the initializer for a
398 global variable. See the method [llvm::ConstantArray::get]. **)
399 external const_string : string -> llvalue = "llvm_const_string"
401 (** [const_stringz s] returns the constant [i8] array with the values of the
402 characters in the string [s] and a null terminator. This value can in turn
403 be used as the initializer for a global variable.
404 See the method [llvm::ConstantArray::get]. **)
405 external const_stringz : string -> llvalue = "llvm_const_stringz"
407 (** [const_array ty elts] returns the constant array of type
408 [array_type ty (Array.length elts)] and containing the values [elts].
409 This value can in turn be used as the initializer for a global variable.
410 See the method [llvm::ConstantArray::get]. **)
411 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
413 (** [const_struct elts] returns the structured constant of type
414 [struct_type (Array.map type_of elts)] and containing the values [elts].
415 This value can in turn be used as the initializer for a global variable.
416 See the method [llvm::ConstantStruct::get]. **)
417 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
419 (** [const_packed_struct elts] returns the structured constant of type
420 [packed_struct_type (Array.map type_of elts)] and containing the values
421 [elts]. This value can in turn be used as the initializer for a global
422 variable. See the method [llvm::ConstantStruct::get]. **)
423 external const_packed_struct : llvalue array -> llvalue
424 = "llvm_const_packed_struct"
426 (** [const_vector elts] returns the vector constant of type
427 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
428 values [elts]. See the method [llvm::ConstantVector::get]. **)
429 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
431 (*--... Constant expressions ...............................................--*)
433 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
434 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
435 (const_int i64_type 1)) i64_type], but considerably more readable.
436 See the method [llvm::ConstantExpr::getSizeOf]. **)
437 external size_of : lltype -> llvalue = "LLVMSizeOf"
439 (** [const_neg c] returns the arithmetic negation of the constant [c].
440 See the method [llvm::ConstantExpr::getNeg]. **)
441 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
443 (** [const_not c] returns the bitwise inverse of the constant [c].
444 See the method [llvm::ConstantExpr::getNot]. **)
445 external const_not : llvalue -> llvalue = "LLVMConstNot"
447 (** [const_add c1 c2] returns the constant sum of two constants.
448 See the method [llvm::ConstantExpr::getAdd]. **)
449 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
451 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
452 constants. See the method [llvm::ConstantExpr::getSub]. **)
453 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
455 (** [const_mul c1 c2] returns the constant product of two constants.
456 See the method [llvm::ConstantExpr::getMul]. **)
457 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
459 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
461 See the method [llvm::ConstantExpr::getUDiv]. **)
462 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
464 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
466 See the method [llvm::ConstantExpr::]. **)
467 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
469 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
471 See the method [llvm::ConstantExpr::getFDiv]. **)
472 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
474 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
475 unsigned integer constants.
476 See the method [llvm::ConstantExpr::getURem]. **)
477 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
479 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
480 signed integer constants.
481 See the method [llvm::ConstantExpr::getSRem]. **)
482 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
484 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
485 signed floating point constants.
486 See the method [llvm::ConstantExpr::getFRem]. **)
487 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
489 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
491 See the method [llvm::ConstantExpr::getAnd]. **)
492 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
494 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
496 See the method [llvm::ConstantExpr::getOr]. **)
497 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
499 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
501 See the method [llvm::ConstantExpr::getXor]. **)
502 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
504 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
505 constants, [c1 pred c2].
506 See the method [llvm::ConstantExpr::getICmp]. **)
507 external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
510 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
511 point constants, [c1 pred c2].
512 See the method [llvm::ConstantExpr::getFCmp]. **)
513 external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
516 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
517 constant integer [c2].
518 See the method [llvm::ConstantExpr::getShl]. **)
519 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
521 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
522 constant integer [c2] with zero extension.
523 See the method [llvm::ConstantExpr::getLShr]. **)
524 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
526 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
527 constant integer [c2] with sign extension.
528 See the method [llvm::ConstantExpr::getAShr]. **)
529 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
531 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
532 constant integers indices from the array [indices].
533 See the method [llvm::ConstantExpr::getGetElementPtr]. **)
534 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
536 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
537 to the smaller integer type [ty].
538 See the method [llvm::ConstantExpr::getTrunc]. **)
539 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
541 (** [const_sext c ty] returns the constant sign extension of integer constant
542 [c] to the larger integer type [ty].
543 See the method [llvm::ConstantExpr::getSExt]. **)
544 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
546 (** [const_zext c ty] returns the constant zero extension of integer constant
547 [c] to the larger integer type [ty].
548 See the method [llvm::ConstantExpr::getZExt]. **)
549 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
551 (** [const_fptrunc c ty] returns the constant truncation of floating point
552 constant [c] to the smaller floating point type [ty].
553 See the method [llvm::ConstantExpr::getFPTrunc]. **)
554 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
556 (** [const_fpext c ty] returns the constant extension of floating point constant
557 [c] to the larger floating point type [ty].
558 See the method [llvm::ConstantExpr::getFPExt]. **)
559 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
561 (** [const_uitofp c ty] returns the constant floating point conversion of
562 unsigned integer constant [c] to the floating point type [ty].
563 See the method [llvm::ConstantExpr::getUIToFP]. **)
564 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
566 (** [const_sitofp c ty] returns the constant floating point conversion of
567 signed integer constant [c] to the floating point type [ty].
568 See the method [llvm::ConstantExpr::getSIToFP]. **)
569 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
571 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
572 floating point constant [c] to integer type [ty].
573 See the method [llvm::ConstantExpr::getFPToUI]. **)
574 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
576 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
577 floating point constant [c] to integer type [ty].
578 See the method [llvm::ConstantExpr::getFPToSI]. **)
579 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
581 (** [const_ptrtoint c ty] returns the constant integer conversion of
582 pointer constant [c] to integer type [ty].
583 See the method [llvm::ConstantExpr::getPtrToInt]. **)
584 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
586 (** [const_inttoptr c ty] returns the constant pointer conversion of
587 integer constant [c] to pointer type [ty].
588 See the method [llvm::ConstantExpr::getIntToPtr]. **)
589 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
591 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
592 to type [ty] of equal size.
593 See the method [llvm::ConstantExpr::getBitCast]. **)
594 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
596 (** [const_select cond t f] returns the constant conditional which returns value
597 [t] if the boolean constant [cond] is true and the value [f] otherwise.
598 See the method [llvm::ConstantExpr::getSelect]. **)
599 external const_select : llvalue -> llvalue -> llvalue -> llvalue
602 (** [const_extractelement vec i] returns the constant [i]th element of
603 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
604 the size of the vector.
605 See the method [llvm::ConstantExpr::getExtractElement]. **)
606 external const_extractelement : llvalue -> llvalue -> llvalue
607 = "LLVMConstExtractElement"
609 (** [const_insertelement vec v i] returns the constant vector with the same
610 elements as constant vector [v] but the [i]th element replaced by the
611 constant [v]. [v] must be a constant value with the type of the vector
612 elements. [i] must be a constant [i32] value unsigned less than the size
614 See the method [llvm::ConstantExpr::getInsertElement]. **)
615 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
616 = "LLVMConstInsertElement"
618 (** [const_shufflevector a b mask] returns a constant [shufflevector].
619 See the LLVM Language Reference for details on the [sufflevector]
621 See the method [llvm::ConstantExpr::getShuffleVector]. **)
622 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
623 = "LLVMConstShuffleVector"
625 (*--... Operations on global variables, functions, and aliases (globals) ...--*)
627 (** [is_declaration g] returns [true] if the global value [g] is a declaration
628 only. Returns [false] otherwise.
629 See the method [llvm::GlobalValue::isDeclaration]. **)
630 external is_declaration : llvalue -> bool = "llvm_is_declaration"
632 (** [linkage g] returns the linkage of the global value [g].
633 See the method [llvm::GlobalValue::getLinkage]. **)
634 external linkage : llvalue -> linkage = "llvm_linkage"
636 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
637 See the method [llvm::GlobalValue::setLinkage]. **)
638 external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
640 (** [section g] returns the linker section of the global value [g].
641 See the method [llvm::GlobalValue::getSection]. **)
642 external section : llvalue -> string = "llvm_section"
644 (** [set_section s g] sets the linker section of the global value [g] to [s].
645 See the method [llvm::GlobalValue::setSection]. **)
646 external set_section : string -> llvalue -> unit = "llvm_set_section"
648 (** [visibility g] returns the linker visibility of the global value [g].
649 See the method [llvm::GlobalValue::getVisibility]. **)
650 external visibility : llvalue -> visibility = "llvm_visibility"
652 (** [set_visibility v g] sets the linker visibility of the global value [g] to
653 [v]. See the method [llvm::GlobalValue::setVisibility]. **)
654 external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
656 (** [alignment g] returns the required alignment of the global value [g].
657 See the method [llvm::GlobalValue::getAlignment]. **)
658 external alignment : llvalue -> int = "llvm_alignment"
660 (** [set_alignment n g] sets the required alignment of the global value [g] to
661 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. **)
662 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
664 (*--... Operations on global variables .....................................--*)
666 (** [declare_global ty name m] returns a new global variable of type [ty] and
667 with name [name] in module [m]. If such a global variable already exists,
668 it is returned. If the type of the existing global differs, then a bitcast
669 to [ty] is returned. **)
670 external declare_global : lltype -> string -> llmodule -> llvalue
671 = "llvm_declare_global"
673 (** [define_global name init m] returns a new global with name [name] and
674 initializer [init] in module [m]. If the named global already exists, it is
676 See the constructor of [llvm::GlobalVariable]. **)
677 external define_global : string -> llvalue -> llmodule -> llvalue
678 = "llvm_define_global"
680 (** [lookup_global name m] returns [Some g] if a global variable with name
681 [name] exists in module [m]. If no such global exists, returns [None].
682 See the [llvm::GlobalVariable] constructor. **)
683 external lookup_global : string -> llmodule -> llvalue option
684 = "llvm_lookup_global"
686 (** [delete_global gv] destroys the global variable [gv].
687 See the method [llvm::GlobalVariable::eraseFromParent]. **)
688 external delete_global : llvalue -> unit = "llvm_delete_global"
690 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
691 constant. Returns [false] otherwise.
692 See the method [llvm::GlobalVariable::isConstant]. **)
693 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
695 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
696 [c] is [true] and not if [c] is [false].
697 See the method [llvm::GlobalVariable::setConstant]. **)
698 external set_global_constant : bool -> llvalue -> unit
699 = "llvm_set_global_constant"
701 (** [has_initializer gv] returns [true] if the global variable [gv] has an
702 initializer and [false] otherwise.
703 See the method [llvm::GlobalVariable::hasInitializer]. **)
704 external has_initializer : llvalue -> bool = "llvm_has_initializer"
706 (** [global_initializer gv] returns the initializer for the global variable
707 [gv]. See the method [llvm::GlobalVariable::getInitializer]. **)
708 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
710 (** [set_initializer c gv] sets the initializer for the global variable
711 [gv] to the constant [c].
712 See the method [llvm::GlobalVariable::setInitializer]. **)
713 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
715 (** [remove_initializer gv] unsets the initializer for the global variable
717 See the method [llvm::GlobalVariable::setInitializer]. **)
718 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
720 (** [is_thread_local gv] returns [true] if the global variable [gv] is
721 thread-local and [false] otherwise.
722 See the method [llvm::GlobalVariable::isThreadLocal]. **)
723 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
725 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
726 [c] is [true] and not otherwise.
727 See the method [llvm::GlobalVariable::setThreadLocal]. **)
728 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
730 (*--... Operations on functions ............................................--*)
732 (** [declare_function name ty m] returns a new function of type [ty] and
733 with name [name] in module [m]. If such a function already exists,
734 it is returned. If the type of the existing function differs, then a bitcast
735 to [ty] is returned. **)
736 external declare_function : string -> lltype -> llmodule -> llvalue
737 = "llvm_declare_function"
739 (** [define_function name ty m] creates a new function with name [name] and
740 type [ty] in module [m]. If the named function already exists, it is
741 renamed. An entry basic block is created in the function.
742 See the constructor of [llvm::GlobalVariable]. **)
743 external define_function : string -> lltype -> llmodule -> llvalue
744 = "llvm_define_function"
746 (** [lookup_function name m] returns [Some f] if a function with name
747 [name] exists in module [m]. If no such function exists, returns [None].
748 See the method [llvm::Module] constructor. **)
749 external lookup_function : string -> llmodule -> llvalue option
750 = "llvm_lookup_function"
752 (** [delete_function f] destroys the function [f].
753 See the method [llvm::Function::eraseFromParent]. **)
754 external delete_function : llvalue -> unit = "llvm_delete_function"
756 (** [params f] returns the parameters of function [f].
757 See the method [llvm::Function::getArgumentList]. **)
758 external params : llvalue -> llvalue array = "llvm_params"
760 (** [param f n] returns the [n]th parameter of function [f].
761 See the method [llvm::Function::getArgumentList]. **)
762 external param : llvalue -> int -> llvalue = "llvm_param"
764 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
765 See the method [llvm::Function::isIntrinsic]. **)
766 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
768 (** [function_call_conv f] returns the calling convention of the function [f].
769 See the method [llvm::Function::getCallingConv]. **)
770 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
772 (** [set_function_call_conv cc f] sets the calling convention of the function
773 [f] to the calling convention numbered [cc].
774 See the method [llvm::Function::setCallingConv]. **)
775 external set_function_call_conv : int -> llvalue -> unit
776 = "llvm_set_function_call_conv"
778 (** [collector f] returns [Some name] if the function [f] has a garbage
779 collection algorithm specified and [None] otherwise.
780 See the method [llvm::Function::getCollector]. **)
781 external collector : llvalue -> string option = "llvm_collector"
783 (** [set_collector gc f] sets the collection algorithm for the function [f] to
784 [gc]. See the method [llvm::Function::setCollector]. **)
785 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
787 (*--... Operations on basic blocks .........................................--*)
789 (** [basic_blocks fn] returns the basic blocks of the function [f].
790 See the method [llvm::Function::getBasicBlockList]. **)
791 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
793 (** [entry_block fn] returns the entry basic block of the function [f].
794 See the method [llvm::Function::getEntryBlock]. **)
795 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
797 (** [delete_block bb] deletes the basic block [bb].
798 See the method [llvm::BasicBlock::eraseFromParent]. **)
799 external delete_block : llbasicblock -> unit = "llvm_delete_block"
801 (** [append_block name f] creates a new basic block named [name] at the end of
803 See the constructor of [llvm::BasicBlock]. **)
804 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
806 (** [insert_block name bb] creates a new basic block named [name] before the
808 See the constructor of [llvm::BasicBlock]. **)
809 external insert_block : string -> llbasicblock -> llbasicblock
810 = "llvm_insert_block"
812 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. **)
813 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
815 (** [value_is_block v] returns [true] if the value [v] is a basic block and
817 Similar to [llvm::isa<BasicBlock>]. **)
818 external value_is_block : llvalue -> bool = "llvm_value_is_block"
820 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. **)
821 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
823 (*--... Operations on phi nodes ............................................--*)
825 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
826 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. **)
827 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
828 = "llvm_add_incoming"
830 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
831 See the method [llvm::PHINode::getIncomingValue]. **)
832 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
835 (*===-- Instruction builders ----------------------------------------------===*)
837 (** [builder_before ins] creates an instruction builder positioned before the
838 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. **)
839 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
841 (** [builder_at_end bb] creates an instruction builder positioned at the end of
842 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. **)
843 external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
845 (** [position_before ins b] moves the instruction builder [b] to before the
846 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
847 external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
849 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
850 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. **)
851 external position_at_end : llbasicblock -> llbuilder -> unit
852 = "llvm_position_at_end"
854 (*--... Terminators ........................................................--*)
856 (** [build_ret_void b] creates a
858 instruction at the position specified by the instruction builder [b].
859 See the method [llvm::LLVMBuilder::CreateRetVoid]. **)
860 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
862 (** [build_ret v b] creates a
864 instruction at the position specified by the instruction builder [b].
865 See the method [llvm::LLVMBuilder::CreateRet]. **)
866 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
868 (** [build_br bb b] creates a
870 instruction at the position specified by the instruction builder [b].
871 See the method [llvm::LLVMBuilder::CreateBr]. **)
872 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
874 (** [build_cond_br cond tbb fbb b] creates a
875 [b %cond, %tbb, %fbb]
876 instruction at the position specified by the instruction builder [b].
877 See the method [llvm::LLVMBuilder::CreateCondBr]. **)
878 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
879 llvalue = "llvm_build_cond_br"
881 (** [build_switch case elsebb b] creates an empty
882 [switch %case, %elsebb]
883 instruction at the position specified by the instruction builder [b].
884 See the method [llvm::LLVMBuilder::CreateSwitch]. **)
885 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
886 = "llvm_build_switch"
888 (** [build_invoke fn args tobb unwindbb name b] creates an
889 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
890 instruction at the position specified by the instruction builder [b].
891 See the method [llvm::LLVMBuilder::CreateInvoke]. **)
892 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
893 llbasicblock -> string -> llbuilder -> llvalue
894 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
896 (** [build_unwind b] creates an
898 instruction at the position specified by the instruction builder [b].
899 See the method [llvm::LLVMBuilder::CreateUnwind]. **)
900 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
902 (** [build_unreachable b] creates an
904 instruction at the position specified by the instruction builder [b].
905 See the method [llvm::LLVMBuilder::CreateUnwind]. **)
906 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
908 (*--... Arithmetic .........................................................--*)
910 (** [build_add x y name b] creates a
912 instruction at the position specified by the instruction builder [b].
913 See the method [llvm::LLVMBuilder::CreateAdd]. **)
914 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
917 (** [build_sub x y name b] creates a
919 instruction at the position specified by the instruction builder [b].
920 See the method [llvm::LLVMBuilder::CreateSub]. **)
921 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
924 (** [build_mul x y name b] creates a
926 instruction at the position specified by the instruction builder [b].
927 See the method [llvm::LLVMBuilder::CreateMul]. **)
928 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
931 (** [build_udiv x y name b] creates a
932 [%name = udiv %x, %y]
933 instruction at the position specified by the instruction builder [b].
934 See the method [llvm::LLVMBuilder::CreateUDiv]. **)
935 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
938 (** [build_sdiv x y name b] creates a
939 [%name = sdiv %x, %y]
940 instruction at the position specified by the instruction builder [b].
941 See the method [llvm::LLVMBuilder::CreateSDiv]. **)
942 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
945 (** [build_fdiv x y name b] creates a
946 [%name = fdiv %x, %y]
947 instruction at the position specified by the instruction builder [b].
948 See the method [llvm::LLVMBuilder::CreateFDiv]. **)
949 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
952 (** [build_urem x y name b] creates a
953 [%name = urem %x, %y]
954 instruction at the position specified by the instruction builder [b].
955 See the method [llvm::LLVMBuilder::CreateURem]. **)
956 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
959 (** [build_SRem x y name b] creates a
960 [%name = srem %x, %y]
961 instruction at the position specified by the instruction builder [b].
962 See the method [llvm::LLVMBuilder::CreateSRem]. **)
963 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
966 (** [build_frem x y name b] creates a
967 [%name = frem %x, %y]
968 instruction at the position specified by the instruction builder [b].
969 See the method [llvm::LLVMBuilder::CreateFRem]. **)
970 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
973 (** [build_shl x y name b] creates a
975 instruction at the position specified by the instruction builder [b].
976 See the method [llvm::LLVMBuilder::CreateShl]. **)
977 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
980 (** [build_lshr x y name b] creates a
981 [%name = lshr %x, %y]
982 instruction at the position specified by the instruction builder [b].
983 See the method [llvm::LLVMBuilder::CreateLShr]. **)
984 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
987 (** [build_ashr x y name b] creates a
988 [%name = ashr %x, %y]
989 instruction at the position specified by the instruction builder [b].
990 See the method [llvm::LLVMBuilder::CreateAShr]. **)
991 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
994 (** [build_and x y name b] creates a
996 instruction at the position specified by the instruction builder [b].
997 See the method [llvm::LLVMBuilder::CreateAnd]. **)
998 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1001 (** [build_or x y name b] creates a
1003 instruction at the position specified by the instruction builder [b].
1004 See the method [llvm::LLVMBuilder::CreateOr]. **)
1005 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1008 (** [build_xor x y name b] creates a
1009 [%name = xor %x, %y]
1010 instruction at the position specified by the instruction builder [b].
1011 See the method [llvm::LLVMBuilder::CreateXor]. **)
1012 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1015 (** [build_neg x name b] creates a
1017 instruction at the position specified by the instruction builder [b].
1018 [-0.0] is used for floating point types to compute the correct sign.
1019 See the method [llvm::LLVMBuilder::CreateNeg]. **)
1020 external build_neg : llvalue -> string -> llbuilder -> llvalue
1023 (** [build_xor x name b] creates a
1024 [%name = xor %x, -1]
1025 instruction at the position specified by the instruction builder [b].
1026 [-1] is the correct "all ones" value for the type of [x].
1027 See the method [llvm::LLVMBuilder::CreateXor]. **)
1028 external build_not : llvalue -> string -> llbuilder -> llvalue
1031 (*--... Memory .............................................................--*)
1033 (** [build_malloc ty name b] creates a
1034 [%name = malloc %ty]
1035 instruction at the position specified by the instruction builder [b].
1036 See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1037 external build_malloc : lltype -> string -> llbuilder -> llvalue
1038 = "llvm_build_malloc"
1040 (** [build_array_malloc ty n name b] creates a
1041 [%name = malloc %ty, %n]
1042 instruction at the position specified by the instruction builder [b].
1043 See the method [llvm::LLVMBuilder::CreateMalloc]. **)
1044 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1045 llvalue = "llvm_build_array_malloc"
1047 (** [build_alloca ty name b] creates a
1048 [%name = alloca %ty]
1049 instruction at the position specified by the instruction builder [b].
1050 See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1051 external build_alloca : lltype -> string -> llbuilder -> llvalue
1052 = "llvm_build_alloca"
1054 (** [build_array_alloca ty n name b] creates a
1055 [%name = alloca %ty, %n]
1056 instruction at the position specified by the instruction builder [b].
1057 See the method [llvm::LLVMBuilder::CreateAlloca]. **)
1058 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1059 llvalue = "llvm_build_array_alloca"
1061 (** [build_free v b] creates a
1063 instruction at the position specified by the instruction builder [b].
1064 See the method [llvm::LLVMBuilder::CreateFree]. **)
1065 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1067 (** [build_load v name b] creates a
1069 instruction at the position specified by the instruction builder [b].
1070 See the method [llvm::LLVMBuilder::CreateLoad]. **)
1071 external build_load : llvalue -> string -> llbuilder -> llvalue
1074 (** [build_store v p b] creates a
1076 instruction at the position specified by the instruction builder [b].
1077 See the method [llvm::LLVMBuilder::CreateStore]. **)
1078 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1079 = "llvm_build_store"
1081 (** [build_store p indices name b] creates a
1082 [%name = gep %p, indices...]
1083 instruction at the position specified by the instruction builder [b].
1084 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. **)
1085 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1088 (*--... Casts ..............................................................--*)
1090 (** [build_trunc v ty name b] creates a
1091 [%name = trunc %p to %ty]
1092 instruction at the position specified by the instruction builder [b].
1093 See the method [llvm::LLVMBuilder::CreateTrunc]. **)
1094 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1095 = "llvm_build_trunc"
1097 (** [build_zext v ty name b] creates a
1098 [%name = zext %p to %ty]
1099 instruction at the position specified by the instruction builder [b].
1100 See the method [llvm::LLVMBuilder::CreateZExt]. **)
1101 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1104 (** [build_sext v ty name b] creates a
1105 [%name = sext %p to %ty]
1106 instruction at the position specified by the instruction builder [b].
1107 See the method [llvm::LLVMBuilder::CreateSExt]. **)
1108 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1111 (** [build_fptoui v ty name b] creates a
1112 [%name = fptoui %p to %ty]
1113 instruction at the position specified by the instruction builder [b].
1114 See the method [llvm::LLVMBuilder::CreateFPToUI]. **)
1115 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1116 = "llvm_build_fptoui"
1118 (** [build_fptosi v ty name b] creates a
1119 [%name = fptosi %p to %ty]
1120 instruction at the position specified by the instruction builder [b].
1121 See the method [llvm::LLVMBuilder::CreateFPToSI]. **)
1122 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1123 = "llvm_build_fptosi"
1125 (** [build_uitofp v ty name b] creates a
1126 [%name = uitofp %p to %ty]
1127 instruction at the position specified by the instruction builder [b].
1128 See the method [llvm::LLVMBuilder::CreateUIToFP]. **)
1129 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1130 = "llvm_build_uitofp"
1132 (** [build_sitofp v ty name b] creates a
1133 [%name = sitofp %p to %ty]
1134 instruction at the position specified by the instruction builder [b].
1135 See the method [llvm::LLVMBuilder::CreateSIToFP]. **)
1136 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1137 = "llvm_build_sitofp"
1139 (** [build_fptrunc v ty name b] creates a
1140 [%name = fptrunc %p to %ty]
1141 instruction at the position specified by the instruction builder [b].
1142 See the method [llvm::LLVMBuilder::CreateFPTrunc]. **)
1143 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1144 = "llvm_build_fptrunc"
1146 (** [build_fpext v ty name b] creates a
1147 [%name = fpext %p to %ty]
1148 instruction at the position specified by the instruction builder [b].
1149 See the method [llvm::LLVMBuilder::CreateFPExt]. **)
1150 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1151 = "llvm_build_fpext"
1153 (** [build_ptrtoint v ty name b] creates a
1154 [%name = prtotint %p to %ty]
1155 instruction at the position specified by the instruction builder [b].
1156 See the method [llvm::LLVMBuilder::CreatePtrToInt]. **)
1157 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1158 = "llvm_build_prttoint"
1160 (** [build_inttoptr v ty name b] creates a
1161 [%name = inttoptr %p to %ty]
1162 instruction at the position specified by the instruction builder [b].
1163 See the method [llvm::LLVMBuilder::CreateIntToPtr]. **)
1164 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1165 = "llvm_build_inttoptr"
1167 (** [build_bitcast v ty name b] creates a
1168 [%name = bitcast %p to %ty]
1169 instruction at the position specified by the instruction builder [b].
1170 See the method [llvm::LLVMBuilder::CreateBitcast]. **)
1171 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1172 = "llvm_build_bitcast"
1174 (*--... Comparisons ........................................................--*)
1176 (** [build_icmp pred x y name b] creates a
1177 [%name = icmp %pred %x, %y]
1178 instruction at the position specified by the instruction builder [b].
1179 See the method [llvm::LLVMBuilder::CreateICmp]. **)
1180 external build_icmp : int_predicate -> llvalue -> llvalue -> string ->
1181 llbuilder -> llvalue = "llvm_build_icmp"
1183 (** [build_fcmp pred x y name b] creates a
1184 [%name = fcmp %pred %x, %y]
1185 instruction at the position specified by the instruction builder [b].
1186 See the method [llvm::LLVMBuilder::CreateFCmp]. **)
1187 external build_fcmp : real_predicate -> llvalue -> llvalue -> string ->
1188 llbuilder -> llvalue = "llvm_build_fcmp"
1190 (*--... Miscellaneous instructions .........................................--*)
1192 (** [build_phi incoming name b] creates a
1193 [%name = phi %incoming]
1194 instruction at the position specified by the instruction builder [b].
1195 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1196 See the method [llvm::LLVMBuilder::CreatePHI]. **)
1197 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1198 llvalue = "llvm_build_phi"
1200 (** [build_call fn args name b] creates a
1201 [%name = call %fn(args...)]
1202 instruction at the position specified by the instruction builder [b].
1203 See the method [llvm::LLVMBuilder::CreateCall]. **)
1204 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1207 (** [build_select cond thenv elsev name b] creates a
1208 [%name = select %cond, %thenv, %elsev]
1209 instruction at the position specified by the instruction builder [b].
1210 See the method [llvm::LLVMBuilder::CreateSelect]. **)
1211 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1212 llvalue = "llvm_build_select"
1214 (** [build_va_arg valist argty name b] creates a
1215 [%name = va_arg %valist, %argty]
1216 instruction at the position specified by the instruction builder [b].
1217 See the method [llvm::LLVMBuilder::CreateVAArg]. **)
1218 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1219 = "llvm_build_va_arg"
1221 (** [build_extractelement vec i name b] creates a
1222 [%name = extractelement %vec, %i]
1223 instruction at the position specified by the instruction builder [b].
1224 See the method [llvm::LLVMBuilder::CreateExtractElement]. **)
1225 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1226 llvalue = "llvm_build_extractelement"
1228 (** [build_insertelement vec elt i name b] creates a
1229 [%name = insertelement %vec, %elt, %i]
1230 instruction at the position specified by the instruction builder [b].
1231 See the method [llvm::LLVMBuilder::CreateInsertElement]. **)
1232 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1233 llbuilder -> llvalue = "llvm_build_insertelement"
1235 (** [build_shufflevector veca vecb mask name b] creates a
1236 [%name = shufflevector %veca, %vecb, %mask]
1237 instruction at the position specified by the instruction builder [b].
1238 See the method [llvm::LLVMBuilder::CreateShuffleVector]. **)
1239 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1240 llbuilder -> llvalue = "llvm_build_shufflevector"
1243 (*===-- Module providers --------------------------------------------------===*)
1245 module ModuleProvider : sig
1246 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1247 ownership of the module. See the constructor
1248 [llvm::ExistingModuleProvider::ExistingModuleProvider]. **)
1249 external create : llmodule -> llmoduleprovider
1250 = "LLVMCreateModuleProviderForExistingModule"
1252 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1253 the contained module. **)
1254 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1258 (*===-- Memory buffers ----------------------------------------------------===*)
1260 module MemoryBuffer : sig
1261 (** [of_file p] is the memory buffer containing the contents of the file at
1262 path [p]. If the file could not be read, then [IoError msg] is raised. **)
1263 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1265 (** [stdin ()] is the memory buffer containing the contents of standard input.
1266 If standard input is empty, then [IoError msg] is raised. **)
1267 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1269 (** Disposes of a memory buffer. **)
1270 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"