diff --git a/Cargo.toml b/Cargo.toml index 8d03d70..e9a6473 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,18 @@ rust-version = "1.74.1" [dependencies] smallvec = { version = "1.13.2" } -logos = { version = "0.14.2" } +logos = { version = "0.14.2", optional = true } [features] default = [] +asm = ["dep:logos"] [profile.release] lto = "fat" codegen-units = 1 + + +[[bin]] +name = "uasm" +path = "src/bin/uasm.rs" +required-features = ["asm"] diff --git a/deny.toml b/deny.toml index d17b7ec..1493fb6 100644 --- a/deny.toml +++ b/deny.toml @@ -1,5 +1,5 @@ [graph] -all-features = false +all-features = true no-default-features = false [output] diff --git a/src/bin/um.rs b/src/bin/um.rs index 48ed6a6..e08055d 100644 --- a/src/bin/um.rs +++ b/src/bin/um.rs @@ -46,8 +46,13 @@ fn main() { } } +#[cfg(feature = "asm")] fn load_program(path: &Path) -> std::io::Result> { match path.extension().map(|ext| ext.as_encoded_bytes()) { + // In an ideal world we would just add `#[cfg(feature = "asm")]` here. + // Unfortunately this leads some wierd code generation fuckery which + // makes the version without the 'asm' feature ~1-2 seconds slower + // when running the sandmark program. Some(b"uasm") | Some(b"asm") => { let source = std::fs::read_to_string(path)?; Ok(um::asm::assemble(&source)) @@ -58,3 +63,9 @@ fn load_program(path: &Path) -> std::io::Result> { } } } + +#[cfg(not(feature = "asm"))] +fn load_program(path: &Path) -> std::io::Result> { + let program = std::fs::read(path)?; + Ok(um::conv::bytes_to_program(&program).unwrap()) +} diff --git a/src/lib.rs b/src/lib.rs index 79293a8..69d2379 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ use smallvec::SmallVec; use std::io::{Read, Write}; +#[cfg(feature = "asm")] pub mod asm; pub mod conv; pub mod ops; @@ -324,6 +325,7 @@ mod tests { } #[test] + #[cfg(feature = "asm")] fn hello_world() { let program = asm::assemble(include_str!("../files/hello-world.asm")); let mut buffer = Vec::new(); @@ -332,6 +334,7 @@ mod tests { } #[test] + #[cfg(feature = "asm")] fn cat() { let program = asm::assemble(include_str!("../files/cat.asm")); let input = include_bytes!("lib.rs");