mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 06:35:40 +00:00
Add CallTrace CLI option.
This commit is contained in:
parent
36f95fc660
commit
ad3faa0ba0
@ -36,8 +36,6 @@ use wasmer_runtime_core::{
|
|||||||
debug,
|
debug,
|
||||||
loader::{Instance as LoadedInstance, LocalLoader},
|
loader::{Instance as LoadedInstance, LocalLoader},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "backend-singlepass")]
|
|
||||||
use wasmer_singlepass_backend::SinglePassCompiler;
|
|
||||||
#[cfg(feature = "wasi")]
|
#[cfg(feature = "wasi")]
|
||||||
use wasmer_wasi;
|
use wasmer_wasi;
|
||||||
|
|
||||||
@ -81,7 +79,7 @@ enum CLIOptions {
|
|||||||
SelfUpdate,
|
SelfUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
struct PrestandardFeatures {
|
struct PrestandardFeatures {
|
||||||
/// Enable support for the SIMD proposal.
|
/// Enable support for the SIMD proposal.
|
||||||
#[structopt(long = "enable-simd")]
|
#[structopt(long = "enable-simd")]
|
||||||
@ -113,7 +111,7 @@ pub struct LLVMCLIOptions {
|
|||||||
obj_file: Option<PathBuf>,
|
obj_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt, Clone)]
|
||||||
struct Run {
|
struct Run {
|
||||||
// Disable the cache
|
// Disable the cache
|
||||||
#[structopt(long = "disable-cache")]
|
#[structopt(long = "disable-cache")]
|
||||||
@ -177,6 +175,10 @@ struct Run {
|
|||||||
#[structopt(long = "no-track-state")]
|
#[structopt(long = "no-track-state")]
|
||||||
no_track_state: bool,
|
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
|
/// 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
|
/// to the wasm program. This is used in wapm to provide nicer output in
|
||||||
/// help commands and error messages of the running wasm program
|
/// 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))?;
|
.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,
|
Some(x) => x,
|
||||||
None => return Err("the requested backend is not enabled".into()),
|
None => return Err("the requested backend is not enabled".into()),
|
||||||
};
|
};
|
||||||
@ -615,11 +617,13 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
&import_object,
|
&import_object,
|
||||||
start_raw,
|
start_raw,
|
||||||
&mut instance,
|
&mut instance,
|
||||||
|
options.backend,
|
||||||
options
|
options
|
||||||
.optimized_backends
|
.optimized_backends
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&backend| -> Box<dyn Fn() -> Box<dyn Compiler> + Send> {
|
.map(|&backend| -> (Backend, Box<dyn Fn() -> Box<dyn Compiler> + Send>) {
|
||||||
Box::new(move || get_compiler_by_backend(backend).unwrap())
|
let options = options.clone();
|
||||||
|
(backend, Box::new(move || get_compiler_by_backend(backend, &options).unwrap()))
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
interactive_shell,
|
interactive_shell,
|
||||||
@ -639,6 +643,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
baseline: true,
|
baseline: true,
|
||||||
msm: instance.module.runnable_module.get_module_state_map().unwrap(),
|
msm: instance.module.runnable_module.get_module_state_map().unwrap(),
|
||||||
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
|
||||||
|
backend: options.backend,
|
||||||
});
|
});
|
||||||
let result = start.call();
|
let result = start.call();
|
||||||
pop_code_version().unwrap();
|
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 {
|
Some(match backend {
|
||||||
#[cfg(feature = "backend-singlepass")]
|
#[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"))]
|
#[cfg(not(feature = "backend-singlepass"))]
|
||||||
Backend::Singlepass => return None,
|
Backend::Singlepass => return None,
|
||||||
Backend::Cranelift => Box::new(CraneliftCompiler::new()),
|
Backend::Cranelift => Box::new(CraneliftCompiler::new()),
|
||||||
|
Loading…
Reference in New Issue
Block a user