diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index f1e20328b..16d048d97 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -36,8 +36,6 @@ use wasmer_runtime_core::{ debug, loader::{Instance as LoadedInstance, LocalLoader}, }; -#[cfg(feature = "backend-singlepass")] -use wasmer_singlepass_backend::SinglePassCompiler; #[cfg(feature = "wasi")] use wasmer_wasi; @@ -81,7 +79,7 @@ enum CLIOptions { SelfUpdate, } -#[derive(Debug, StructOpt)] +#[derive(Debug, StructOpt, Clone)] struct PrestandardFeatures { /// Enable support for the SIMD proposal. #[structopt(long = "enable-simd")] @@ -113,7 +111,7 @@ pub struct LLVMCLIOptions { obj_file: Option, } -#[derive(Debug, StructOpt)] +#[derive(Debug, StructOpt, Clone)] struct Run { // Disable the cache #[structopt(long = "disable-cache")] @@ -177,6 +175,10 @@ struct Run { #[structopt(long = "no-track-state")] no_track_state: bool, + // Enable the CallTrace middleware. + #[structopt(long = "call-trace")] + call_trace: bool, + /// The command name is a string that will override the first argument passed /// to the wasm program. This is used in wapm to provide nicer output in /// help commands and error messages of the running wasm program @@ -397,7 +399,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .map_err(|e| format!("Can't convert from wast to wasm: {:?}", e))?; } - let compiler: Box = match get_compiler_by_backend(options.backend) { + let compiler: Box = match get_compiler_by_backend(options.backend, options) { Some(x) => x, None => return Err("the requested backend is not enabled".into()), }; @@ -615,11 +617,13 @@ fn execute_wasm(options: &Run) -> Result<(), String> { &import_object, start_raw, &mut instance, + options.backend, options .optimized_backends .iter() - .map(|&backend| -> Box Box + Send> { - Box::new(move || get_compiler_by_backend(backend).unwrap()) + .map(|&backend| -> (Backend, Box Box + Send>) { + let options = options.clone(); + (backend, Box::new(move || get_compiler_by_backend(backend, &options).unwrap())) }) .collect(), interactive_shell, @@ -639,6 +643,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { baseline: true, msm: instance.module.runnable_module.get_module_state_map().unwrap(), base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, + backend: options.backend, }); let result = start.call(); pop_code_version().unwrap(); @@ -809,10 +814,27 @@ fn validate(validate: Validate) { } } -fn get_compiler_by_backend(backend: Backend) -> Option> { +fn get_compiler_by_backend(backend: Backend, opts: &Run) -> Option> { + use wasmer_runtime_core::codegen::{MiddlewareChain}; + let opts = opts.clone(); + let middlewares_gen = move || { + let mut middlewares = MiddlewareChain::new(); + if opts.call_trace { + use wasmer_middleware_common::call_trace::CallTrace; + middlewares.push(CallTrace::new()); + } + middlewares + }; + Some(match backend { #[cfg(feature = "backend-singlepass")] - Backend::Singlepass => Box::new(SinglePassCompiler::new()), + Backend::Singlepass => { + use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG; + use wasmer_runtime_core::codegen::{StreamingCompiler}; + + let c: StreamingCompiler = StreamingCompiler::new(middlewares_gen); + Box::new(c) + } #[cfg(not(feature = "backend-singlepass"))] Backend::Singlepass => return None, Backend::Cranelift => Box::new(CraneliftCompiler::new()),