still broken - but I need to save progress

This commit is contained in:
Yehowshua Immanuel 2022-07-27 09:35:44 -04:00
parent 18a69872ab
commit 504913c719
2 changed files with 72 additions and 11 deletions

View file

@ -164,8 +164,9 @@ fn parse_events<'a>(
} }
} }
else { else {
let (f, l )= (file!(), line!());
let value = BigInt::parse_bytes(value.as_bytes(), 10).ok_or( let value = BigInt::parse_bytes(value.as_bytes(), 10).ok_or(
format!("failed to parse {value} as BigInt at {cursor:?}").as_str())?; format!("Error near {f}:{l}. Failed to parse {value} as BigInt at {cursor:?}").as_str())?;
vcd.cursor = Value::BigInt(value); vcd.cursor = Value::BigInt(value);
Ok(()) Ok(())
}; };
@ -187,12 +188,14 @@ fn parse_events<'a>(
// There could have been other parse errors... // There could have been other parse errors...
// Return Err below if there were. // Return Err below if there were.
if e.kind() != &IntErrorKind::PosOverflow { if e.kind() != &IntErrorKind::PosOverflow {
Err(format!("{e:?}"))?; let (f, l )= (file!(), line!());
Err(format!("Error near {f}:{l}. {e:?}"))?;
} }
match value.parse::<u16>() { match value.parse::<u16>() {
Ok(value) => { Ok(value) => {
vcd.cursor = Value::u16(value); vcd.cursor = Value::u16(value);
println!("switching to u16");
Ok(()) Ok(())
} }
Err(e) => Err(e) Err(e) => Err(e)
@ -215,12 +218,14 @@ fn parse_events<'a>(
// There could have been other parse errors... // There could have been other parse errors...
// Return Err below if there were. // Return Err below if there were.
if e.kind() != &IntErrorKind::PosOverflow { if e.kind() != &IntErrorKind::PosOverflow {
Err(format!("{e:?}"))?; let (f, l )= (file!(), line!());
Err(format!("Error near {f}:{l}. {e:?}"))?;
} }
match value.parse::<u32>() { match value.parse::<u32>() {
Ok(value) => { Ok(value) => {
vcd.cursor = Value::u32(value); vcd.cursor = Value::u32(value);
println!("switching to u32");
Ok(()) Ok(())
} }
Err(e) => Err(e) Err(e) => Err(e)
@ -243,17 +248,66 @@ fn parse_events<'a>(
// There could have been other parse errors... // There could have been other parse errors...
// Return Err below if there were. // Return Err below if there were.
if e.kind() != &IntErrorKind::PosOverflow { if e.kind() != &IntErrorKind::PosOverflow {
Err(format!("{e:?}"))?; let (f, l )= (file!(), line!());
Err(format!("Error near {f}:{l}. {e:?}"))?;
} }
match value.parse::<u64>() { match value.parse::<u64>() {
Ok(value) => { Ok(value) => {
vcd.cursor = Value::u64(value); vcd.cursor = Value::u64(value);
println!("switching to u64");
Ok(()) Ok(())
} }
Err(e) => Err(e) Err(e) => Err(e)
} }
}; };
// If there was no parse error, we don't evaluate any more logic
// in this match arm and simply continue to the next iteration of
// the outer loop to evaluate the next word.
if parse_ok.is_ok() {
continue
}
// Try parsing value as u64 since there was a previous
// PosOverflow error, and record if this parse attempt
// was Ok or Err in parse_ok.
let parse_ok =
{
let e = parse_ok.unwrap_err();
// There could have been other parse errors...
// Return Err below if there were.
if e.kind() != &IntErrorKind::PosOverflow {
let (f, l )= (file!(), line!());
Err(format!("Error near {f}:{l}. {e:?}"))?;
}
match value.parse::<u64>() {
Ok(value) => {
vcd.cursor = Value::u64(value);
println!("switching to u64");
Ok(())
}
Err(e) => Err(e)
}
};
// Try parsing value as BigInt since there was a previous
// PosOverflow error and propagate any Result Errors.
let e = parse_ok.unwrap_err();
// There could have been other parse errors...
// Return Err below if there were.
if e.kind() != &IntErrorKind::PosOverflow {
let (f, l )= (file!(), line!());
Err(format!("Error near {f}:{l}. {e:?}"))?;
}
let (f, l )= (file!(), line!());
let value = BigInt::parse_bytes(value.as_bytes(), 10).ok_or(
format!("Error near {f}:{l}. Failed to parse {value} as BigInt at {cursor:?}").as_str())?;
vcd.cursor = Value::BigInt(value);
println!("switching to BigInt");
} }
"0" => { "0" => {
// lokup signal idx // lokup signal idx
@ -278,14 +332,14 @@ fn parse_events<'a>(
// after handling potential indirection, go ahead and update the timeline // after handling potential indirection, go ahead and update the timeline
// of the signal signal_idx references // of the signal signal_idx references
let signal = vcd.all_signals.get_mut(0usize).unwrap(); let signal = vcd.all_signals.get_mut(signal_idx).unwrap();
// let signal = vcd.all_signals.get_mut(signal_idx).unwrap();
match signal { match signal {
Signal::Data {name, sig_type, num_bits, Signal::Data {name, sig_type, num_bits,
self_idx, timeline, scope_parent} => { self_idx, timeline, scope_parent} => {
let value = 0.to_bigint().unwrap(); // let pair = (0.to_bigint(), Value::u8(0));
let pair = (vcd.cursor.clone(), Value::u8(0)); let pair = (Value::u8(0), Value::u8(0));
timeline.push(pair); let t = 0u32.to_be_bytes();
// timeline.push(pair);
Ok(()) Ok(())
} }
Signal::Alias {..} => { Signal::Alias {..} => {
@ -358,6 +412,7 @@ pub fn parse_vcd(file : File) -> Result<VCD, String> {
let mut vcd = VCD{ let mut vcd = VCD{
metadata : header, metadata : header,
cursor : Value::u8(0), cursor : Value::u8(0),
timeline : vec![],
all_signals: vec![], all_signals: vec![],
all_scopes : vec![], all_scopes : vec![],
scope_roots: vec![], scope_roots: vec![],

View file

@ -21,6 +21,9 @@ pub(super) struct Scope_Idx(pub(super) usize);
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub(super) struct Signal_Idx(pub(super) usize); pub(super) struct Signal_Idx(pub(super) usize);
#[derive(Debug, Copy, Clone)]
pub(super) struct TimelineIdx(pub(super) usize);
#[derive(Debug)] #[derive(Debug)]
pub(super) enum Sig_Type {Integer, Parameter, Real, Reg, Str, Wire, Tri1, Time} pub(super) enum Sig_Type {Integer, Parameter, Real, Reg, Str, Wire, Tri1, Time}
@ -42,6 +45,8 @@ pub(super) enum Value {
BigInt(BigInt), BigInt(BigInt),
} }
pub type BigNum = Vec<u8>;
#[derive(Debug)] #[derive(Debug)]
pub(super) enum Sig_Value { pub(super) enum Sig_Value {
Numeric(u64), Numeric(u64),
@ -55,7 +60,7 @@ pub(super) enum Signal{
num_bits : Option<usize>, num_bits : Option<usize>,
// TODO : may be able to remove self_idx // TODO : may be able to remove self_idx
self_idx : Signal_Idx, self_idx : Signal_Idx,
timeline : Vec<(Value, Value)>, timeline : Vec<(TimelineIdx, BigNum)>,
scope_parent : Scope_Idx}, scope_parent : Scope_Idx},
Alias{ Alias{
name : String, name : String,
@ -77,7 +82,8 @@ pub(super) struct Scope {
#[derive(Debug)] #[derive(Debug)]
pub struct VCD { pub struct VCD {
pub(super) metadata : Metadata, pub(super) metadata : Metadata,
pub (super) cursor : Value, pub(super) cursor : Value,
pub(super) timeline : Vec<BigNum>,
pub(super) all_signals : Vec<Signal>, pub(super) all_signals : Vec<Signal>,
pub(super) all_scopes : Vec<Scope>, pub(super) all_scopes : Vec<Scope>,
pub(super) scope_roots : Vec<Scope_Idx>} pub(super) scope_roots : Vec<Scope_Idx>}