From ea6701f104d50754eecd6f3ac4c85669f4836aa8 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sat, 20 Aug 2022 02:58:48 -0400 Subject: [PATCH] now parsing single bit 0|1|x|z|u --- src/vcd/parse/events.rs | 511 ++++++++++++++++++---------------------- 1 file changed, 228 insertions(+), 283 deletions(-) diff --git a/src/vcd/parse/events.rs b/src/vcd/parse/events.rs index 29d861f..9dfb319 100644 --- a/src/vcd/parse/events.rs +++ b/src/vcd/parse/events.rs @@ -185,7 +185,6 @@ pub(super) fn parse_events<'a>( })?; lsb_indxs_of_num_tmstmp_vals_on_tmln .push(LsbIdxOfTmstmpValOnTmln(curr_tmstmp_lsb_idx)); - byte_len_of_num_tmstmp_vals_on_tmln.push(curr_num_bytes); // we may need to zero extend values // so that we end up storing all values @@ -194,19 +193,10 @@ pub(super) fn parse_events<'a>( let bytes_required = Signal::bytes_required(num_bits, name)?; while curr_num_bytes < bytes_required { - // TODO: remove once library is known to be stable - // useful for debugging - // let err = format!("Error at {cursor:?}.\ - // num_bits = {num_bits}, \ - // observed_bits = {observed_num_bits}, \ - // curr_num_bytes = {curr_num_bytes}, \ - // bytes_required = {bytes_required} \ - // for signal {name}"); - // Err(err)?; - - byte_len_of_num_tmstmp_vals_on_tmln.push(0u8); + nums_encoded_as_fixed_width_le_u8.push(0u8); curr_num_bytes += 1; } + byte_len_of_num_tmstmp_vals_on_tmln.push(curr_num_bytes); Ok(()) } } @@ -221,288 +211,243 @@ pub(super) fn parse_events<'a>( } // handle the case of a one bit signal whose value is set to `0` - // "0" => { - // // lookup signal idx - // let hash = &word[1..]; - // let SignalIdx(ref signal_idx) = signal_map.get(hash).ok_or(()).map_err(|_| { - // format!( - // "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", - // file!(), - // line!() - // ) - // })?; + "0" => { + // lookup signal idx + let hash = &word[1..]; + let signal_idx = signal_map.get(hash).ok_or(()).map_err(|_| { + format!( + "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", + file!(), + line!() + ) + })?; - // // account for fact that signal idx could be an alias, so there - // // could be one step of indirection - // let signal_idx = { - // let signal = vcd.all_signals.get(*signal_idx).unwrap(); - // match signal { - // Signal::Data { .. } => *signal_idx, - // Signal::Alias { signal_alias, .. } => { - // let SignalIdx(ref signal_idx) = signal_alias; - // signal_idx.clone() - // } - // } - // }; + let signal = vcd.try_dereference_alias_mut(signal_idx)?; - // // after handling potential indirection, go ahead and update the timeline - // // of the signal signal_idx references - // let signal = vcd.all_signals.get_mut(signal_idx).unwrap(); - // match signal { - // Signal::Data { - // name, - // sig_type, - // ref mut signal_error, - // num_bits, - // u8_timeline, - // u8_timeline_markers, - // .. - // } => { - // // if this is a bad signal, go ahead and skip it - // if signal_error.is_some() { - // continue; - // } + match signal { + Signal::Data { + name, + sig_type, + ref mut signal_error, + num_bits, + self_idx, + nums_encoded_as_fixed_width_le_u8, + string_vals, + lsb_indxs_of_num_tmstmp_vals_on_tmln, + byte_len_of_num_tmstmp_vals_on_tmln, + lsb_indxs_of_string_tmstmp_vals_on_tmln, + byte_len_of_string_tmstmp_vals_on_tmln, + scope_parent, + } => { + // if this is a bad signal, go ahead and skip it + if signal_error.is_some() { + continue; + } - // // Get bitwidth and verify that it is 1. - // // Also account for the error case of a bitwidth of `None` - // match num_bits { - // Some(ref num_bits) => { - // if *num_bits != 1 { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // of sig_type {sig_type:?} is expected to be `1` not \ - // `{num_bits}`. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // *signal_error = Some(msg); - // continue; - // } - // } - // None => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // must be specified for a signal of type {sig_type:?}. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // Err(msg)?; - // } - // }; + // Get bitwidth and verify that it is 1. + // Also account for the error case of a bitwidth of `None` + match num_bits { + Some(ref num_bits) => { + if *num_bits != 1 { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + of sig_type {sig_type:?} is expected to be `1` not \ + `{num_bits}`. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + *signal_error = Some(msg); + continue; + } + } + None => { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + must be specified for a signal of type {sig_type:?}. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + Err(msg)?; + } + }; + nums_encoded_as_fixed_width_le_u8.push(0u8); + lsb_indxs_of_num_tmstmp_vals_on_tmln + .push(LsbIdxOfTmstmpValOnTmln(curr_tmstmp_lsb_idx)); + byte_len_of_num_tmstmp_vals_on_tmln.push(1u8); + Ok(()) + } + Signal::Alias { .. } => { + let (f, l) = (file!(), line!()); + let msg = format!( + "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ + This error occurred while parsing vcd file at {cursor:?}"); + Err(msg) + } + }?; + } - // let (f, l) = (file!(), line!()); - // let timeline_idx = u32::try_from(vcd.tmstmps_encoded_as_u8s.len()) - // .map_err(|_| { - // format!("Error near {f}:{l}. Failed to convert from usize to u32.") - // })?; - // let timeline_idx = TimelineIdx(timeline_idx); + "1" => { + // lokup signal idx + let hash = &word[1..]; + let signal_idx = signal_map.get(hash).ok_or(()).map_err(|_| { + format!( + "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", + file!(), + line!() + ) + })?; - // u8_timeline_markers.push(timeline_idx); - // u8_timeline.push(0u8); - // Ok(()) - // } - // Signal::Alias { .. } => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ - // This error occurred while parsing vcd file at {cursor:?}"); - // Err(msg) - // } - // }?; - // } + let signal = vcd.try_dereference_alias_mut(signal_idx)?; - // "1" => { - // // lokup signal idx - // let hash = &word[1..]; - // let SignalIdx(ref signal_idx) = signal_map.get(hash).ok_or(()).map_err(|_| { - // format!( - // "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", - // file!(), - // line!() - // ) - // })?; + match signal { + Signal::Data { + name, + sig_type, + ref mut signal_error, + num_bits, + self_idx, + nums_encoded_as_fixed_width_le_u8, + string_vals, + lsb_indxs_of_num_tmstmp_vals_on_tmln, + byte_len_of_num_tmstmp_vals_on_tmln, + lsb_indxs_of_string_tmstmp_vals_on_tmln, + byte_len_of_string_tmstmp_vals_on_tmln, + scope_parent, + } => { + // if this is a bad signal, go ahead and skip it + if signal_error.is_some() { + continue; + } - // // account for fact that signal idx could be an alias, so there - // // could be one step of indirection - // let signal_idx = { - // let signal = vcd.all_signals.get(*signal_idx).unwrap(); - // match signal { - // Signal::Data { .. } => *signal_idx, - // Signal::Alias { signal_alias, .. } => { - // let SignalIdx(ref signal_idx) = signal_alias; - // signal_idx.clone() - // } - // } - // }; + // Get bitwidth and verify that it is 1. + // Also account for the error case of a bitwidth of `None` + match num_bits { + Some(ref num_bits) => { + if *num_bits != 1 { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + of sig_type {sig_type:?} is expected to be `1` not \ + `{num_bits}`. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + *signal_error = Some(msg); + continue; + } + } + None => { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + must be specified for a signal of type {sig_type:?}. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + Err(msg)?; + } + }; + nums_encoded_as_fixed_width_le_u8.push(1u8); + lsb_indxs_of_num_tmstmp_vals_on_tmln + .push(LsbIdxOfTmstmpValOnTmln(curr_tmstmp_lsb_idx)); + byte_len_of_num_tmstmp_vals_on_tmln.push(1u8); + Ok(()) + } + Signal::Alias { .. } => { + let (f, l) = (file!(), line!()); + let msg = format!( + "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ + This error occurred while parsing vcd file at {cursor:?}"); + Err(msg) + } + }?; + } - // // after handling potential indirection, go ahead and update the timeline - // // of the signal signal_idx references - // let signal = vcd.all_signals.get_mut(signal_idx).unwrap(); - // match signal { - // Signal::Data { - // name, - // sig_type, - // ref mut signal_error, - // num_bits, - // u8_timeline, - // u8_timeline_markers, - // .. - // } => { - // // if this is a bad signal, go ahead and skip it - // if signal_error.is_some() { - // continue; - // } + // other one bit cases + "x" | "X" | "z" | "Z" | "u" | "U" => { + let val = word.to_string(); + // lokup signal idx + let hash = &word[1..]; + let signal_idx = signal_map.get(hash).ok_or(()).map_err(|_| { + format!( + "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", + file!(), + line!() + ) + })?; - // // Get bitwidth and verify that it is 1. - // // Also account for the error case of a bitwidth of `None` - // match num_bits { - // Some(ref num_bits) => { - // if *num_bits != 1 { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // of sig_type {sig_type:?} is expected to be `1` not \ - // `{num_bits}`. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // *signal_error = Some(msg); - // continue; - // } - // } - // None => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // must be specified for a signal of type {sig_type:?}. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // Err(msg)?; - // } - // }; + let signal = vcd.try_dereference_alias_mut(signal_idx)?; - // let (f, l) = (file!(), line!()); - // let timeline_idx = u32::try_from(vcd.tmstmps_encoded_as_u8s.len()) - // .map_err(|_| { - // format!("Error near {f}:{l}. Failed to convert from usize to u32.") - // })?; - // let timeline_idx = TimelineIdx(timeline_idx); + match signal { + Signal::Data { + name, + sig_type, + ref mut signal_error, + num_bits, + self_idx, + nums_encoded_as_fixed_width_le_u8, + string_vals, + lsb_indxs_of_num_tmstmp_vals_on_tmln, + byte_len_of_num_tmstmp_vals_on_tmln, + lsb_indxs_of_string_tmstmp_vals_on_tmln, + byte_len_of_string_tmstmp_vals_on_tmln, + scope_parent, + } => { + // if this is a bad signal, go ahead and skip it + if signal_error.is_some() { + continue; + } - // u8_timeline_markers.push(timeline_idx); - // u8_timeline.push(1u8); - // Ok(()) - // } - // Signal::Alias { .. } => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ - // This error occurred while parsing vcd file at {cursor:?}"); - // Err(msg) - // } - // }?; - // } - // // other one bit cases - // "x" | "X" | "z" | "Z" | "u" | "U" => { - // let val = word.to_string(); - // // lokup signal idx - // let hash = &word[1..]; - // let SignalIdx(ref signal_idx) = signal_map.get(hash).ok_or(()).map_err(|_| { - // format!( - // "Error near {}:{}. Failed to lookup signal {hash} at {cursor:?}", - // file!(), - // line!() - // ) - // })?; - - // // account for fact that signal idx could be an alias, so there - // // could be one step of indirection - // let signal_idx = { - // let signal = vcd.all_signals.get(*signal_idx).unwrap(); - // match signal { - // Signal::Data { .. } => *signal_idx, - // Signal::Alias { signal_alias, .. } => { - // let SignalIdx(ref signal_idx) = signal_alias; - // signal_idx.clone() - // } - // } - // }; - - // // after handling potential indirection, go ahead and update the timeline - // // of the signal signal_idx references - // let signal = vcd.all_signals.get_mut(signal_idx).unwrap(); - // match signal { - // Signal::Data { - // name, - // sig_type, - // ref mut signal_error, - // num_bits, - // string_timeline, - // string_timeline_markers, - // .. - // } => { - // // if this is a bad signal, go ahead and skip it - // if signal_error.is_some() { - // continue; - // } - - // // Get bitwidth and verify that it is 1. - // // Also account for the error case of a bitwidth of `None` - // match num_bits { - // Some(ref num_bits) => { - // if *num_bits != 1 { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // of sig_type {sig_type:?} is expected to be `1` not \ - // `{num_bits}`. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // *signal_error = Some(msg); - // continue; - // } - // } - // None => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "\ - // Error near {f}:{l}. The bitwidth for signal {name} \ - // must be specified for a signal of type {sig_type:?}. \ - // This error occurred while parsing the vcd file at \ - // {cursor:?}" - // ); - // Err(msg)?; - // } - // }; - - // let (f, l) = (file!(), line!()); - // let timeline_idx = u32::try_from(vcd.tmstmps_encoded_as_u8s.len()) - // .map_err(|_| { - // format!("Error near {f}:{l}. Failed to convert from usize to u32.") - // })?; - // let timeline_idx = TimelineIdx(timeline_idx); - - // string_timeline_markers.push(timeline_idx); - // string_timeline.push(val); - // Ok(()) - // } - // Signal::Alias { .. } => { - // let (f, l) = (file!(), line!()); - // let msg = format!( - // "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ - // This error occurred while parsing vcd file at {cursor:?}"); - // Err(msg) - // } - // }?; - // } + // Get bitwidth and verify that it is 1. + // Also account for the error case of a bitwidth of `None` + match num_bits { + Some(ref num_bits) => { + if *num_bits != 1 { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + of sig_type {sig_type:?} is expected to be `1` not \ + `{num_bits}`. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + *signal_error = Some(msg); + continue; + } + } + None => { + let (f, l) = (file!(), line!()); + let msg = format!( + "\ + Error near {f}:{l}. The bitwidth for signal {name} \ + must be specified for a signal of type {sig_type:?}. \ + This error occurred while parsing the vcd file at \ + {cursor:?}" + ); + Err(msg)?; + } + }; + string_vals.push(val); + lsb_indxs_of_string_tmstmp_vals_on_tmln + .push(LsbIdxOfTmstmpValOnTmln(curr_tmstmp_lsb_idx)); + Ok(()) + } + Signal::Alias { .. } => { + let (f, l) = (file!(), line!()); + let msg = format!( + "Error near {f}:{l}, a signal alias should not point to a signal alias.\n\ + This error occurred while parsing vcd file at {cursor:?}"); + Err(msg) + } + }?; + } _ => {} } }