Refactor signal #6

Merged
ThePerfectComputer merged 5 commits from refactor-signal into main 2022-10-26 06:23:08 +00:00
4 changed files with 30 additions and 54 deletions
Showing only changes of commit 6abcd7ce32 - Show all commits

View file

@ -6,8 +6,6 @@ use std::fs::File;
use fastwave_backend::*;
use num::{BigUint};
fn indented_print(indent : u8, name : &String) {
for _ in 0..indent {print!(" |");}
print!("---");
@ -19,7 +17,15 @@ fn print_root_scope_tree(root_idx: ScopeIdx, vcd: &VCD, indent : u8) {
} else {
for child_scope_idx in vcd.child_scopes_by_idx(root_idx) {
indented_print(indent, vcd.scope_name_by_idx(child_scope_idx));
let ScopeIdx(idx) = child_scope_idx;
// for signal_idx in vcd.get_children_signal_idxs(child_scope_idx) {
// let signal = vcd.try_signal_idx_to_signal(signal_idx).unwrap();
// match signal {
// Signal::Data {..} => {}
// Signal::Alias {..} => {}
// }
// // let to_print = format!("{},{}", signal.name(), )
// }
// vcd.try_signal_idx_to_signal(idx)
print_root_scope_tree(child_scope_idx, vcd.clone(), indent + 1);
}
}
@ -47,7 +53,11 @@ fn main() -> std::io::Result<()> {
ui_all_scopes(&vcd);
// let state_signal = vcd.
let file_path = "tests/vcd-files/amaranth/up_counter.vcd";
let file = File::open(file_path)?;
let vcd = parse_vcd(file).unwrap();
// let state_signal = vcd.all_si
// for signal_idx in vcd.si
// let name = state_signal.name();
// let time = BigUint::from(57760000u32);
// let val = state_signal

View file

@ -2,7 +2,6 @@
// This program is distributed under both the GPLV3 license
// and the YEHOWSHUA license, both of which can be found at
// the root of the folder containing the sources for this program.
use num::Zero;
use super::*;
@ -13,7 +12,6 @@ pub(super) fn parse_events<'a>(
) -> Result<(), String> {
let mut curr_tmstmp_lsb_idx = 0u32;
let mut curr_tmstmp_len_u8 = 0u8;
let mut curr_time = BigUint::zero();
loop {
let next_word = word_reader.next_word();
@ -42,7 +40,6 @@ pub(super) fn parse_events<'a>(
"Error near {f}:{l}. Failed to parse {value} as BigInt at {cursor:?}"
)
})?;
curr_time = value.clone();
let mut value = value.to_bytes_le();
// TODO : u32 helps with less memory, but should ideally likely be
// configurable.
@ -422,7 +419,6 @@ pub(super) fn parse_events<'a>(
ref mut signal_error,
num_bits,
string_vals,
byte_len_of_num_tmstmp_vals_on_tmln,
byte_len_of_string_tmstmp_vals_on_tmln,
lsb_indxs_of_string_tmstmp_vals_on_tmln,
..
@ -497,12 +493,8 @@ pub(super) fn parse_events<'a>(
match signal {
Signal::Data {
name,
sig_type,
ref mut signal_error,
num_bits,
string_vals,
byte_len_of_num_tmstmp_vals_on_tmln,
byte_len_of_string_tmstmp_vals_on_tmln,
lsb_indxs_of_string_tmstmp_vals_on_tmln,
..

View file

@ -28,6 +28,7 @@ pub(super) enum TimelineQueryResults {
String(String),
}
#[derive(Debug)]
pub enum Signal {
Data {
@ -100,18 +101,6 @@ type SignalValNum = BigUint;
// getter functions
impl Signal {
pub fn self_idx(&self) -> Result<SignalIdx, String> {
match self {
Signal::Data { self_idx, ..} => {return Ok(self_idx.clone())},
Signal::Alias { .. } => Err(format!(
"Error near {}:{}. A signal alias shouldn't \
point to a signal alias.",
file!(),
line!()
)),
}
}
pub fn name(&self) -> String {
match self {
Signal::Data { name, ..} => name,

View file

@ -72,6 +72,11 @@ impl VCD {
let scope = &self.all_scopes[idx];
scope.child_scopes.clone()
}
pub fn get_children_signal_idxs(&self, scope_idx: ScopeIdx) -> Vec<SignalIdx> {
let ScopeIdx(idx) = scope_idx;
let scope = &self.all_scopes[idx];
scope.child_signals.clone()
}
pub fn scope_name_by_idx(&self, scope_idx: ScopeIdx) -> &String {
let ScopeIdx(idx) = scope_idx;
let scope = &self.all_scopes[idx];
@ -109,40 +114,20 @@ impl VCD {
)),
}
}
pub(super) fn dealiasing_signal_idx_to_signal_lookup<'a>(
&'a self,
idx: &SignalIdx,
) -> Result<&'a Signal, String> {
// get the signal pointed to be SignalIdx from the arena
let SignalIdx(idx) = idx;
let signal = &self.all_signals[*idx];
// dereference signal if Signal::Alias, or keep idx if Signal::Data
let signal_idx = match signal {
Signal::Data { self_idx, .. } => *self_idx,
Signal::Alias { name, signal_alias } => *signal_alias,
};
// Should now point to Signal::Data variant, or else there's an error
let SignalIdx(idx) = signal_idx;
let signal = self.all_signals.get(idx).unwrap();
match signal {
Signal::Data { .. } => Ok(signal),
Signal::Alias { .. } => Err(format!(
"Error near {}:{}. A signal alias shouldn't \
point to a signal alias.",
file!(),
line!()
)),
}
}
/// Takes a signal as input and returns the signal if the signal is of the
/// Signal::Data variant, else the function follows follows the uses the
/// Takes a signal_idx as input and returns the corresponding signal if the
/// corresponding signal is of the Signal::Data variant, else the function the
/// SignalIdx in the signal_alias field of Signal::Alias variant to index
/// into the signal arena in the all_signals field of the vcd, and returns
/// the resulting signal if that signal is a Signal::Data variant, else,
/// this function returns an Err.
pub fn dealiasing_signal_lookup<'a>(&'a self, signal: &Signal) -> Result<&'a Signal, String> {
pub fn try_signal_idx_to_signal<'a>(
&'a self,
idx: SignalIdx,
) -> Result<&'a Signal, String> {
// get the signal pointed to be SignalIdx from the arena
let SignalIdx(idx) = idx;
let signal = &self.all_signals[idx];
// dereference signal if Signal::Alias, or keep idx if Signal::Data
let signal_idx = match signal {
Signal::Data { self_idx, .. } => *self_idx,