From: Erick Tryzelaar Date: Tue, 2 Mar 2010 23:59:00 +0000 (+0000) Subject: Remove module providers from ocaml. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=16609f3c5c26ba34603ae0d7ebab86fb11a72722 Remove module providers from ocaml. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97609 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/bindings/ocaml/bitreader/bitreader_ocaml.c b/bindings/ocaml/bitreader/bitreader_ocaml.c index 318c7038e21..ef72ce213d8 100644 --- a/bindings/ocaml/bitreader/bitreader_ocaml.c +++ b/bindings/ocaml/bitreader/bitreader_ocaml.c @@ -46,17 +46,16 @@ static void llvm_raise(value Prototype, char *Message) { /*===-- Modules -----------------------------------------------------------===*/ /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */ -CAMLprim value llvm_get_module_provider(LLVMContextRef C, - LLVMMemoryBufferRef MemBuf) { +CAMLprim value llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) { CAMLparam0(); CAMLlocal2(Variant, MessageVal); char *Message; - LLVMModuleProviderRef MP; - if (LLVMGetBitcodeModuleProviderInContext(C, MemBuf, &MP, &Message)) + LLVMModuleRef M; + if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message)) llvm_raise(llvm_bitreader_error_exn, Message); - CAMLreturn((value) MP); + CAMLreturn((value) M); } /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */ diff --git a/bindings/ocaml/bitreader/llvm_bitreader.ml b/bindings/ocaml/bitreader/llvm_bitreader.ml index 88587cbe1ef..8b9d01d8fb0 100644 --- a/bindings/ocaml/bitreader/llvm_bitreader.ml +++ b/bindings/ocaml/bitreader/llvm_bitreader.ml @@ -13,9 +13,8 @@ exception Error of string external register_exns : exn -> unit = "llvm_register_bitreader_exns" let _ = register_exns (Error "") -external get_module_provider : Llvm.llcontext -> Llvm.llmemorybuffer -> - Llvm.llmoduleprovider - = "llvm_get_module_provider" +external get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule + = "llvm_get_module" external parse_bitcode : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule = "llvm_parse_bitcode" diff --git a/bindings/ocaml/bitreader/llvm_bitreader.mli b/bindings/ocaml/bitreader/llvm_bitreader.mli index 5648b35fee2..5e2240974af 100644 --- a/bindings/ocaml/bitreader/llvm_bitreader.mli +++ b/bindings/ocaml/bitreader/llvm_bitreader.mli @@ -14,14 +14,12 @@ exception Error of string -(** [get_module_provider context mb] reads the bitcode for a new - module provider [m] from the memory buffer [mb] in the context [context]. - Returns [m] if successful, or raises [Error msg] otherwise, where [msg] is a - description of the error encountered. See the function - [llvm::getBitcodeModuleProvider]. *) -external get_module_provider : Llvm.llcontext -> Llvm.llmemorybuffer -> - Llvm.llmoduleprovider - = "llvm_get_module_provider" +(** [get_module context mb] reads the bitcode for a new module [m] from the + memory buffer [mb] in the context [context]. Returns [m] if successful, or + raises [Error msg] otherwise, where [msg] is a description of the error + encountered. See the function [llvm::getBitcodeModule]. *) +external get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule + = "llvm_get_module" (** [parse_bitcode context mb] parses the bitcode for a new module [m] from the memory buffer [mb] in the context [context]. Returns [m] if successful, or diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c index 072d583bf8f..bc2b08196b6 100644 --- a/bindings/ocaml/executionengine/executionengine_ocaml.c +++ b/bindings/ocaml/executionengine/executionengine_ocaml.c @@ -168,41 +168,41 @@ CAMLprim value llvm_genericvalue_as_nativeint(value GenVal) { /*--... Operations on execution engines ....................................--*/ -/* llmoduleprovider -> ExecutionEngine.t */ -CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleProviderRef MP) { +/* llmodule -> ExecutionEngine.t */ +CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) { LLVMExecutionEngineRef Interp; char *Error; - if (LLVMCreateExecutionEngine(&Interp, MP, &Error)) + if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error)) llvm_raise(llvm_ee_error_exn, Error); return Interp; } -/* llmoduleprovider -> ExecutionEngine.t */ +/* llmodule -> ExecutionEngine.t */ CAMLprim LLVMExecutionEngineRef -llvm_ee_create_interpreter(LLVMModuleProviderRef MP) { +llvm_ee_create_interpreter(LLVMModuleRef M) { LLVMExecutionEngineRef Interp; char *Error; - if (LLVMCreateInterpreter(&Interp, MP, &Error)) + if (LLVMCreateInterpreterForModule(&Interp, M, &Error)) llvm_raise(llvm_ee_error_exn, Error); return Interp; } -/* llmoduleprovider -> ExecutionEngine.t */ +/* llmodule -> ExecutionEngine.t */ CAMLprim LLVMExecutionEngineRef -llvm_ee_create_jit(LLVMModuleProviderRef MP) { +llvm_ee_create_jit(LLVMModuleRef M) { LLVMExecutionEngineRef JIT; char *Error; - if (LLVMCreateJITCompiler(&JIT, MP, 3, &Error)) + if (LLVMCreateJITCompilerForModule(&JIT, M, 3, &Error)) llvm_raise(llvm_ee_error_exn, Error); return JIT; } -/* llmoduleprovider -> ExecutionEngine.t */ +/* llmodule -> ExecutionEngine.t */ CAMLprim LLVMExecutionEngineRef -llvm_ee_create_fast_jit(LLVMModuleProviderRef MP) { +llvm_ee_create_fast_jit(LLVMModuleRef M) { LLVMExecutionEngineRef JIT; char *Error; - if (LLVMCreateJITCompiler(&JIT, MP, 0, &Error)) + if (LLVMCreateJITCompiler(&JIT, M, 0, &Error)) llvm_raise(llvm_ee_error_exn, Error); return JIT; } @@ -213,19 +213,18 @@ CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) { return Val_unit; } -/* llmoduleprovider -> ExecutionEngine.t -> unit */ -CAMLprim value llvm_ee_add_mp(LLVMModuleProviderRef MP, - LLVMExecutionEngineRef EE) { - LLVMAddModuleProvider(EE, MP); +/* llmodule -> ExecutionEngine.t -> unit */ +CAMLprim value llvm_ee_add_mp(LLVMModuleRef M, LLVMExecutionEngineRef EE) { + LLVMAddModule(EE, M); return Val_unit; } -/* llmoduleprovider -> ExecutionEngine.t -> llmodule */ -CAMLprim LLVMModuleRef llvm_ee_remove_mp(LLVMModuleProviderRef MP, +/* llmodule -> ExecutionEngine.t -> llmodule */ +CAMLprim LLVMModuleRef llvm_ee_remove_mp(LLVMModuleRef M, LLVMExecutionEngineRef EE) { LLVMModuleRef RemovedModule; char *Error; - if (LLVMRemoveModuleProvider(EE, MP, &RemovedModule, &Error)) + if (LLVMRemoveModule(EE, M, &RemovedModule, &Error)) llvm_raise(llvm_ee_error_exn, Error); return RemovedModule; } diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml index c9e8f18b224..921d424ad51 100644 --- a/bindings/ocaml/executionengine/llvm_executionengine.ml +++ b/bindings/ocaml/executionengine/llvm_executionengine.ml @@ -56,19 +56,19 @@ module ExecutionEngine = struct call into LLVM. *) let _ = register_exns (Error "") - external create: Llvm.llmoduleprovider -> t + external create: Llvm.llmodule -> t = "llvm_ee_create" - external create_interpreter: Llvm.llmoduleprovider -> t + external create_interpreter: Llvm.llmodule -> t = "llvm_ee_create_interpreter" - external create_jit: Llvm.llmoduleprovider -> t + external create_jit: Llvm.llmodule -> t = "llvm_ee_create_jit" - external create_fast_jit: Llvm.llmoduleprovider -> t + external create_fast_jit: Llvm.llmodule -> t = "llvm_ee_create_fast_jit" external dispose: t -> unit = "llvm_ee_dispose" - external add_module_provider: Llvm.llmoduleprovider -> t -> unit + external add_module: Llvm.llmodule -> t -> unit = "llvm_ee_add_mp" - external remove_module_provider: Llvm.llmoduleprovider -> t -> Llvm.llmodule + external remove_module: Llvm.llmodule -> t -> Llvm.llmodule = "llvm_ee_remove_mp" external find_function: string -> t -> Llvm.llvalue option = "llvm_ee_find_function" diff --git a/bindings/ocaml/executionengine/llvm_executionengine.mli b/bindings/ocaml/executionengine/llvm_executionengine.mli index 6c2fdfb7868..ec469fcf047 100644 --- a/bindings/ocaml/executionengine/llvm_executionengine.mli +++ b/bindings/ocaml/executionengine/llvm_executionengine.mli @@ -85,48 +85,47 @@ module ExecutionEngine: sig invoking a static compiler and generating a native executable. *) type t - (** [create mp] creates a new execution engine, taking ownership of the - module provider [mp] if successful. Creates a JIT if possible, else falls - back to an interpreter. Raises [Error msg] if an error occurrs. The - execution engine is not garbage collected and must be destroyed with - [dispose ee]. See the function [llvm::EngineBuilder::create]. *) - val create: Llvm.llmoduleprovider -> t + (** [create m] creates a new execution engine, taking ownership of the + module [m] if successful. Creates a JIT if possible, else falls back to an + interpreter. Raises [Error msg] if an error occurrs. The execution engine + is not garbage collected and must be destroyed with [dispose ee]. + See the function [llvm::EngineBuilder::create]. *) + val create: Llvm.llmodule -> t - (** [create_interpreter mp] creates a new interpreter, taking ownership of the - module provider [mp] if successful. Raises [Error msg] if an error - occurrs. The execution engine is not garbage collected and must be - destroyed with [dispose ee]. + (** [create_interpreter m] creates a new interpreter, taking ownership of the + module [m] if successful. Raises [Error msg] if an error occurrs. The + execution engine is not garbage collected and must be destroyed with + [dispose ee]. See the function [llvm::EngineBuilder::create]. *) - val create_interpreter: Llvm.llmoduleprovider -> t + val create_interpreter: Llvm.llmodule -> t - (** [create_jit mp] creates a new JIT (just-in-time compiler), taking - ownership of the module provider [mp] if successful. This function creates - a JIT which favors code quality over compilation speed. Raises [Error msg] - if an error occurrs. The execution engine is not garbage collected and - must be destroyed with [dispose ee]. + (** [create_jit m] creates a new JIT (just-in-time compiler), taking + ownership of the module [m] if successful. This function creates a JIT + which favors code quality over compilation speed. Raises [Error msg] if an + error occurrs. The execution engine is not garbage collected and must be + destroyed with [dispose ee]. See the function [llvm::EngineBuilder::create]. *) - val create_jit: Llvm.llmoduleprovider -> t + val create_jit: Llvm.llmodule -> t - (** [create_fast_jit mp] creates a new JIT (just-in-time compiler) which + (** [create_fast_jit m] creates a new JIT (just-in-time compiler) which favors compilation speed over code quality. It takes ownership of the - module provider [mp] if successful. Raises [Error msg] if an error - occurrs. The execution engine is not garbage collected and must be - destroyed with [dispose ee]. + module [m] if successful. Raises [Error msg] if an error occurrs. The + execution engine is not garbage collected and must be destroyed with + [dispose ee]. See the function [llvm::EngineBuilder::create]. *) - val create_fast_jit: Llvm.llmoduleprovider -> t + val create_fast_jit: Llvm.llmodule -> t (** [dispose ee] releases the memory used by the execution engine and must be invoked to avoid memory leaks. *) val dispose: t -> unit - (** [add_module_provider mp ee] adds the module provider [mp] to the execution - engine [ee]. *) - val add_module_provider: Llvm.llmoduleprovider -> t -> unit + (** [add_module m ee] adds the module [m] to the execution engine [ee]. *) + val add_module: Llvm.llmodule -> t -> unit - (** [remove_module_provider mp ee] removes the module provider [mp] from the - execution engine [ee], disposing of [mp] and the module referenced by - [mp]. Raises [Error msg] if an error occurs. *) - val remove_module_provider: Llvm.llmoduleprovider -> t -> Llvm.llmodule + (** [remove_module m ee] removes the module [m] from the execution engine + [ee], disposing of [m] and the module referenced by [mp]. Raises + [Error msg] if an error occurs. *) + val remove_module: Llvm.llmodule -> t -> Llvm.llmodule (** [find_function n ee] finds the function named [n] defined in any of the modules owned by the execution engine [ee]. Returns [None] if the function diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index 7b906d26843..407c1fc6c63 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -16,7 +16,6 @@ type llvalue type lluse type llbasicblock type llbuilder -type llmoduleprovider type llmemorybuffer module TypeKind = struct @@ -948,14 +947,6 @@ external build_is_not_null : llvalue -> string -> llbuilder -> llvalue external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue = "llvm_build_ptrdiff" -(*===-- Module providers --------------------------------------------------===*) - -module ModuleProvider = struct - external create : llmodule -> llmoduleprovider - = "LLVMCreateModuleProviderForExistingModule" - external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider" -end - (*===-- Memory buffers ----------------------------------------------------===*) @@ -972,7 +963,7 @@ module PassManager = struct type 'a t type any = [ `Module | `Function ] external create : unit -> [ `Module ] t = "llvm_passmanager_create" - external create_function : llmoduleprovider -> [ `Function ] t + external create_function : llmodule -> [ `Function ] t = "LLVMCreateFunctionPassManager" external run_module : llmodule -> [ `Module ] t -> bool = "llvm_passmanager_run_module" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index cf06d5a9840..3ea7ad482d8 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -49,10 +49,6 @@ type llbasicblock class. *) type llbuilder -(** Used to provide a module to JIT or interpreter. - See the [llvm::ModuleProvider] class. *) -type llmoduleprovider - (** Used to efficiently handle large buffers of read-only binary data. See the [llvm::MemoryBuffer] class. *) type llmemorybuffer @@ -2198,20 +2194,6 @@ external build_is_not_null : llvalue -> string -> llbuilder -> llvalue external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue = "llvm_build_ptrdiff" -(** {6 Module providers} *) - -module ModuleProvider : sig - (** [create_module_provider m] encapsulates [m] in a module provider and takes - ownership of the module. See the constructor - [llvm::ExistingModuleProvider::ExistingModuleProvider]. *) - external create : llmodule -> llmoduleprovider - = "LLVMCreateModuleProviderForExistingModule" - - (** [dispose_module_provider mp] destroys the module provider [mp] as well as - the contained module. *) - external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider" -end - (** {6 Memory buffers} *) @@ -2243,12 +2225,12 @@ module PassManager : sig See the constructor of [llvm::PassManager]. *) external create : unit -> [ `Module ] t = "llvm_passmanager_create" - (** [PassManager.create_function mp] constructs a new function-by-function - pass pipeline over the module provider [mp]. It does not take ownership of - [mp]. This type of pipeline is suitable for code generation and JIT - compilation tasks. + (** [PassManager.create_function m] constructs a new function-by-function + pass pipeline over the module [m]. It does not take ownership of [m]. + This type of pipeline is suitable for code generation and JIT compilation + tasks. See the constructor of [llvm::FunctionPassManager]. *) - external create_function : llmoduleprovider -> [ `Function ] t + external create_function : llmodule -> [ `Function ] t = "LLVMCreateFunctionPassManager" (** [run_module m pm] initializes, executes on the module [m], and finalizes @@ -2278,7 +2260,7 @@ module PassManager : sig external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize" (** Frees the memory of a pass pipeline. For function pipelines, does not free - the module provider. + the module. See the destructor of [llvm::BasePassManager]. *) external dispose : [< any ] t -> unit = "llvm_passmanager_dispose" end diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index 4bcc764a83b..d526a05a510 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -1752,14 +1752,6 @@ CAMLprim LLVMValueRef llvm_build_ptrdiff(LLVMValueRef LHS, LLVMValueRef RHS, return LLVMBuildPtrDiff(Builder_val(B), LHS, RHS, String_val(Name)); } -/*===-- Module Providers --------------------------------------------------===*/ - -/* llmoduleprovider -> unit */ -CAMLprim value llvm_dispose_module_provider(LLVMModuleProviderRef MP) { - LLVMDisposeModuleProvider(MP); - return Val_unit; -} - /*===-- Memory buffers ----------------------------------------------------===*/ diff --git a/test/Bindings/Ocaml/bitreader.ml b/test/Bindings/Ocaml/bitreader.ml index 5c23041c80d..112ca618301 100644 --- a/test/Bindings/Ocaml/bitreader.ml +++ b/test/Bindings/Ocaml/bitreader.ml @@ -41,16 +41,16 @@ let _ = true end; - (* get_module_provider *) + (* get_module *) begin let mb = Llvm.MemoryBuffer.of_file fn in - let mp = begin try - Llvm_bitreader.get_module_provider context mb + let m = begin try + Llvm_bitreader.get_module context mb with x -> Llvm.MemoryBuffer.dispose mb; raise x end in - Llvm.ModuleProvider.dispose mp + Llvm.dispose_module m end; (* corrupt the bitcode *) @@ -60,17 +60,17 @@ let _ = close_out oc end; - (* test get_module_provider exceptions *) + (* test get_module exceptions *) test begin try let mb = Llvm.MemoryBuffer.of_file fn in - let mp = begin try - Llvm_bitreader.get_module_provider context mb + let m = begin try + Llvm_bitreader.get_module context mb with x -> Llvm.MemoryBuffer.dispose mb; raise x end in - Llvm.ModuleProvider.dispose mp; + Llvm.dispose_module m; false with Llvm_bitreader.Error _ -> true diff --git a/test/Bindings/Ocaml/executionengine.ml b/test/Bindings/Ocaml/executionengine.ml index ce56c50dcb6..2caeb82aac2 100644 --- a/test/Bindings/Ocaml/executionengine.ml +++ b/test/Bindings/Ocaml/executionengine.ml @@ -64,9 +64,8 @@ let test_executionengine () = let m2 = create_module (global_context ()) "test_module2" in define_plus m2; - let ee = ExecutionEngine.create (ModuleProvider.create m) in - let mp2 = ModuleProvider.create m2 in - ExecutionEngine.add_module_provider mp2 ee; + let ee = ExecutionEngine.create m in + ExecutionEngine.add_module m2 ee; (* run_static_ctors *) ExecutionEngine.run_static_ctors ee; @@ -94,8 +93,8 @@ let test_executionengine () = ee in if 4 != GenericValue.as_int res then bomb "plus did not work"; - (* remove_module_provider *) - Llvm.dispose_module (ExecutionEngine.remove_module_provider mp2 ee); + (* remove_module *) + Llvm.dispose_module (ExecutionEngine.remove_module m2 ee); (* run_static_dtors *) ExecutionEngine.run_static_dtors ee; diff --git a/test/Bindings/Ocaml/scalar_opts.ml b/test/Bindings/Ocaml/scalar_opts.ml index 0a65810105b..1b488c5b021 100644 --- a/test/Bindings/Ocaml/scalar_opts.ml +++ b/test/Bindings/Ocaml/scalar_opts.ml @@ -22,7 +22,6 @@ let suite name f = let filename = Sys.argv.(1) let m = create_module context filename -let mp = ModuleProvider.create m (*===-- Transforms --------------------------------------------------------===*) @@ -36,7 +35,7 @@ let test_transforms () = let td = TargetData.create (target_triple m) in - ignore (PassManager.create_function mp + ignore (PassManager.create_function m ++ TargetData.add td ++ add_instruction_combining ++ add_reassociation @@ -55,4 +54,4 @@ let test_transforms () = let _ = suite "transforms" test_transforms; - ModuleProvider.dispose mp + dispose_module m diff --git a/test/Bindings/Ocaml/vmcore.ml b/test/Bindings/Ocaml/vmcore.ml index d87e162b9c6..506bf50e2a4 100644 --- a/test/Bindings/Ocaml/vmcore.ml +++ b/test/Bindings/Ocaml/vmcore.ml @@ -58,7 +58,6 @@ let suite name f = let filename = Sys.argv.(1) let m = create_module context filename -let mp = ModuleProvider.create m (*===-- Target ------------------------------------------------------------===*) @@ -1264,14 +1263,6 @@ let test_builder () = end -(*===-- Module Provider ---------------------------------------------------===*) - -let test_module_provider () = - let m = create_module context "test" in - let mp = ModuleProvider.create m in - ModuleProvider.dispose mp - - (*===-- Pass Managers -----------------------------------------------------===*) let test_pass_manager () = @@ -1288,7 +1279,7 @@ let test_pass_manager () = let fn = define_function "FunctionPassManager" fty m in ignore (build_ret_void (builder_at_end context (entry_block fn))); - ignore (PassManager.create_function mp + ignore (PassManager.create_function m ++ PassManager.initialize ++ PassManager.run_function fn ++ PassManager.finalize @@ -1307,7 +1298,7 @@ let test_writer () = group "writer"; insist (write_bitcode_file m filename); - ModuleProvider.dispose mp + dispose_module m (*===-- Driver ------------------------------------------------------------===*) @@ -1326,7 +1317,6 @@ let _ = suite "basic blocks" test_basic_blocks; suite "instructions" test_instructions; suite "builder" test_builder; - suite "module provider" test_module_provider; suite "pass manager" test_pass_manager; suite "writer" test_writer; (* Keep this last; it disposes m. *) exit !exit_status