From f96c38dd67fe1c2d038201a71b6b8f0ae8088d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20L=C3=A4ufer?= Date: Wed, 12 Jun 2024 15:50:48 -0400 Subject: [PATCH] fst: add small hack to deal with how NVC encodes bools --- Cargo.toml | 2 +- wellen/inputs/nvc/vhdl_test_bool_issue_16.fst | Bin 0 -> 263 bytes wellen/src/fst.rs | 20 +++++++++++++++++- wellen/tests/fst.rs | 20 ++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 wellen/inputs/nvc/vhdl_test_bool_issue_16.fst diff --git a/Cargo.toml b/Cargo.toml index 06ce0a9..054f86c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = ["wellen"] default-members = ["wellen"] [workspace.package] -version = "0.9.10" +version = "0.9.11" edition = "2021" # we require the `div_ceil` method on integers rust-version = "1.73.0" diff --git a/wellen/inputs/nvc/vhdl_test_bool_issue_16.fst b/wellen/inputs/nvc/vhdl_test_bool_issue_16.fst new file mode 100644 index 0000000000000000000000000000000000000000..dbbbc933af3cdcee0cc5c340cfd6f718c1d603df GIT binary patch literal 263 zcmeyz00xX~5SqzUzMBKWWKK?CV0QE8;ANbxcf>HIt-GZ7ZF(ugM@xaAo*ggxD^pK$ zwNRYYRJT2RpMWGb;=0m9$=A-N4Ym9%Saj zz~Z3D$*SbAwI`5=XH90O<8HaExJ0G5My?llsOGpeuZ(5`038&03 zjk7=GIetVg*u$dnR_Q)(sm$m1huN { let bits = len.get(); - debug_assert_eq!(value.len(), bits as usize); + + // nvc will declare boolean signals as 1-bit bit-vectors and then generate + // the strings "true" and "false" + let value = if value.len() > bits as usize && bits == 1 { + match value { + b"true" => b"1", + b"false" => b"0", + _ => value, + } + } else { + value + }; + + debug_assert_eq!( + value.len(), + bits as usize, + "{}", + String::from_utf8_lossy(value) + ); let local_encoding = check_states(value).unwrap_or_else(|| { panic!( "Unexpected signal value: {}", diff --git a/wellen/tests/fst.rs b/wellen/tests/fst.rs index 977e6e3..3c2f943 100644 --- a/wellen/tests/fst.rs +++ b/wellen/tests/fst.rs @@ -183,3 +183,23 @@ fn test_scope_merging() { fn test_nvc_xwb_fofb_shaper_filt_tb() { let _waves = read("inputs/nvc/xwb_fofb_shaper_filt_tb.fst").unwrap(); } + +fn load_all_signals(waves: &mut Waveform) { + let all_signals = waves + .hierarchy() + .get_unique_signals_vars() + .iter() + .flatten() + .map(|v| v.signal_ref()) + .collect::>(); + waves.load_signals(&all_signals); +} + +/// This file was provided by Augusto Fraga Giachero in the following issue: +/// https://github.com/ekiwi/wellen/issues/16 +#[test] +fn test_nvc_vhdl_test_bool_issue_16() { + // turns out that NVC needs a little hack to deal with the way it encodes booleans + let mut waves = read("inputs/nvc/vhdl_test_bool_issue_16.fst").unwrap(); + load_all_signals(&mut waves); +}