Some changes including:

- modify data structures to support arenas
 - preliminary work on parser
This commit is contained in:
Yehowshua Immanuel 2022-05-20 22:52:26 -04:00
parent 7d1c0e16a8
commit 825b947bad
2 changed files with 87 additions and 27 deletions

View file

@ -24,6 +24,7 @@ The first build of the program may take some time.
- [ ] Need to perform signal aliasing - [ ] Need to perform signal aliasing
- use vec of enum {Sig, Alias} - use vec of enum {Sig, Alias}
- [ ] Should insert nodes in BFS order - [ ] Should insert nodes in BFS order
- [ ] Change states to lowercase
- [ ] We need to start regression testing the parser over all files - [ ] We need to start regression testing the parser over all files
- [ ] Take a look at GTKWave parser to compare effificiency. - [ ] Take a look at GTKWave parser to compare effificiency.
- [ ] Send survey to community channel. - [ ] Send survey to community channel.

View file

@ -12,54 +12,113 @@ use clap::Parser;
struct Cli { struct Cli {
/// The path to the file to read /// The path to the file to read
#[clap(parse(from_os_str))] #[clap(parse(from_os_str))]
path: std::path::PathBuf, path: std::path::PathBuf}
}
// TODO: implement any timescales greater than a second // TODO: implement any timescales greater than a second
enum Timescale {ps, ns, us, ms, s} enum Timescale {ps, ns, us, ms, s}
struct Scope_Idx(usize);
struct Signal_Idx(usize);
struct Metadata { struct Metadata {
date : DateTime<FixedOffset>, date : DateTime<Utc>,
version : String, version : String,
timescale : Timescale timescale : Timescale}
}
struct Signal { struct Signal {
name : String, name : String,
timeline : BTreeMap<BigInt, BigInt>, timeline : BTreeMap<BigInt, BigInt>,
children_arena: Vec<usize>, scope_parent : Scope_Idx}
parent_index : usize
}
struct SignalAlias { struct SignalAlias {
name : String, name : String,
signal_alias : Rc<Signal> signal_alias : Signal_Idx}
}
enum SignalGeneric{ enum SignalGeneric{
Signal(Signal), Signal(Signal),
SignalAlias(SignalAlias), SignalAlias(SignalAlias)}
}
struct Scope { struct Scope {
name : String, name : String,
signals : Vec<SignalGeneric>, child_signals : Vec<Signal_Idx>,
scopes : Vec<Scope>, child_scopes : Vec<Scope_Idx>}
}
struct VCD { struct VCD {
metadata : Metadata, metadata : Metadata,
top_scopes : Vec<Scope> all_signals : Vec<SignalGeneric>,
// the root scope should always be placed at index 0
all_scopes : Vec<Scope>}
#[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::<SignalGeneric>::new();
VCD {
metadata : metadata,
all_signals : Vec::<SignalGeneric>::new(),
all_scopes : Vec::<Scope>::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(())
}
} }
fn advance_VCD_parser_FSM(word: &str, mut state : VCD_Parser_State) {}
enum VCD_Parser_State {Date, Version, Timescale, SignalTree, Values} fn advance_Date_parser_FSM(word : &str, mut state : Date_Parser_State) {}
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 yield_word_and_apply(file : File, mut f : impl FnMut(&str)) { fn yield_word_and_apply(file : File, mut f : impl FnMut(&str)) {
let mut reader = io::BufReader::new(file); let mut reader = io::BufReader::new(file);