From 76ad5fe5dd36f561b95c45990da5991ea65ede21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20L=C3=A4ufer?= Date: Tue, 5 Mar 2024 16:00:16 -0500 Subject: [PATCH] ghw: example loads --- src/ghw/common.rs | 7 ++++++- src/ghw/hierarchy.rs | 4 ++-- src/ghw/signals.rs | 12 +++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ghw/common.rs b/src/ghw/common.rs index 6746f68..371a2ed 100644 --- a/src/ghw/common.rs +++ b/src/ghw/common.rs @@ -292,16 +292,18 @@ pub struct GhwVecInfo { max: GhwSignalId, min: GhwSignalId, two_state: bool, + signal_ref: SignalRef, /// pointer to an alias list alias: Option, } impl GhwVecInfo { - pub fn new(min: GhwSignalId, max: GhwSignalId, two_state: bool) -> Self { + pub fn new(min: GhwSignalId, max: GhwSignalId, two_state: bool, signal_ref: SignalRef) -> Self { Self { min, max, two_state, + signal_ref, alias: None, } } @@ -317,6 +319,9 @@ impl GhwVecInfo { pub fn max(&self) -> GhwSignalId { self.max } + pub fn signal_ref(&self) -> SignalRef { + self.signal_ref + } pub fn alias(&self) -> Option { self.alias } diff --git a/src/ghw/hierarchy.rs b/src/ghw/hierarchy.rs index c90eb91..bdac196 100644 --- a/src/ghw/hierarchy.rs +++ b/src/ghw/hierarchy.rs @@ -1052,14 +1052,14 @@ impl GhwSignals { // create a new vec entry let vec_id = self.vectors.len(); + let id = self.new_signal_ref(); self.vectors - .push(GhwVecInfo::new(min_id, max_id, is_binary)); + .push(GhwVecInfo::new(min_id, max_id, is_binary, id)); let tpe = if is_binary { SignalType::TwoStateVec } else { SignalType::NineStateVec }; - let id = self.new_signal_ref(); // update all bits for ii in min..=max { diff --git a/src/ghw/signals.rs b/src/ghw/signals.rs index 7f7442a..4fb00e5 100644 --- a/src/ghw/signals.rs +++ b/src/ghw/signals.rs @@ -4,7 +4,7 @@ use crate::ghw::common::*; use crate::wavemem::{Encoder, States}; -use crate::Hierarchy; +use crate::{Hierarchy, SignalRef}; use std::io::BufRead; /// Reads the GHW signal values. `input` should be advanced until right after the end of hierarchy @@ -133,8 +133,7 @@ fn read_cycle_signals( /// This dispatches any remaining vector changes. fn finish_time_step(vecs: &mut VecBuffer, enc: &mut Encoder) { vecs.process_changed_signals(|signal_ref, data, states| { - todo!("finish timestep with vec_id! {signal_ref:?}"); - // enc.raw_value_change(signal_ref, data, states); + enc.raw_value_change(signal_ref, data, states); }) } @@ -224,6 +223,7 @@ struct VecBufferInfo { bit_change_start: u32, bits: u32, states: States, + signal_ref: SignalRef, } impl VecBufferInfo { @@ -259,6 +259,7 @@ impl VecBuffer { bit_change_start: bit_change_start as u32, bits, states, + signal_ref: vector.signal_ref(), }); data_start += (bits as usize).div_ceil(states.bits_in_a_byte()); bit_change_start += (bits as usize).div_ceil(8); @@ -278,13 +279,14 @@ impl VecBuffer { } } - fn process_changed_signals(&mut self, mut callback: impl FnMut(GhwVecId, &[u8], States)) { + fn process_changed_signals(&mut self, mut callback: impl FnMut(SignalRef, &[u8], States)) { let change_list = std::mem::take(&mut self.change_list); for vec_id in change_list.into_iter() { if self.has_signal_changed(vec_id) { let states = self.info[vec_id.index()].states; + let signal_ref = self.info[vec_id.index()].signal_ref; let data = self.get_full_value_and_clear_changes(vec_id); - (callback)(vec_id, data, states); + (callback)(signal_ref, data, states); } } }