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 0000000..dbbbc93 Binary files /dev/null and b/wellen/inputs/nvc/vhdl_test_bool_issue_16.fst differ diff --git a/wellen/src/fst.rs b/wellen/src/fst.rs index 503870c..29f3d6f 100644 --- a/wellen/src/fst.rs +++ b/wellen/src/fst.rs @@ -181,7 +181,25 @@ impl SignalWriter { } SignalType::BitVector(len, _) => { 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); +}