From 767ea3207a7919d69e95791d2bdc71f9fa22cfe3 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Mon, 4 Dec 2023 14:12:09 +0100 Subject: chore: remove unneeded dependencies Signed-off-by: Henry Gressmann --- crates/cli/bin.rs | 112 ------------------------------------------------------ 1 file changed, 112 deletions(-) delete mode 100644 crates/cli/bin.rs (limited to 'crates/cli/bin.rs') diff --git a/crates/cli/bin.rs b/crates/cli/bin.rs deleted file mode 100644 index 3615e4a..0000000 --- a/crates/cli/bin.rs +++ /dev/null @@ -1,112 +0,0 @@ -use std::str::FromStr; - -use argh::FromArgs; -use color_eyre::eyre::Result; -use log::info; -use tinywasm::{self, Module}; -mod util; - -#[cfg(feature = "wat")] -mod wat; - -#[derive(FromArgs)] -/// TinyWasm CLI -struct TinyWasmCli { - #[argh(subcommand)] - nested: TinyWasmSubcommand, - - /// log level - #[argh(option, short = 'l', default = "\"info\".to_string()")] - log_level: String, -} - -#[derive(FromArgs)] -#[argh(subcommand)] -enum TinyWasmSubcommand { - Run(Run), -} - -enum Engine { - Main, -} - -impl FromStr for Engine { - type Err = String; - - fn from_str(s: &str) -> Result { - match s { - "main" => Ok(Self::Main), - _ => Err(format!("unknown engine: {}", s)), - } - } -} - -#[derive(FromArgs)] -/// run a wasm file -#[argh(subcommand, name = "run")] -struct Run { - /// wasm file to run - #[argh(positional)] - wasm_file: String, - - /// engine to use - #[argh(option, short = 'e', default = "Engine::Main")] - engine: Engine, -} - -fn main() -> Result<()> { - color_eyre::install()?; - - let args: TinyWasmCli = argh::from_env(); - let level = match args.log_level.as_str() { - "trace" => log::LevelFilter::Trace, - "debug" => log::LevelFilter::Debug, - "warn" => log::LevelFilter::Warn, - "error" => log::LevelFilter::Error, - "info" => log::LevelFilter::Info, - _ => log::LevelFilter::Info, - }; - - pretty_env_logger::formatted_builder() - .filter_level(level) - .init(); - - let cwd = std::env::current_dir()?; - - match args.nested { - TinyWasmSubcommand::Run(Run { wasm_file, engine }) => { - let path = cwd.join(wasm_file.clone()); - let module = match wasm_file.ends_with(".wat") { - #[cfg(feature = "wat")] - true => { - let wat = std::fs::read_to_string(path)?; - let wasm = wat::wat2wasm(&wat); - tinywasm::Module::parse_bytes(&wasm)? - } - #[cfg(not(feature = "wat"))] - true => { - return Err(color_eyre::eyre::eyre!( - "wat support is not enabled in this build" - )) - } - false => tinywasm::Module::parse_file(path)?, - }; - - match engine { - Engine::Main => run(module), - } - } - } -} - -fn run(module: Module) -> Result<()> { - let mut store = tinywasm::Store::default(); - - let instance = module.instantiate(&mut store)?; - - let func = instance.get_typed_func::<(i32, i32), (i32,)>(&store, "add")?; - let (res,) = func.call(&mut store, (2, 2))?; - info!("{res:?}"); - - Ok(()) -} -- cgit v1.3.1