Add .to_trace_as_string() and clean up code

This commit is contained in:
Jacob Lifshay 2026-05-13 23:32:33 -07:00
parent ea183eac87
commit cf3e6cfc6b
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
18 changed files with 894 additions and 255 deletions

View file

@ -13,7 +13,7 @@ use fayalite::{
prelude::*,
reset::ResetType,
sim::vcd::VcdWriterDecls,
ty::{SimValueDebug, StaticType, TraceAsString, TraceAsStringSimValue},
ty::SimValueDebug,
util::{RcWriter, ready_valid::queue},
};
use std::{collections::BTreeMap, num::NonZeroUsize, rc::Rc};
@ -3019,6 +3019,9 @@ impl HasCustomDebug {
}
}
}
pub fn new(text: Result<&str, std::fmt::Error>) -> Expr<Self> {
Self::new_sim(text).to_expr()
}
}
impl SimValueDebug for HasCustomDebug {
@ -3061,10 +3064,7 @@ pub fn sim_trace_as_string() {
#[hdl]
let write: WriteStruct<Array<TraceAsString<HasCustomDebug>, 2>, ConstUsize<8>> = m.input();
#[hdl]
let mut mem = memory_with_init(
[[Expr::as_trace_as_string(HasCustomDebug::new_sim(Ok("")).to_expr(), StaticType::TYPE); 2];
4],
);
let mut mem = memory_with_init([[HasCustomDebug::new(Ok("")).to_trace_as_string(); 2]; 4]);
let read_port = mem.new_read_port();
connect(read_port.clk, clk);
connect_any(read_port.addr, read.addr);
@ -3156,7 +3156,7 @@ fn test_sim_trace_as_string() {
sim.write(sim.io().write.en, write_addr.is_some());
sim.write(
sim.io().write.data,
write_data.map(|v| TraceAsStringSimValue::new(HasCustomDebug::new_sim(v))),
write_data.map(|v| HasCustomDebug::new_sim(v).to_trace_as_string()),
);
sim.write(
sim.io().write.mask,
@ -3172,7 +3172,7 @@ fn test_sim_trace_as_string() {
.map(HasCustomDebug::new_sim)
.into_sim_value();
assert!(
**read_data == *expected_read_data,
*read_data.inner() == expected_read_data,
"{read_data:#?}\n!= {expected_read_data:#?}",
);
}

View file

@ -55,7 +55,7 @@ error[E0277]: `Rc<(dyn value::sim_only_value_unsafe::DynSimOnlyValueTrait + 'sta
note: required because it appears within the type `DynSimOnlyValue`
--> src/sim/value/sim_only_value_unsafe.rs
|
271 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
281 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
| ^^^^^^^^^^^^^^^
note: required because it appears within the type `PhantomData<DynSimOnlyValue>`
--> $RUST/core/src/marker.rs
@ -75,12 +75,12 @@ note: required because it appears within the type `Vec<DynSimOnlyValue>`
note: required because it appears within the type `OpaqueSimValue`
--> src/ty.rs
|
895 | pub struct OpaqueSimValue {
896 | pub struct OpaqueSimValue {
| ^^^^^^^^^^^^^^
note: required because it appears within the type `value::SimValueInner<()>`
--> src/sim/value.rs
|
52 | struct SimValueInner<T: Type> {
51 | struct SimValueInner<T: Type> {
| ^^^^^^^^^^^^^
note: required because it appears within the type `UnsafeCell<value::SimValueInner<()>>`
--> $RUST/core/src/cell.rs
@ -95,7 +95,7 @@ note: required because it appears within the type `util::alternating_cell::Alter
note: required because it appears within the type `fayalite::prelude::SimValue<()>`
--> src/sim/value.rs
|
161 | pub struct SimValue<T: Type> {
160 | pub struct SimValue<T: Type> {
| ^^^^^^^^
note: required by a bound in `fayalite::intern::Interned`
--> src/intern.rs
@ -194,7 +194,7 @@ error[E0277]: `Rc<(dyn value::sim_only_value_unsafe::DynSimOnlyValueTrait + 'sta
note: required because it appears within the type `DynSimOnlyValue`
--> src/sim/value/sim_only_value_unsafe.rs
|
271 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
281 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
| ^^^^^^^^^^^^^^^
note: required because it appears within the type `PhantomData<DynSimOnlyValue>`
--> $RUST/core/src/marker.rs
@ -214,12 +214,12 @@ note: required because it appears within the type `Vec<DynSimOnlyValue>`
note: required because it appears within the type `OpaqueSimValue`
--> src/ty.rs
|
895 | pub struct OpaqueSimValue {
896 | pub struct OpaqueSimValue {
| ^^^^^^^^^^^^^^
note: required because it appears within the type `value::SimValueInner<()>`
--> src/sim/value.rs
|
52 | struct SimValueInner<T: Type> {
51 | struct SimValueInner<T: Type> {
| ^^^^^^^^^^^^^
note: required because it appears within the type `UnsafeCell<value::SimValueInner<()>>`
--> $RUST/core/src/cell.rs
@ -234,7 +234,7 @@ note: required because it appears within the type `util::alternating_cell::Alter
note: required because it appears within the type `fayalite::prelude::SimValue<()>`
--> src/sim/value.rs
|
161 | pub struct SimValue<T: Type> {
160 | pub struct SimValue<T: Type> {
| ^^^^^^^^
note: required by a bound in `intern_sized`
--> src/intern.rs
@ -306,7 +306,7 @@ error[E0277]: `Rc<(dyn value::sim_only_value_unsafe::DynSimOnlyValueTrait + 'sta
note: required because it appears within the type `DynSimOnlyValue`
--> src/sim/value/sim_only_value_unsafe.rs
|
271 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
281 | pub struct DynSimOnlyValue(Rc<dyn DynSimOnlyValueTrait>);
| ^^^^^^^^^^^^^^^
note: required because it appears within the type `PhantomData<DynSimOnlyValue>`
--> $RUST/core/src/marker.rs
@ -326,12 +326,12 @@ note: required because it appears within the type `Vec<DynSimOnlyValue>`
note: required because it appears within the type `OpaqueSimValue`
--> src/ty.rs
|
895 | pub struct OpaqueSimValue {
896 | pub struct OpaqueSimValue {
| ^^^^^^^^^^^^^^
note: required because it appears within the type `value::SimValueInner<()>`
--> src/sim/value.rs
|
52 | struct SimValueInner<T: Type> {
51 | struct SimValueInner<T: Type> {
| ^^^^^^^^^^^^^
note: required because it appears within the type `UnsafeCell<value::SimValueInner<()>>`
--> $RUST/core/src/cell.rs
@ -346,7 +346,7 @@ note: required because it appears within the type `util::alternating_cell::Alter
note: required because it appears within the type `fayalite::prelude::SimValue<()>`
--> src/sim/value.rs
|
161 | pub struct SimValue<T: Type> {
160 | pub struct SimValue<T: Type> {
| ^^^^^^^^
note: required by a bound in `fayalite::intern::Interned`
--> src/intern.rs