From 9f18b166a5caeeea80992bf42e51a4a6c55b1b82 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 26 Oct 2022 01:16:39 -0400 Subject: [PATCH] sane import and export behaviors --- examples/parse_vcd.rs | 6 ++---- examples/vcd.rs | 2 +- src/lib.rs | 6 +++++- src/vcd.rs | 18 +++++------------- src/vcd/parse.rs | 26 +++++++------------------- src/vcd/parse/combinator_atoms.rs | 2 +- src/vcd/parse/events.rs | 9 ++++++++- src/vcd/parse/metadata.rs | 8 ++++++-- src/vcd/parse/scopes.rs | 12 ++++++++++-- src/vcd/reader.rs | 2 +- src/vcd/signal.rs | 9 ++++----- src/vcd/types.rs | 24 ++++++++++++------------ 12 files changed, 62 insertions(+), 62 deletions(-) diff --git a/examples/parse_vcd.rs b/examples/parse_vcd.rs index 9833f3c..4d7f5da 100644 --- a/examples/parse_vcd.rs +++ b/examples/parse_vcd.rs @@ -5,9 +5,7 @@ use clap::Parser; use std::fs::File; -use fastwave_backend::*; - -use num::{BigUint}; +use fastwave_backend::parse_vcd; #[derive(Parser)] struct Cli { @@ -23,7 +21,7 @@ fn main() -> std::io::Result<()> { let now = Instant::now(); let file = File::open(&args.path)?; - let vcd = parse_vcd(file).unwrap(); + parse_vcd(file).unwrap(); let elapsed = now.elapsed(); println!("Parsed VCD file {} : {:.2?}", &args.path.as_os_str().to_str().unwrap(), elapsed); diff --git a/examples/vcd.rs b/examples/vcd.rs index af552bd..2577410 100644 --- a/examples/vcd.rs +++ b/examples/vcd.rs @@ -4,7 +4,7 @@ // the root of the folder containing the sources for this program. use std::fs::File; -use fastwave_backend::*; +use fastwave_backend::{ScopeIdx, VCD, parse_vcd}; fn indented_print(indent : u8, name : &String) { for _ in 0..indent {print!(" |");} diff --git a/src/lib.rs b/src/lib.rs index f28b750..f73512a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,11 @@ // 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. + mod vcd; -pub use vcd::*; +pub use vcd::parse::parse_vcd; +pub use vcd::types::{ScopeIdx, SignalIdx, VCD}; +pub use vcd::types::{Metadata, Timescale, Version}; +pub use vcd::signal::{Signal}; pub use num::BigUint; diff --git a/src/vcd.rs b/src/vcd.rs index 10419ec..fc58b13 100644 --- a/src/vcd.rs +++ b/src/vcd.rs @@ -2,17 +2,9 @@ // 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. + mod reader; -use reader::*; - -mod types; -pub use types::*; - -mod parse; -pub use parse::*; - -mod signal; -pub use signal::*; - -mod utilities; -use utilities::*; +pub(crate) mod types; +pub(crate) mod parse; +pub(crate) mod signal; +mod utilities; \ No newline at end of file diff --git a/src/vcd/parse.rs b/src/vcd/parse.rs index fcdd9fe..c89361c 100644 --- a/src/vcd/parse.rs +++ b/src/vcd/parse.rs @@ -2,38 +2,26 @@ // 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::BigUint; -use std::collections::HashMap; use std::fs::File; -use super::*; - mod combinator_atoms; -use combinator_atoms::*; - mod types; -use types::*; - mod metadata; -use metadata::*; - mod scopes; -use scopes::*; - mod events; -use events::*; -pub fn parse_vcd(file: File) -> Result { - let mut word_gen = WordReader::new(file); - let header = parse_metadata(&mut word_gen)?; +pub fn parse_vcd(file: File) -> Result { + let mut word_gen = super::reader::WordReader::new(file); + + let header = metadata::parse_metadata(&mut word_gen)?; // later, we'll need to map parsed ascii symbols to their // respective signal indexes let mut signal_map = std::collections::HashMap::new(); // after we parse metadata, we form the VCD object - let mut vcd = VCD { + let mut vcd = super::types::VCD { metadata: header, tmstmps_encoded_as_u8s: vec![], all_signals: vec![], @@ -41,8 +29,8 @@ pub fn parse_vcd(file: File) -> Result { root_scopes: vec![], }; - parse_scopes(&mut word_gen, &mut vcd, &mut signal_map)?; - parse_events(&mut word_gen, &mut vcd, &mut signal_map)?; + scopes::parse_scopes(&mut word_gen, &mut vcd, &mut signal_map)?; + events::parse_events(&mut word_gen, &mut vcd, &mut signal_map)?; Ok(vcd) } \ No newline at end of file diff --git a/src/vcd/parse/combinator_atoms.rs b/src/vcd/parse/combinator_atoms.rs index 4329831..0473f63 100644 --- a/src/vcd/parse/combinator_atoms.rs +++ b/src/vcd/parse/combinator_atoms.rs @@ -2,7 +2,7 @@ // 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 super::reader::{next_word, WordReader}; +use super::super::reader::{next_word, WordReader}; use super::types::ParseResult; pub(super) fn digit(chr: u8) -> bool { diff --git a/src/vcd/parse/events.rs b/src/vcd/parse/events.rs index 79418c0..05e24ed 100644 --- a/src/vcd/parse/events.rs +++ b/src/vcd/parse/events.rs @@ -3,7 +3,14 @@ // and the YEHOWSHUA license, both of which can be found at // the root of the folder containing the sources for this program. -use super::*; +use std::collections::HashMap; +use num::BigUint; + +use super::super::utilities::{BinaryParserErrTypes, binary_str_to_vec_u8}; +use super::super::signal::{SignalEnum, LsbIdxOfTmstmpValOnTmln}; +use super::super::reader::{WordReader, Cursor, Line, Word, next_word}; +use super::super::types::{SignalIdx, VCD}; + pub(super) fn parse_events<'a>( word_reader: &mut WordReader, diff --git a/src/vcd/parse/metadata.rs b/src/vcd/parse/metadata.rs index d847f32..6d0fffc 100644 --- a/src/vcd/parse/metadata.rs +++ b/src/vcd/parse/metadata.rs @@ -2,10 +2,14 @@ // 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 chrono::prelude::*; +use chrono::prelude::{DateTime, Utc, TimeZone}; use itertools::Itertools; -use super::*; +use super::super::reader::{Cursor, WordReader, next_word}; +use super::super::types::{Timescale, Version, Metadata}; + +use super::combinator_atoms::{take_until, take_while, digit, tag}; +use super::types::{ParseResult}; pub(super) fn parse_date( word_and_ctx1: (&str, &Cursor), diff --git a/src/vcd/parse/scopes.rs b/src/vcd/parse/scopes.rs index 406a4f0..94b8965 100644 --- a/src/vcd/parse/scopes.rs +++ b/src/vcd/parse/scopes.rs @@ -5,7 +5,15 @@ /// part of the vcd parser that handles parsing the signal tree and /// building the resulting signal tree -use super::*; + +use std::collections::HashMap; + +use super::super::reader::{WordReader, next_word, curr_word}; +use super::super::types::{VCD, Scope, ScopeIdx, SignalIdx}; +use super::super::signal::{SigType, SignalEnum}; + +use super::combinator_atoms::{tag, ident}; +use super::types::{ParseResult}; pub(super) fn parse_var<'a>( word_reader: &mut WordReader, @@ -322,7 +330,7 @@ pub(super) fn parse_scopes<'a>( signal_map: &mut HashMap, ) -> Result<(), String> { // get the current word - let (word, cursor) = curr_word!(word_reader)?; + let (word, _) = curr_word!(word_reader)?; // we may have orphaned vars that occur before the first scope if word == "$var" { diff --git a/src/vcd/reader.rs b/src/vcd/reader.rs index 4be573f..9fc32ec 100644 --- a/src/vcd/reader.rs +++ b/src/vcd/reader.rs @@ -5,7 +5,7 @@ use std::collections::VecDeque; use std::fs::File; use std::io; -use std::io::prelude::*; +use std::io::BufRead; use std::slice; use std::str; diff --git a/src/vcd/signal.rs b/src/vcd/signal.rs index 6d8f03b..fb15c5a 100644 --- a/src/vcd/signal.rs +++ b/src/vcd/signal.rs @@ -1,10 +1,9 @@ -use crate::VCD; - // Copyright (C) 2022 Yehowshua Immanuel // 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 super::{ScopeIdx, SignalIdx}; +use super::types::{ScopeIdx, SignalIdx}; +use super::types; use num::{BigUint}; // Index to the least significant byte of a timestamp @@ -41,7 +40,7 @@ impl<'a> Signal<'a> { &self, desired_time: &BigUint, tmstmps_encoded_as_u8s: &Vec, - vcd: &VCD, + vcd: &types::VCD, ) -> Result { let Signal(signal_enum) = &self; signal_enum.query_string_val_on_tmln(desired_time, tmstmps_encoded_as_u8s, &vcd.all_signals) @@ -50,7 +49,7 @@ impl<'a> Signal<'a> { &self, desired_time: &BigUint, tmstmps_encoded_as_u8s: &Vec, - vcd: &VCD, + vcd: &types::VCD, ) -> Result { let Signal(signal_enum) = &self; signal_enum.query_num_val_on_tmln(desired_time, tmstmps_encoded_as_u8s, &vcd.all_signals) diff --git a/src/vcd/types.rs b/src/vcd/types.rs index 5dd934d..60be9bc 100644 --- a/src/vcd/types.rs +++ b/src/vcd/types.rs @@ -1,17 +1,17 @@ -use crate::Signal; +// use crate::Signal; // Copyright (C) 2022 Yehowshua Immanuel // 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 super::SignalEnum; -use chrono::prelude::*; +use chrono::prelude::{DateTime, Utc}; +use super::signal::{Signal, SignalEnum}; #[derive(Debug)] -pub(super) struct Version(pub String); +pub struct Version(pub String); #[derive(Debug)] -pub(super) enum Timescale { +pub enum Timescale { Fs, Ps, Ns, @@ -22,10 +22,10 @@ pub(super) enum Timescale { } #[derive(Debug)] -pub(super) struct Metadata { - pub(super) date: Option>, - pub(super) version: Option, - pub(super) timescale: (Option, Timescale), +pub struct Metadata { + pub date: Option>, + pub version: Option, + pub timescale: (Option, Timescale), } // We do a lot of arena allocation in this codebase. @@ -48,7 +48,7 @@ pub(super) struct Scope { #[derive(Debug)] pub struct VCD { - pub(super) metadata: Metadata, + pub metadata: Metadata, // Since we only need to store values when there is an actual change // in the timeline, we keep a vector that stores the time at which an // event occurs. Time t is always stored/encoded as the minimum length sequence @@ -100,7 +100,7 @@ impl VCD { // dereference signal if Signal::Alias, or keep idx if Signal::Data let signal_idx = match signal { SignalEnum::Data { self_idx, .. } => *self_idx, - SignalEnum::Alias { name, signal_alias } => *signal_alias, + SignalEnum::Alias {signal_alias, .. } => *signal_alias, }; // Should now point to Signal::Data variant, or else there's an error @@ -119,7 +119,7 @@ impl VCD { pub fn get_signal<'a>(&'a self, idx: SignalIdx) -> Signal<'a> { let SignalIdx(idx) = idx; let signal_enum = &self.all_signals[idx]; - return Signal(signal_enum) + return Signal(signal_enum); } // 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