kaze/runtime/
tracing.rs

1//! Rust simulator runtime dependencies for tracing.
2
3pub mod vcd;
4
5use std::io;
6
7// TODO: Do we want to re-use graph::Constant for this? They're equivalent but currently distinct in their usage, so I'm not sure it's the right API design decision.
8#[derive(Debug, Eq, PartialEq)]
9pub enum TraceValue {
10    /// Contains a boolean value
11    Bool(bool),
12    /// Contains an unsigned, 32-bit value
13    U32(u32),
14    /// Contains an unsigned, 64-bit value
15    U64(u64),
16    /// Contains an unsigned, 128-bit value
17    U128(u128),
18}
19
20#[derive(Debug, Eq, PartialEq)]
21pub enum TraceValueType {
22    Bool,
23    U32,
24    U64,
25    U128,
26}
27
28impl TraceValueType {
29    pub(crate) fn from_bit_width(bit_width: u32) -> TraceValueType {
30        if bit_width == 1 {
31            TraceValueType::Bool
32        } else if bit_width <= 32 {
33            TraceValueType::U32
34        } else if bit_width <= 64 {
35            TraceValueType::U64
36        } else if bit_width <= 128 {
37            TraceValueType::U128
38        } else {
39            unreachable!()
40        }
41    }
42}
43
44pub trait Trace {
45    type SignalId;
46
47    fn push_module(&mut self, name: &'static str) -> io::Result<()>;
48    fn pop_module(&mut self) -> io::Result<()>;
49    fn add_signal(
50        &mut self,
51        name: &'static str,
52        bit_width: u32,
53        type_: TraceValueType,
54    ) -> io::Result<Self::SignalId>;
55
56    fn update_time_stamp(&mut self, time_stamp: u64) -> io::Result<()>;
57    fn update_signal(&mut self, signal_id: &Self::SignalId, value: TraceValue) -> io::Result<()>;
58}