From 825b947bad4005961afe5c23bc377ca5e4ec9beb Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 20 May 2022 22:52:26 -0400 Subject: [PATCH] Some changes including: - modify data structures to support arenas - preliminary work on parser --- README.md | 1 + src/main.rs | 113 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 3580a09..3bf6430 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ The first build of the program may take some time. - [ ] Need to perform signal aliasing - use vec of enum {Sig, Alias} - [ ] Should insert nodes in BFS order + - [ ] Change states to lowercase - [ ] We need to start regression testing the parser over all files - [ ] Take a look at GTKWave parser to compare effificiency. - [ ] Send survey to community channel. diff --git a/src/main.rs b/src/main.rs index a8f468b..a869248 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,54 +12,113 @@ use clap::Parser; struct Cli { /// The path to the file to read #[clap(parse(from_os_str))] - path: std::path::PathBuf, -} + path: std::path::PathBuf} // TODO: implement any timescales greater than a second enum Timescale {ps, ns, us, ms, s} +struct Scope_Idx(usize); +struct Signal_Idx(usize); + struct Metadata { - date : DateTime, + date : DateTime, version : String, - timescale : Timescale -} + timescale : Timescale} struct Signal { - name : String, - timeline : BTreeMap, - children_arena: Vec, - parent_index : usize - -} + name : String, + timeline : BTreeMap, + scope_parent : Scope_Idx} struct SignalAlias { name : String, - signal_alias : Rc -} + signal_alias : Signal_Idx} enum SignalGeneric{ Signal(Signal), - SignalAlias(SignalAlias), -} + SignalAlias(SignalAlias)} struct Scope { - name : String, - signals : Vec, - scopes : Vec, -} + name : String, + child_signals : Vec, + child_scopes : Vec} struct VCD { - metadata : Metadata, - top_scopes : Vec + metadata : Metadata, + all_signals : Vec, + // the root scope should always be placed at index 0 + all_scopes : Vec} + +#[derive(Debug)] +enum Date_Parser_State {Weekday, Month, Day, HHMMSS, Year} +#[derive(Debug)] +enum VCD_Parser_State { + Begin, + Date(Date_Parser_State), + Signal_Tree, Values} + +struct DateBuffer { + Weekday : String, + Month : String, + Day : String, + HHMMSS : String, + Year : String} + +struct VCD_Parser<'a> { + vcd_parser_state : VCD_Parser_State, + date_parser_state : Date_Parser_State, + date_buffer : DateBuffer, + + vcd : &'a VCD, + curr_scope : &'a Scope, + curr_parent_scope : &'a Scope} + +impl VCD { + pub fn new() -> Self { + let dt = Utc + .datetime_from_str("Thu Jan 1 00:00:00 1970", "%a %b %e %T %Y") + .unwrap(); + let metadata = Metadata { + date : dt, + version : "".to_string(), + timescale : Timescale::ps}; + let signal = Vec::::new(); + VCD { + metadata : metadata, + all_signals : Vec::::new(), + all_scopes : Vec::::new()}}} + +impl<'a> VCD_Parser<'a> { + pub fn new(&mut self, vcd : &'a VCD) { + self.vcd_parser_state = VCD_Parser_State::Begin; + self.date_parser_state = Date_Parser_State::Weekday; + self.vcd = vcd;} + + pub fn parse_word(&mut self, word : &str) -> Result<(), String> { + let mut state = &mut self.vcd_parser_state; + match state { + VCD_Parser_State::Begin => { + match word { + "$date" => {*state = VCD_Parser_State::Date(Date_Parser_State::Weekday); Ok(())}, + // "$version" => {*state = VCD_Parser_State::VERSION_ENTER; Ok(())}, + // "$timescale" => {*state = VCD_Parser_State::TIMESCALE_ENTER; Ok(())}, + _ => Err(format!("unsure what to do with {word:?}"))}}, + + VCD_Parser_State::Date(Date_Parser_State) => { + let res = self.parse_date(word); Ok(()) + } + _ => Err(format!("parser in bad state : {state:?}"))} + } + + pub fn parse_date(&mut self, word : &str) -> Result<(), String> { + let mut state = &mut self.date_parser_state; + Ok(()) + } } - -enum VCD_Parser_State {Date, Version, Timescale, SignalTree, Values} -enum Date_Parser_State {Date, Day, Month, HHMMSS, Year} - -fn parse_vcd(word: &str, mut state : VCD_Parser_State) {} -fn parse_date(word : &str, mut state : Date_Parser_State) {} +fn advance_VCD_parser_FSM(word: &str, mut state : VCD_Parser_State) {} +fn advance_Date_parser_FSM(word : &str, mut state : Date_Parser_State) {} fn yield_word_and_apply(file : File, mut f : impl FnMut(&str)) { let mut reader = io::BufReader::new(file);