Add CallTrace CLI option.

This commit is contained in:
losfair 2019-10-11 21:05:59 +08:00
parent 36f95fc660
commit ad3faa0ba0

View File

@ -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<PathBuf>,
}
#[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<dyn Compiler> = match get_compiler_by_backend(options.backend) {
let compiler: Box<dyn Compiler> = 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<dyn Fn() -> Box<dyn Compiler> + Send> {
Box::new(move || get_compiler_by_backend(backend).unwrap())
.map(|&backend| -> (Backend, Box<dyn Fn() -> Box<dyn Compiler> + 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<Box<dyn Compiler>> {
fn get_compiler_by_backend(backend: Backend, opts: &Run) -> Option<Box<dyn Compiler>> {
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<SinglePassMCG, _, _, _, _> = StreamingCompiler::new(middlewares_gen);
Box::new(c)
}
#[cfg(not(feature = "backend-singlepass"))]
Backend::Singlepass => return None,
Backend::Cranelift => Box::new(CraneliftCompiler::new()),