expse paths and fix warnings

This commit is contained in:
TheZoq2 2023-06-16 17:08:20 +02:00
parent 53bbacd261
commit a8edb3d602
4 changed files with 33 additions and 19 deletions

View file

@ -2,7 +2,6 @@
// This program is distributed under both the GPLV3 license // This program is distributed under both the GPLV3 license
// and the YEHOWSHUA license, both of which can be found at // and the YEHOWSHUA license, both of which can be found at
// the root of the folder containing the sources for this program. // the root of the folder containing the sources for this program.
use std::fs::File;
mod combinator_atoms; mod combinator_atoms;
mod types; mod types;

View file

@ -20,6 +20,7 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
parent_scope_idx: ScopeIdx, parent_scope_idx: ScopeIdx,
vcd: &'a mut VCD, vcd: &'a mut VCD,
signal_map: &mut HashMap<String, SignalIdx>, signal_map: &mut HashMap<String, SignalIdx>,
path: &Vec<String>,
) -> Result<(), String> { ) -> Result<(), String> {
let (word, cursor) = next_word!(word_reader)?; let (word, cursor) = next_word!(word_reader)?;
let expected_types = [ let expected_types = [
@ -120,7 +121,8 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
Some(ref_signal_idx) => { Some(ref_signal_idx) => {
let signal_idx = SignalIdx(vcd.all_signals.len()); let signal_idx = SignalIdx(vcd.all_signals.len());
let signal = SignalEnum::Alias { let signal = SignalEnum::Alias {
name: full_signal_name, name: full_signal_name.clone(),
path: path.iter().cloned().chain([full_signal_name]).collect::<Vec<String>>(),
signal_alias: *ref_signal_idx, signal_alias: *ref_signal_idx,
}; };
(signal, signal_idx) (signal, signal_idx)
@ -129,11 +131,12 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
let signal_idx = SignalIdx(vcd.all_signals.len()); let signal_idx = SignalIdx(vcd.all_signals.len());
signal_map.insert(signal_alias.to_string(), signal_idx); signal_map.insert(signal_alias.to_string(), signal_idx);
let signal = SignalEnum::Data { let signal = SignalEnum::Data {
name: full_signal_name, name: full_signal_name.clone(),
path: path.iter().cloned().chain([full_signal_name]).collect::<Vec<String>>(),
sig_type: var_type, sig_type: var_type,
signal_error: None, signal_error: None,
num_bits: num_bits, num_bits,
num_bytes: num_bytes, num_bytes,
self_idx: signal_idx, self_idx: signal_idx,
nums_encoded_as_fixed_width_le_u8: vec![], nums_encoded_as_fixed_width_le_u8: vec![],
string_vals: vec![], string_vals: vec![],
@ -141,7 +144,6 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
byte_len_of_num_tmstmp_vals_on_tmln: vec![], byte_len_of_num_tmstmp_vals_on_tmln: vec![],
byte_len_of_string_tmstmp_vals_on_tmln: vec![], byte_len_of_string_tmstmp_vals_on_tmln: vec![],
lsb_indxs_of_string_tmstmp_vals_on_tmln: vec![], lsb_indxs_of_string_tmstmp_vals_on_tmln: vec![],
scope_parent: parent_scope_idx,
}; };
(signal, signal_idx) (signal, signal_idx)
} }
@ -185,7 +187,6 @@ fn parse_orphaned_vars<'a, R: std::io::Read>(
if !scope_already_exists { if !scope_already_exists {
vcd.all_scopes.push(Scope { vcd.all_scopes.push(Scope {
name: scope_name.to_string(), name: scope_name.to_string(),
parent_idx: None,
self_idx: scope_idx, self_idx: scope_idx,
child_signals: vec![], child_signals: vec![],
child_scopes: vec![], child_scopes: vec![],
@ -195,14 +196,14 @@ fn parse_orphaned_vars<'a, R: std::io::Read>(
// we can go ahead and parse the current var as we've already encountered // we can go ahead and parse the current var as we've already encountered
// "$var" before now. // "$var" before now.
parse_var(word_reader, scope_idx, vcd, signal_map)?; parse_var(word_reader, scope_idx, vcd, signal_map, &vec![])?;
loop { loop {
let (word, cursor) = next_word!(word_reader)?; let (word, cursor) = next_word!(word_reader)?;
match word { match word {
"$var" => { "$var" => {
parse_var(word_reader, scope_idx, vcd, signal_map)?; parse_var(word_reader, scope_idx, vcd, signal_map, &vec![])?;
} }
"$scope" => break, "$scope" => break,
_ => { _ => {
@ -226,6 +227,7 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
parent_scope_idx: Option<ScopeIdx>, parent_scope_idx: Option<ScopeIdx>,
vcd: &'a mut VCD, vcd: &'a mut VCD,
signal_map: &mut HashMap<String, SignalIdx>, signal_map: &mut HashMap<String, SignalIdx>,
path: &Vec<String>
) -> Result<(), String> { ) -> Result<(), String> {
// $scope module reg_mag_i $end // $scope module reg_mag_i $end
// ^^^^^^ - module keyword // ^^^^^^ - module keyword
@ -249,6 +251,9 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
// ^^^^^^^^^ - scope name // ^^^^^^^^^ - scope name
let (scope_name, _) = next_word!(word_reader)?; let (scope_name, _) = next_word!(word_reader)?;
let mut path = path.clone();
path.push(scope_name.to_string());
let curr_scope_idx = ScopeIdx(vcd.all_scopes.len()); let curr_scope_idx = ScopeIdx(vcd.all_scopes.len());
// register this scope as a child of the current parent scope // register this scope as a child of the current parent scope
@ -265,7 +270,6 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
// add this scope to list of existing scopes // add this scope to list of existing scopes
vcd.all_scopes.push(Scope { vcd.all_scopes.push(Scope {
name: scope_name.to_string(), name: scope_name.to_string(),
parent_idx: parent_scope_idx,
self_idx: curr_scope_idx, self_idx: curr_scope_idx,
child_signals: vec![], child_signals: vec![],
child_scopes: vec![], child_scopes: vec![],
@ -275,6 +279,8 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
// ^^^^ - end keyword // ^^^^ - end keyword
ident(word_reader, "$end")?; ident(word_reader, "$end")?;
loop { loop {
let (word, cursor) = next_word!(word_reader)?; let (word, cursor) = next_word!(word_reader)?;
let ParseResult { matched, residual } = tag(word, "$"); let ParseResult { matched, residual } = tag(word, "$");
@ -284,10 +290,10 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
match residual { match residual {
"scope" => { "scope" => {
// recursive - parse inside of current scope tree // recursive - parse inside of current scope tree
parse_scopes_inner(word_reader, Some(curr_scope_idx), vcd, signal_map)?; parse_scopes_inner(word_reader, Some(curr_scope_idx), vcd, signal_map, &path)?;
} }
"var" => { "var" => {
parse_var(word_reader, curr_scope_idx, vcd, signal_map)?; parse_var(word_reader, curr_scope_idx, vcd, signal_map, &path)?;
} }
"upscope" => { "upscope" => {
ident(word_reader, "$end")?; ident(word_reader, "$end")?;
@ -360,7 +366,7 @@ pub(super) fn parse_scopes<'a, R: std::io::Read>(
} }
// now for the interesting part // now for the interesting part
parse_scopes_inner(word_reader, None, vcd, signal_map)?; parse_scopes_inner(word_reader, None, vcd, signal_map, &vec![])?;
// let err = format!("reached end of file without parser leaving {}", function_name!()); // let err = format!("reached end of file without parser leaving {}", function_name!());
let expected_keywords = ["$scope", "$enddefinitions"]; let expected_keywords = ["$scope", "$enddefinitions"];
@ -374,7 +380,7 @@ pub(super) fn parse_scopes<'a, R: std::io::Read>(
match word { match word {
"$scope" => { "$scope" => {
parse_scopes_inner(word_reader, None, vcd, signal_map)?; parse_scopes_inner(word_reader, None, vcd, signal_map, &vec![])?;
} }
"$enddefinitions" => { "$enddefinitions" => {
ident(word_reader, "$end")?; ident(word_reader, "$end")?;

View file

@ -2,9 +2,9 @@
// This program is distributed under both the GPLV3 license // This program is distributed under both the GPLV3 license
// and the YEHOWSHUA license, both of which can be found at // and the YEHOWSHUA license, both of which can be found at
// the root of the folder containing the sources for this program. // the root of the folder containing the sources for this program.
use super::types::{ScopeIdx, SignalIdx}; use super::types::SignalIdx;
use super::types; use super::types;
use num::{BigUint}; use num::BigUint;
// Index to the least significant byte of a timestamp // Index to the least significant byte of a timestamp
// value on the timeline // value on the timeline
@ -37,6 +37,13 @@ impl<'a> Signal<'a> {
signal_enum.name() signal_enum.name()
} }
pub fn path(&self) -> &[String] {
match self.0 {
SignalEnum::Data {path, ..} => path,
SignalEnum::Alias { path, .. } => path,
}
}
pub fn num_bits(&self) -> Option<u16> { pub fn num_bits(&self) -> Option<u16> {
let Signal(signal_enum) = &self; let Signal(signal_enum) = &self;
signal_enum.bits_required() signal_enum.bits_required()
@ -101,6 +108,7 @@ impl<'a> Signal<'a> {
pub(super) enum SignalEnum { pub(super) enum SignalEnum {
Data { Data {
name: String, name: String,
path: Vec<String>,
sig_type: SigType, sig_type: SigType,
/// I've seen a 0 bit signal parameter in a xilinx /// I've seen a 0 bit signal parameter in a xilinx
/// simulation before that gets assigned 1 bit values. /// simulation before that gets assigned 1 bit values.
@ -136,10 +144,10 @@ pub(super) enum SignalEnum {
byte_len_of_num_tmstmp_vals_on_tmln: Vec<u8>, byte_len_of_num_tmstmp_vals_on_tmln: Vec<u8>,
byte_len_of_string_tmstmp_vals_on_tmln: Vec<u8>, byte_len_of_string_tmstmp_vals_on_tmln: Vec<u8>,
lsb_indxs_of_string_tmstmp_vals_on_tmln: Vec<LsbIdxOfTmstmpValOnTmln>, lsb_indxs_of_string_tmstmp_vals_on_tmln: Vec<LsbIdxOfTmstmpValOnTmln>,
scope_parent: ScopeIdx,
}, },
Alias { Alias {
name: String, name: String,
path: Vec<String>,
signal_alias: SignalIdx, signal_alias: SignalIdx,
}, },
} }
@ -305,7 +313,7 @@ impl SignalEnum {
match self { match self {
SignalEnum::Data {num_bits, ..} => num_bits.clone(), SignalEnum::Data {num_bits, ..} => num_bits.clone(),
// TODO: Follow aliases? // TODO: Follow aliases?
SignalEnum::Alias { name, signal_alias } => None, SignalEnum::Alias { .. } => None,
} }
} }
} }
@ -329,6 +337,7 @@ impl SignalEnum {
Self::Alias { Self::Alias {
name: _, name: _,
signal_alias, signal_alias,
path: _
} => { } => {
let SignalIdx(idx) = signal_alias; let SignalIdx(idx) = signal_alias;
*idx *idx
@ -443,6 +452,7 @@ impl SignalEnum {
} }
Self::Alias { Self::Alias {
name: _, name: _,
path: _,
signal_alias, signal_alias,
} => { } => {
let SignalIdx(idx) = signal_alias; let SignalIdx(idx) = signal_alias;

View file

@ -40,7 +40,6 @@ pub struct SignalIdx(pub usize);
pub(super) struct Scope { pub(super) struct Scope {
pub(super) name: String, pub(super) name: String,
pub(super) parent_idx: Option<ScopeIdx>,
pub(super) self_idx: ScopeIdx, pub(super) self_idx: ScopeIdx,
pub(super) child_signals: Vec<SignalIdx>, pub(super) child_signals: Vec<SignalIdx>,