able to parse all signal trees

This commit is contained in:
Yehowshua Immanuel 2022-07-15 20:48:02 -04:00
parent 217dea1d41
commit 298bbe1969
3 changed files with 137 additions and 44 deletions

View file

@ -21,7 +21,7 @@ pub(super) struct Scope_Idx(pub(super) usize);
pub(super) struct Signal_Idx(pub(super) usize);
#[derive(Debug)]
pub(super) enum Sig_Type {Integer, Parameter, Real, Reg, Str, Wire,}
pub(super) enum Sig_Type {Integer, Parameter, Real, Reg, Str, Wire, Tri1, Time}
#[derive(Debug)]
pub(super) enum Sig_Value {
@ -60,4 +60,47 @@ pub struct VCD {
pub(super) metadata : Metadata,
pub(super) all_signals : Vec<Signal>,
pub(super) all_scopes : Vec<Scope>,
pub(super) scope_roots : Vec<Scope_Idx>}
pub(super) scope_roots : Vec<Scope_Idx>}
impl VCD {
// TODO : make this a generic traversal function that applies specified
// functions upon encountering scopes and signals
fn print_scope_tree(
&self,
root_scope_idx : Scope_Idx,
depth : usize)
{
let all_scopes = &self.all_scopes;
let all_signals = &self.all_signals;
let indent = " ".repeat(depth * 4);
let Scope_Idx(root_scope_idx) = root_scope_idx;
let root_scope = &all_scopes[root_scope_idx];
let root_scope_name = &root_scope.name;
println!("{indent}scope: {root_scope_name}");
for Signal_Idx(ref signal_idx) in &root_scope.child_signals {
let child_signal = &all_signals[*signal_idx];
let name = match child_signal {
Signal::Data{name, ..} => {name}
Signal::Alias{name, ..} => {name}
};
println!("{indent} - sig: {name}")
}
println!();
for scope_idx in &root_scope.child_scopes {
// let Scope_Idx(ref scope_idx_usize) = scope_idx;
// let child_scope = &all_scopes[*scope_idx_usize];
self.print_scope_tree(*scope_idx, depth+1);
}
// let root = vcd.all_scopes;
}
pub fn print_scopes(&self) {
for scope_root in &self.scope_roots {
self.print_scope_tree(*scope_root, 0);
}
}
}