diff --git a/.github/workflows/checkfmt.yml b/.github/workflows/checkfmt.yml index 077ec5d..4fcf76b 100644 --- a/.github/workflows/checkfmt.yml +++ b/.github/workflows/checkfmt.yml @@ -30,17 +30,16 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - name: "Check Scala format" - continue-on-error: true + if: "!cancelled()" run: | nix develop -c bash -c 'mill -i gcd.checkFormat && mill -i elaborator.checkFormat' - name: "Check Rust format" - continue-on-error: true + if: "!cancelled()" run: | cd gcdemu nix develop -c cargo fmt --check cd .. - name: "Check nix format" - continue-on-error: true + if: "!cancelled()" run: | nix fmt -- --check nix flake.nix - diff --git a/templates/chisel/gcdemu/Cargo.lock b/templates/chisel/gcdemu/Cargo.lock index e6d520d..5540ae2 100644 --- a/templates/chisel/gcdemu/Cargo.lock +++ b/templates/chisel/gcdemu/Cargo.lock @@ -11,55 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -78,57 +29,10 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clap" -version = "4.5.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" - -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - [[package]] name = "gcdemu" version = "0.1.0" dependencies = [ - "clap", "num-bigint", "num-traits", "rand", @@ -148,18 +52,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - [[package]] name = "lazy_static" version = "1.5.0" @@ -366,12 +258,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "svdpi" version = "0.0.1" @@ -466,12 +352,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "valuable" version = "0.1.0" @@ -506,79 +386,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - [[package]] name = "zerocopy" version = "0.7.35" diff --git a/templates/chisel/gcdemu/Cargo.toml b/templates/chisel/gcdemu/Cargo.toml index b29c8f5..eb2e5af 100644 --- a/templates/chisel/gcdemu/Cargo.toml +++ b/templates/chisel/gcdemu/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] svdpi = { version = "0.0.1" } -clap = { version = "4.4.18", features = ["derive"] } rand = "0.8" num-traits = "0.2.19" num-bigint = { version = "0.4.6", features = ["rand"] } diff --git a/templates/chisel/gcdemu/src/dpi.rs b/templates/chisel/gcdemu/src/dpi.rs index 97d9359..c48b7f5 100644 --- a/templates/chisel/gcdemu/src/dpi.rs +++ b/templates/chisel/gcdemu/src/dpi.rs @@ -3,8 +3,8 @@ use std::ffi::{c_char, CString}; use std::sync::Mutex; use crate::drive::Driver; +use crate::plusarg::PlusArgMatcher; use crate::GcdArgs; -use clap::Parser; use num_bigint::BigUint; use svdpi::sys::dpi::{svBitVecVal, svLogic}; use svdpi::SvScope; @@ -64,7 +64,8 @@ unsafe fn fill_test_payload(dst: *mut SvBitVecVal, data_width: u64, payload: &Te #[no_mangle] unsafe extern "C" fn gcd_init() { - let args = GcdArgs::parse(); + let plusargs = PlusArgMatcher::from_args(); + let args = GcdArgs::from_plusargs(&plusargs); args.setup_logger().unwrap(); let scope = SvScope::get_current().expect("failed to get scope in gcd_init"); let driver = Box::new(Driver::new(scope, &args)); diff --git a/templates/chisel/gcdemu/src/drive.rs b/templates/chisel/gcdemu/src/drive.rs index 98fe414..09acce8 100644 --- a/templates/chisel/gcdemu/src/drive.rs +++ b/templates/chisel/gcdemu/src/drive.rs @@ -45,10 +45,10 @@ impl Driver { dump_end: args.dump_end, #[cfg(feature = "trace")] dump_started: false, - data_width: args.data_width, - timeout: args.timeout, - test_size: args.test_size, - clock_flip_time: args.clock_flip_time, + data_width: env!("DESIGN_DATA_WIDTH").parse().unwrap(), + timeout: env!("DESIGN_TIMEOUT").parse().unwrap(), + test_size: env!("DESIGN_TEST_SIZE").parse().unwrap(), + clock_flip_time: env!("CLOCK_FLIP_TIME").parse().unwrap(), test_num: 0, last_input_cycle: 0, } diff --git a/templates/chisel/gcdemu/src/lib.rs b/templates/chisel/gcdemu/src/lib.rs index f9eca3d..e0d844b 100644 --- a/templates/chisel/gcdemu/src/lib.rs +++ b/templates/chisel/gcdemu/src/lib.rs @@ -1,38 +1,22 @@ -use clap::Parser; +use plusarg::PlusArgMatcher; use tracing::Level; use tracing_subscriber::{EnvFilter, FmtSubscriber}; pub mod dpi; pub mod drive; +pub mod plusarg; -#[derive(Parser)] pub(crate) struct GcdArgs { #[cfg(feature = "trace")] - #[arg(long)] dump_start: u64, #[cfg(feature = "trace")] - #[arg(long)] dump_end: u64, #[cfg(feature = "trace")] - #[arg(long)] pub wave_path: String, - #[arg(long, default_value = "info")] pub log_level: String, - - #[arg(long, hide = true,default_value = env!("DESIGN_DATA_WIDTH"))] - data_width: u64, - - #[arg(long, hide = true,default_value = env!("DESIGN_TIMEOUT"))] - timeout: u64, - - #[arg(long, hide = true,default_value = env!("DESIGN_TEST_SIZE"))] - test_size: u64, - - #[arg(long, hide = true,default_value = env!("CLOCK_FLIP_TIME"))] - clock_flip_time: u64, } impl GcdArgs { @@ -50,4 +34,16 @@ impl GcdArgs { .expect("internal error: fail to setup log subscriber"); Ok(()) } + + pub fn from_plusargs(matcher: &PlusArgMatcher) -> Self { + Self { + #[cfg(feature = "trace")] + dump_start: matcher.match_("dump-start").parse().unwrap(), + #[cfg(feature = "trace")] + dump_end: matcher.match_("dump-end").parse().unwrap(), + #[cfg(feature = "trace")] + wave_path: matcher.match_("wave-path").into(), + log_level: matcher.try_match("log-level").unwrap_or("info").into(), + } + } } diff --git a/templates/chisel/gcdemu/src/plusarg.rs b/templates/chisel/gcdemu/src/plusarg.rs new file mode 100644 index 0000000..4164f5f --- /dev/null +++ b/templates/chisel/gcdemu/src/plusarg.rs @@ -0,0 +1,31 @@ +pub struct PlusArgMatcher { + plusargs: Vec, +} + +impl PlusArgMatcher { + pub fn from_args() -> Self { + let plusargs = std::env::args() + .filter(|arg| arg.starts_with('+')) + .collect(); + + Self { plusargs } + } + + pub fn try_match(&self, arg_name: &str) -> Option<&str> { + let prefix = &format!("+{arg_name}="); + + for plusarg in &self.plusargs { + if plusarg.starts_with(prefix) { + return Some(&plusarg[prefix.len()..]); + } + } + None + } + + pub fn match_(&self, arg_name: &str) -> &str { + self.try_match(arg_name).unwrap_or_else(|| { + tracing::error!("required plusarg '+{arg_name}=' not found"); + panic!("failed to match '+{arg_name}='"); + }) + } +} diff --git a/templates/chisel/nix/gcd/dpi-lib.nix b/templates/chisel/nix/gcd/dpi-lib.nix index b4dcb56..0221009 100644 --- a/templates/chisel/nix/gcd/dpi-lib.nix +++ b/templates/chisel/nix/gcd/dpi-lib.nix @@ -14,7 +14,7 @@ rustPlatform.buildRustPackage rec { name = "dpi-lib"; src = ./../../${dpiLibName}; - cargoHash = "sha256-soOva+RFpbA74zyoOIms0G6HLt7dpYcpatsBQSI3hsM="; + cargoHash = "sha256-DzedUaBSNOT552x+/4RjeUcKs68HxAiejQ60BgZnUYc="; buildFeatures = lib.optionals sv2023 [ "sv2023" ] ++ lib.optionals vpi [ "vpi" ] ++ lib.optionals enable-trace [ "trace" ];