* 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 llmoduleprovider
type type_kind =
Void_type
(*===-- 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"
(*===-- 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"
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"
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"
external function_call_conv : llvalue -> int = "llvm_function_call_conv"
external set_function_call_conv : int -> llvalue -> unit
= "llvm_set_function_call_conv"
+external collector : llvalue -> string option = "llvm_collector"
+external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
(* TODO: param attrs *)
external value_is_block : llvalue -> bool = "llvm_value_is_block"
external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
+(*--... Operations on phi nodes ............................................--*)
+external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
+ = "llvm_add_incoming"
+external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
+
(*===-- Instruction builders ----------------------------------------------===*)
external builder_before : llvalue -> llbuilder = "llvm_builder_before"
llbuilder -> llvalue = "llvm_build_fcmp"
(*--... Miscellaneous instructions .........................................--*)
-external build_phi : lltype -> string -> llbuilder -> llvalue = "llvm_build_phi"
+external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
+ llvalue = "llvm_build_phi"
external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
= "llvm_build_call"
external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
llbuilder -> llvalue = "llvm_build_shufflevector"
+(*===-- Module providers --------------------------------------------------===*)
+external create_module_provider : llmodule -> llmoduleprovider
+ = "LLVMCreateModuleProviderForExistingModule"
+external dispose_module_provider : llmoduleprovider -> unit
+ = "llvm_dispose_module_provider"
+
+
(*===-- Non-Externs -------------------------------------------------------===*)
(* These functions are built using the externals, so must be declared late. *)
!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)) ^ "*"