diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ba445c4..dac8dfd 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cambridge-asm-cli" -version = "0.14.0" +version = "0.15.0" authors = ["SaadiSave "] edition = "2021" license = "MPL-2.0" @@ -21,9 +21,10 @@ serde_json = "1" ron = "0.7" serde_yaml = "0.8" bincode = "2.0.0-rc.1" +anyhow = "1" [dependencies.cambridge-asm] -version = "0.15" +version = "0.18" default-features = false features = ["compile"] diff --git a/cli/src/main.rs b/cli/src/main.rs index 1df93c3..eb38168 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -15,7 +15,7 @@ use std::ffi::OsString; #[derive(Parser)] #[clap(name = "Cambridge Pseudoassembly Interpreter")] -#[clap(version = env!("CARGO_PKG_VERSION"))] +#[clap(version = concat!(env!("CARGO_PKG_VERSION"), "\n", "Library version 0.18.0"))] #[clap(author = "Saadi Save ")] #[clap(about = "Run pseudoassembly from Cambridge International syllabus 9618 (2021)")] enum Commands { @@ -60,6 +60,10 @@ enum Commands { /// Minify output #[clap(short = 'm', long = "minify")] minify: bool, + + /// Include debuginfo + #[clap(short, long)] + debug: bool, }, } @@ -80,7 +84,7 @@ enum OutFormats { Bin, } -fn main() -> std::io::Result<()> { +fn main() -> anyhow::Result<()> { #[cfg(not(debug_assertions))] std::panic::set_hook(Box::new(handle_panic)); @@ -101,7 +105,8 @@ fn main() -> std::io::Result<()> { verbosity, format, minify, - } => compile(input, output, verbosity, format, minify)?, + debug, + } => compile(input, output, verbosity, format, minify, debug)?, } Ok(()) @@ -114,7 +119,7 @@ fn run( bench: bool, format: InFormats, io: Io, -) -> std::io::Result<()> { +) -> anyhow::Result<()> { use InFormats::*; init_logger(verbosity); @@ -124,19 +129,15 @@ fn run( let mut timer = bench.then(std::time::Instant::now); let mut executor = match format { - Pasm => parse::jit::(String::from_utf8_lossy(&prog_bytes), io), - Json => serde_json::from_str::(&String::from_utf8_lossy(&prog_bytes)) - .unwrap() + Pasm => parse::jit::(String::from_utf8_lossy(&prog_bytes), io).unwrap(), + Json => serde_json::from_str::(&String::from_utf8_lossy(&prog_bytes))? .to_executor::(io), - Ron => ron::from_str::(&String::from_utf8_lossy(&prog_bytes)) - .unwrap() + Ron => ron::from_str::(&String::from_utf8_lossy(&prog_bytes))? .to_executor::(io), - Yaml => serde_yaml::from_str::(&String::from_utf8_lossy(&prog_bytes)) - .unwrap() + Yaml => serde_yaml::from_str::(&String::from_utf8_lossy(&prog_bytes))? .to_executor::(io), Bin => { - bincode::decode_from_slice::(&prog_bytes, bincode::config::standard()) - .unwrap() + bincode::decode_from_slice::(&prog_bytes, bincode::config::standard())? .0 .to_executor::(io) } @@ -146,13 +147,16 @@ fn run( println!("Total parse time: {:?}", t.elapsed()); std::time::Instant::now() }); + if timer.is_some() || verbosity > 0 { println!("Execution starts on next line"); } executor.exec::(); - let _ = timer.map(|t| println!("Execution done\nExecution time: {:?}", t.elapsed())); + if let Some(t) = timer { + println!("Execution done\nExecution time: {:?}", t.elapsed()); + } Ok(()) } @@ -164,6 +168,7 @@ fn compile( verbosity: usize, format: OutFormats, minify: bool, + debug: bool, ) -> std::io::Result<()> { use OutFormats::*; @@ -171,7 +176,7 @@ fn compile( let prog = std::fs::read_to_string(&input)?; - let compiled = compile::compile::(prog); + let compiled = compile::compile::(prog, debug).unwrap(); let output_path = output.unwrap_or_else(|| { input.push(match format {