From 34e9e52b5651f30cf9dbd9cd3f64c615864d05e8 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 10 Dec 2018 20:15:41 -0800 Subject: [PATCH] Improved execute wasm to use emscripten conditionally --- src/bin/wasmer.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 2f34b4d36..b729fddd9 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -67,16 +67,28 @@ fn execute_wasm(options: &Run) -> Result<(), String> { // TODO: We should instantiate after compilation, so we provide the // emscripten environment conditionally based on the module let import_object = apis::generate_emscripten_env(); - let webassembly::ResultObject { module, mut instance } = - webassembly::instantiate(wasm_binary, import_object, Some(webassembly::InstanceOptions { - mock_missing_imports: true, - mock_missing_globals: true, - mock_missing_tables: true, - use_emscripten: true, - show_progressbar: true, - isa: webassembly::get_isa(), - })) - .map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?; + + + let isa = webassembly::get_isa(); + + debug!("webassembly - creating module"); + let module = webassembly::compile(wasm_binary).map_err(|err| format!("Can't create the WebAssembly module: {}", err))?; + + let instance_options = webassembly::InstanceOptions { + mock_missing_imports: true, + mock_missing_globals: true, + mock_missing_tables: true, + use_emscripten: apis::is_emscripten_module(&module), + show_progressbar: true, + isa: isa, + }; + + debug!("webassembly - creating instance"); + let mut instance = webassembly::Instance::new( + &module, + import_object, + instance_options, + ).map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?; webassembly::start_instance(&module, &mut instance, options.path.to_str().unwrap(), options.args.iter().map(|arg| arg.as_str()).collect()) }