Add signal type query
This commit is contained in:
parent
0df20db383
commit
dba5773ebe
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
mod vcd;
|
mod vcd;
|
||||||
pub use vcd::parse::parse_vcd;
|
pub use vcd::parse::parse_vcd;
|
||||||
pub use vcd::signal::{Signal, SignalValue};
|
pub use vcd::signal::{Signal, SignalType, SignalValue};
|
||||||
pub use vcd::types::{Metadata, Timescale, Version};
|
pub use vcd::types::{Metadata, Timescale, Version};
|
||||||
pub use vcd::types::{ScopeIdx, SignalIdx, VCD};
|
pub use vcd::types::{ScopeIdx, SignalIdx, VCD};
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
match signal {
|
match signal {
|
||||||
SignalEnum::Data {
|
SignalEnum::Data {
|
||||||
name,
|
name,
|
||||||
sig_type,
|
signal_type,
|
||||||
ref mut signal_error,
|
ref mut signal_error,
|
||||||
num_bits,
|
num_bits,
|
||||||
num_bytes,
|
num_bytes,
|
||||||
|
@ -158,7 +158,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let (f, l) = (file!(), line!());
|
let (f, l) = (file!(), line!());
|
||||||
let msg = format!("\
|
let msg = format!("\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
of sig_type {sig_type:?} is expected to be `{num_bits}` not \
|
of signal_type {signal_type:?} is expected to be `{num_bits}` not \
|
||||||
`{observed_num_bits}`. \
|
`{observed_num_bits}`. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}");
|
{cursor:?}");
|
||||||
|
@ -171,7 +171,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
must be specified for a signal of type {sig_type:?}. \
|
must be specified for a signal of type {signal_type:?}. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
);
|
);
|
||||||
|
@ -245,7 +245,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
match signal {
|
match signal {
|
||||||
SignalEnum::Data {
|
SignalEnum::Data {
|
||||||
name,
|
name,
|
||||||
sig_type,
|
signal_type,
|
||||||
ref mut signal_error,
|
ref mut signal_error,
|
||||||
num_bits,
|
num_bits,
|
||||||
num_bytes,
|
num_bytes,
|
||||||
|
@ -268,7 +268,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
of sig_type {sig_type:?} is expected to be `1` not \
|
of signal_type {signal_type:?} is expected to be `1` not \
|
||||||
`{num_bits}`. \
|
`{num_bits}`. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
|
@ -282,7 +282,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
must be specified for a signal of type {sig_type:?}. \
|
must be specified for a signal of type {signal_type:?}. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
);
|
);
|
||||||
|
@ -336,7 +336,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
match signal {
|
match signal {
|
||||||
SignalEnum::Data {
|
SignalEnum::Data {
|
||||||
name,
|
name,
|
||||||
sig_type,
|
signal_type,
|
||||||
ref mut signal_error,
|
ref mut signal_error,
|
||||||
num_bits,
|
num_bits,
|
||||||
num_bytes,
|
num_bytes,
|
||||||
|
@ -359,7 +359,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
of sig_type {sig_type:?} is expected to be `1` not \
|
of signal_type {signal_type:?} is expected to be `1` not \
|
||||||
`{num_bits}`. \
|
`{num_bits}`. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
|
@ -373,7 +373,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
must be specified for a signal of type {sig_type:?}. \
|
must be specified for a signal of type {signal_type:?}. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
);
|
);
|
||||||
|
@ -430,7 +430,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
match signal {
|
match signal {
|
||||||
SignalEnum::Data {
|
SignalEnum::Data {
|
||||||
name,
|
name,
|
||||||
sig_type,
|
signal_type,
|
||||||
ref mut signal_error,
|
ref mut signal_error,
|
||||||
num_bits,
|
num_bits,
|
||||||
string_vals,
|
string_vals,
|
||||||
|
@ -452,7 +452,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
of sig_type {sig_type:?} is expected to be `1` not \
|
of signal_type {signal_type:?} is expected to be `1` not \
|
||||||
`{num_bits}`. \
|
`{num_bits}`. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
|
@ -466,7 +466,7 @@ pub(super) fn parse_events<R: std::io::Read>(
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"\
|
"\
|
||||||
Error near {f}:{l}. The bitwidth for signal {name} \
|
Error near {f}:{l}. The bitwidth for signal {name} \
|
||||||
must be specified for a signal of type {sig_type:?}. \
|
must be specified for a signal of type {signal_type:?}. \
|
||||||
This error occurred while parsing the vcd file at \
|
This error occurred while parsing the vcd file at \
|
||||||
{cursor:?}"
|
{cursor:?}"
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::super::reader::{curr_word, next_word, WordReader};
|
use super::super::reader::{curr_word, next_word, WordReader};
|
||||||
use super::super::signal::{SigType, SignalEnum};
|
use super::super::signal::{SignalEnum, SignalType};
|
||||||
use super::super::types::{Scope, ScopeIdx, SignalIdx, VCD};
|
use super::super::types::{Scope, ScopeIdx, SignalIdx, VCD};
|
||||||
|
|
||||||
use super::combinator_atoms::{ident, tag};
|
use super::combinator_atoms::{ident, tag};
|
||||||
|
@ -47,25 +47,25 @@ pub(super) fn parse_var<R: std::io::Read>(
|
||||||
// $var parameter 3 a IDLE $end
|
// $var parameter 3 a IDLE $end
|
||||||
// ^^^^^^^^^ - var_type
|
// ^^^^^^^^^ - var_type
|
||||||
let var_type = match word {
|
let var_type = match word {
|
||||||
"event" => Ok(SigType::Event),
|
"event" => Ok(SignalType::Event),
|
||||||
"integer" => Ok(SigType::Integer),
|
"integer" => Ok(SignalType::Integer),
|
||||||
"parameter" => Ok(SigType::Parameter),
|
"parameter" => Ok(SignalType::Parameter),
|
||||||
"real" => Ok(SigType::Real),
|
"real" => Ok(SignalType::Real),
|
||||||
"realtime" => Ok(SigType::RealTime),
|
"realtime" => Ok(SignalType::RealTime),
|
||||||
"reg" => Ok(SigType::Reg),
|
"reg" => Ok(SignalType::Reg),
|
||||||
"string" => Ok(SigType::Str),
|
"string" => Ok(SignalType::Str),
|
||||||
"supply0" => Ok(SigType::Supply0),
|
"supply0" => Ok(SignalType::Supply0),
|
||||||
"supply1" => Ok(SigType::Supply1),
|
"supply1" => Ok(SignalType::Supply1),
|
||||||
"tri" => Ok(SigType::Tri),
|
"tri" => Ok(SignalType::Tri),
|
||||||
"triand" => Ok(SigType::TriAnd),
|
"triand" => Ok(SignalType::TriAnd),
|
||||||
"trior" => Ok(SigType::TriOr),
|
"trior" => Ok(SignalType::TriOr),
|
||||||
"trireg" => Ok(SigType::TriReg),
|
"trireg" => Ok(SignalType::TriReg),
|
||||||
"tri0" => Ok(SigType::Tri0),
|
"tri0" => Ok(SignalType::Tri0),
|
||||||
"tri1" => Ok(SigType::Tri1),
|
"tri1" => Ok(SignalType::Tri1),
|
||||||
"time" => Ok(SigType::Time),
|
"time" => Ok(SignalType::Time),
|
||||||
"wand" => Ok(SigType::WAnd),
|
"wand" => Ok(SignalType::WAnd),
|
||||||
"wire" => Ok(SigType::Wire),
|
"wire" => Ok(SignalType::Wire),
|
||||||
"wor" => Ok(SigType::WOr),
|
"wor" => Ok(SignalType::WOr),
|
||||||
_ => {
|
_ => {
|
||||||
let err = format!(
|
let err = format!(
|
||||||
"Error near {}:{} \
|
"Error near {}:{} \
|
||||||
|
@ -85,13 +85,22 @@ pub(super) fn parse_var<R: std::io::Read>(
|
||||||
// $var parameter 3 a IDLE $end
|
// $var parameter 3 a IDLE $end
|
||||||
// ^ - num_bits
|
// ^ - num_bits
|
||||||
let num_bits = match var_type {
|
let num_bits = match var_type {
|
||||||
SigType::Integer
|
SignalType::Event
|
||||||
| SigType::Parameter
|
| SignalType::Integer
|
||||||
| SigType::Real
|
| SignalType::Parameter
|
||||||
| SigType::Reg
|
| SignalType::Reg
|
||||||
| SigType::Wire
|
| SignalType::Supply0
|
||||||
| SigType::Tri1
|
| SignalType::Supply1
|
||||||
| SigType::Time => {
|
| SignalType::Tri
|
||||||
|
| SignalType::TriAnd
|
||||||
|
| SignalType::TriOr
|
||||||
|
| SignalType::TriReg
|
||||||
|
| SignalType::Tri0
|
||||||
|
| SignalType::Tri1
|
||||||
|
| SignalType::Time
|
||||||
|
| SignalType::WAnd
|
||||||
|
| SignalType::Wire
|
||||||
|
| SignalType::WOr => {
|
||||||
let num_bits = word
|
let num_bits = word
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.unwrap_or_else(|_| panic!("{}", parse_err));
|
.unwrap_or_else(|_| panic!("{}", parse_err));
|
||||||
|
@ -105,7 +114,7 @@ pub(super) fn parse_var<R: std::io::Read>(
|
||||||
})?;
|
})?;
|
||||||
Some(num_bits)
|
Some(num_bits)
|
||||||
}
|
}
|
||||||
// for strings, we don't really care what the number of bits is
|
// for strings, reals, and realtimes we don't really care what the number of bits is
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,7 +169,7 @@ pub(super) fn parse_var<R: std::io::Read>(
|
||||||
.cloned()
|
.cloned()
|
||||||
.chain([full_signal_name])
|
.chain([full_signal_name])
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
sig_type: var_type,
|
signal_type: var_type,
|
||||||
signal_error: None,
|
signal_error: None,
|
||||||
num_bits,
|
num_bits,
|
||||||
num_bytes,
|
num_bytes,
|
||||||
|
|
|
@ -11,8 +11,8 @@ use num::BigUint;
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct LsbIdxOfTmstmpValOnTmln(pub(super) u32);
|
pub struct LsbIdxOfTmstmpValOnTmln(pub(super) u32);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum SigType {
|
pub enum SignalType {
|
||||||
Event,
|
Event,
|
||||||
Integer,
|
Integer,
|
||||||
Parameter,
|
Parameter,
|
||||||
|
@ -55,6 +55,11 @@ impl<'a> Signal<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn signal_type(&self) -> Option<&SignalType> {
|
||||||
|
let Signal(signal_enum) = &self;
|
||||||
|
signal_enum.signal_type()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn real_idx(&self) -> SignalIdx {
|
pub fn real_idx(&self) -> SignalIdx {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
SignalEnum::Data { self_idx, .. } => *self_idx,
|
SignalEnum::Data { self_idx, .. } => *self_idx,
|
||||||
|
@ -129,7 +134,7 @@ pub(super) enum SignalEnum {
|
||||||
Data {
|
Data {
|
||||||
name: String,
|
name: String,
|
||||||
path: Vec<String>,
|
path: Vec<String>,
|
||||||
sig_type: SigType,
|
signal_type: SignalType,
|
||||||
/// I've seen a 0 bit signal parameter in a xilinx
|
/// I've seen a 0 bit signal parameter in a xilinx
|
||||||
/// simulation before that gets assigned 1 bit values.
|
/// simulation before that gets assigned 1 bit values.
|
||||||
/// I consider this to be bad behavior. We capture such
|
/// I consider this to be bad behavior. We capture such
|
||||||
|
@ -204,6 +209,15 @@ impl SignalEnum {
|
||||||
}
|
}
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn signal_type(&self) -> Option<&SignalType> {
|
||||||
|
match self {
|
||||||
|
SignalEnum::Data { signal_type, .. } => Some(signal_type),
|
||||||
|
// TODO: Follow aliases?
|
||||||
|
SignalEnum::Alias { .. } => None,
|
||||||
|
}
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions ultimately used by Signal's query functions later on
|
// helper functions ultimately used by Signal's query functions later on
|
||||||
|
|
Loading…
Reference in a new issue