Skip to content

Commit

Permalink
move index out of signal type
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Jun 13, 2024
1 parent f96c38d commit caf740b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = ["wellen"]
default-members = ["wellen"]

[workspace.package]
version = "0.9.11"
version = "0.9.12"
edition = "2021"
# we require the `div_ceil` method on integers
rust-version = "1.73.0"
Expand Down
4 changes: 2 additions & 2 deletions wellen/src/fst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl SignalWriter {
self.time_indices.push(time_idx);
}
}
SignalType::BitVector(len, _) => {
SignalType::BitVector(len) => {
let bits = len.get();

// nvc will declare boolean signals as 1-bit bit-vectors and then generate
Expand Down Expand Up @@ -288,7 +288,7 @@ impl SignalWriter {
self.data_bytes,
)
}
SignalType::BitVector(len, _) => {
SignalType::BitVector(len) => {
debug_assert!(self.strings.is_empty());
let (bytes, meta_byte) = get_len_and_meta(self.max_states, len.get());
let encoding = SignalEncoding::BitVector {
Expand Down
25 changes: 12 additions & 13 deletions wellen/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ impl SignalRef {
pub enum SignalType {
String,
Real,
BitVector(NonZeroU32, Option<VarIndex>),
BitVector(NonZeroU32),
}

impl SignalType {
pub fn from_uint(len: u32, index: Option<VarIndex>) -> Self {
pub fn from_uint(len: u32) -> Self {
match NonZeroU32::new(len) {
// a zero length signal should be represented as a 1-bit signal
None => SignalType::BitVector(NonZeroU32::new(1).unwrap(), index),
Some(value) => SignalType::BitVector(value, index),
None => SignalType::BitVector(NonZeroU32::new(1).unwrap()),
Some(value) => SignalType::BitVector(value),
}
}
}
Expand All @@ -270,6 +270,7 @@ pub struct Var {
var_tpe: VarType,
direction: VarDirection,
signal_tpe: SignalType,
index: Option<VarIndex>,
signal_idx: SignalRef,
enum_type: Option<EnumTypeId>,
vhdl_type_name: Option<HierarchyStringId>,
Expand Down Expand Up @@ -329,10 +330,7 @@ impl Var {
self.direction
}
pub fn index(&self) -> Option<VarIndex> {
match &self.signal_tpe {
SignalType::BitVector(_, index) => *index,
_ => None,
}
self.index
}
pub fn signal_ref(&self) -> SignalRef {
self.signal_idx
Expand All @@ -341,7 +339,7 @@ impl Var {
match &self.signal_tpe {
SignalType::String => None,
SignalType::Real => None,
SignalType::BitVector(len, _) => Some(len.get()),
SignalType::BitVector(len) => Some(len.get()),
}
}
pub fn is_real(&self) -> bool {
Expand All @@ -351,7 +349,7 @@ impl Var {
matches!(self.signal_tpe, SignalType::String)
}
pub fn is_bit_vector(&self) -> bool {
matches!(self.signal_tpe, SignalType::BitVector(_, _))
matches!(self.signal_tpe, SignalType::BitVector(_))
}
pub fn is_1bit(&self) -> bool {
match self.length() {
Expand Down Expand Up @@ -1081,14 +1079,15 @@ impl HierarchyBuilder {
let signal_tpe = match tpe {
VarType::String => SignalType::String,
VarType::Real => SignalType::Real,
_ => SignalType::from_uint(raw_length, index),
_ => SignalType::from_uint(raw_length),
};

// now we can build the node data structure and store it
let node = Var {
parent,
name,
var_tpe: tpe,
index,
direction,
signal_tpe,
signal_idx,
Expand Down Expand Up @@ -1185,8 +1184,8 @@ mod tests {
// unfortunately this one is pretty big
assert_eq!(std::mem::size_of::<HierarchyItemId>(), 8);

// 4 byte length, 8 byte index + tag + padding
assert_eq!(std::mem::size_of::<SignalType>(), 16);
// 4 byte length + tag + padding
assert_eq!(std::mem::size_of::<SignalType>(), 8);

// Var
assert_eq!(
Expand Down
8 changes: 4 additions & 4 deletions wellen/src/wavemem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Reader {
&mut strings,
);
}
SignalType::BitVector(signal_len, _) => {
SignalType::BitVector(signal_len) => {
load_fixed_len_signal(
&mut data.as_ref(),
time_idx_offset,
Expand All @@ -178,7 +178,7 @@ impl Reader {
debug_assert!(data_bytes.is_empty());
Signal::new_var_len(id, time_indices, strings)
}
SignalType::BitVector(len, _) => {
SignalType::BitVector(len) => {
debug_assert!(strings.is_empty());
let (bytes, meta_byte) = get_len_and_meta(meta.max_states, len.get());
let encoding = SignalEncoding::BitVector {
Expand Down Expand Up @@ -707,7 +707,7 @@ impl SignalEncoder {
let time_idx_delta = time_index - self.prev_time_idx;
self.max_states = States::join(self.max_states, states);
match self.tpe {
SignalType::BitVector(len, _) => {
SignalType::BitVector(len) => {
let bits = len.get();
if bits == 1 {
debug_assert_eq!(value.len(), 1);
Expand Down Expand Up @@ -771,7 +771,7 @@ impl SignalEncoder {
fn add_vcd_change(&mut self, time_index: u16, value: &[u8]) {
let time_idx_delta = time_index - self.prev_time_idx;
match self.tpe {
SignalType::BitVector(len, _) => {
SignalType::BitVector(len) => {
let value_bits: &[u8] = match value[0] {
b'b' | b'B' => &value[1..],
_ => value,
Expand Down

0 comments on commit caf740b

Please sign in to comment.