diff options
Diffstat (limited to 'crates/cli')
| -rw-r--r-- | crates/cli/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/cli/bin.rs | 19 | ||||
| -rw-r--r-- | crates/cli/util.rs | 14 |
3 files changed, 32 insertions, 3 deletions
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 4a9974b..bfe0391 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -13,3 +13,5 @@ path="bin.rs" tinywasm={path="../tinywasm"} argh="0.1" color-eyre="0.6" +tracing="0.1" +tracing-subscriber="0.3" diff --git a/crates/cli/bin.rs b/crates/cli/bin.rs index 4e85481..38e30da 100644 --- a/crates/cli/bin.rs +++ b/crates/cli/bin.rs @@ -1,6 +1,9 @@ use argh::FromArgs; use color_eyre::eyre::Result; -use tinywasm::{self, Module}; +use tinywasm::{self, module::WasmValue, Module}; +use util::install_tracing; + +mod util; #[derive(FromArgs)] /// TinyWasm CLI @@ -25,6 +28,9 @@ struct Run { } fn main() -> Result<()> { + color_eyre::install()?; + install_tracing(None); + let args: TinyWasmCli = argh::from_env(); match args.nested { @@ -37,7 +43,14 @@ fn main() -> Result<()> { } fn run(wasm: &[u8]) -> Result<()> { - let module = Module::new(wasm)?; - println!("{:#?}", module); + let mut module = Module::new(wasm)?; + let args = [WasmValue::I32(1), WasmValue::I32(2)]; + let res = module.run("add", &args)?; + println!("res: {:?}", res); + + let args = [WasmValue::I64(1), WasmValue::I64(2)]; + let res = module.run("add_64", &args)?; + println!("res: {:?}", res); + Ok(()) } diff --git a/crates/cli/util.rs b/crates/cli/util.rs new file mode 100644 index 0000000..2a8160a --- /dev/null +++ b/crates/cli/util.rs @@ -0,0 +1,14 @@ +pub fn install_tracing(log_level: Option<tracing::Level>) { + use tracing_subscriber::filter::LevelFilter; + use tracing_subscriber::prelude::*; + + tracing_subscriber::registry() + .with( + tracing_subscriber::fmt::layer() + .compact() + .with_filter(LevelFilter::from( + log_level.unwrap_or(tracing::Level::DEBUG), + )), + ) + .init(); +} |
