1
0
Fork 0

Compare commits

..

10 commits

114 changed files with 75275 additions and 921 deletions

View file

@ -18,6 +18,7 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/master' }}
- run: rustup override set 1.93.0
- run: rustup component add rust-src
- run: make -C rocq-demo
- run: cargo test
- run: cargo build --tests --features=unstable-doc
- run: cargo test --doc --features=unstable-doc

View file

@ -257,5 +257,6 @@ no_op_fold!(syn::Token![let]);
no_op_fold!(syn::Token![mut]);
no_op_fold!(syn::Token![static]);
no_op_fold!(syn::Token![struct]);
no_op_fold!(syn::Token![type]);
no_op_fold!(syn::Token![where]);
no_op_fold!(usize);

View file

@ -3,8 +3,9 @@
use crate::{
Errors, HdlAttr, PairsIterExt,
hdl_type_common::{
ItemOptions, MakeHdlTypeExpr, MaybeParsed, ParsedField, ParsedFieldsNamed, ParsedGenerics,
SplitForImpl, TypesParser, WrappedInConst, common_derives, get_target,
CustomDebugOptions, CustomDebugTrait, ItemOptions, MakeHdlTypeExpr, MaybeParsed,
ParsedField, ParsedFieldsNamed, ParsedGenerics, SplitForImpl, TypesParser, WrappedInConst,
common_derives, create_struct_debug_impl, get_target,
},
kw,
};
@ -30,6 +31,7 @@ pub(crate) struct ParsedBundle {
pub(crate) fields: MaybeParsed<ParsedFieldsNamed, FieldsNamed>,
pub(crate) field_flips: Vec<Option<HdlAttr<kw::flip, kw::hdl>>>,
pub(crate) mask_type_ident: Ident,
pub(crate) mask_type_name: String,
pub(crate) mask_type_match_variant_ident: Ident,
pub(crate) mask_type_sim_value_ident: Ident,
pub(crate) match_variant_ident: Ident,
@ -88,6 +90,8 @@ impl ParsedBundle {
no_runtime_generics: _,
cmp_eq: _,
ref get,
custom_debug: _,
custom_sim_display: _,
} = options.body;
if let Some((get, ..)) = get {
errors.error(get, "#[hdl(get(...))] is not allowed on structs");
@ -131,6 +135,7 @@ impl ParsedBundle {
fields,
field_flips,
mask_type_ident: format_ident!("__{}__MaskType", ident),
mask_type_name: format!("MaskType<{}>", ident),
mask_type_match_variant_ident: format_ident!("__{}__MaskType__MatchVariant", ident),
mask_type_sim_value_ident: format_ident!("__{}__MaskType__SimValue", ident),
match_variant_ident: format_ident!("__{}__MatchVariant", ident),
@ -448,6 +453,7 @@ impl ToTokens for ParsedBundle {
fields,
field_flips,
mask_type_ident,
mask_type_name,
mask_type_match_variant_ident,
mask_type_sim_value_ident,
match_variant_ident,
@ -464,11 +470,20 @@ impl ToTokens for ParsedBundle {
no_runtime_generics,
cmp_eq,
get: _,
custom_debug: _,
custom_sim_display,
} = &options.body;
let CustomDebugOptions {
type_: custom_debug_type,
sim: custom_debug_sim,
mask_type: custom_debug_mask_type,
mask_sim: custom_debug_mask_sim,
} = options.body.custom_debug();
let target = get_target(target, ident);
let struct_name = ident.to_string();
let mut item_attrs = attrs.clone();
item_attrs.push(common_derives(span));
ItemStruct {
item_attrs.push(common_derives(span, false));
let type_struct = ItemStruct {
attrs: item_attrs,
vis: vis.clone(),
struct_token: *struct_token,
@ -476,8 +491,8 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(fields.clone().into()),
semi_token: None,
}
.to_tokens(tokens);
};
type_struct.to_tokens(tokens);
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
if let (MaybeParsed::Parsed(generics), MaybeParsed::Parsed(fields), None) =
(generics, fields, no_runtime_generics)
@ -503,6 +518,9 @@ impl ToTokens for ParsedBundle {
}
let mut wrapped_in_const = WrappedInConst::new(tokens, span);
let tokens = wrapped_in_const.inner();
if custom_debug_type.is_none() {
create_struct_debug_impl(&type_struct, &struct_name, None).to_tokens(tokens);
}
let builder = Builder {
vis: vis.clone(),
struct_token: *struct_token,
@ -530,9 +548,9 @@ impl ToTokens for ParsedBundle {
mask_type_builder.to_tokens(tokens);
let unfilled_mask_type_builder_ty =
mask_type_builder.builder_struct_ty(|_| BuilderFieldState::Unfilled);
ItemStruct {
let mask_type_struct = ItemStruct {
attrs: vec![
common_derives(span),
common_derives(span, false),
parse_quote_spanned! {span=>
#[allow(non_camel_case_types, dead_code)]
},
@ -543,17 +561,20 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(mask_type_fields.clone()),
semi_token: None,
};
mask_type_struct.to_tokens(tokens);
if custom_debug_mask_type.is_none() {
create_struct_debug_impl(&mask_type_struct, mask_type_name, None).to_tokens(tokens);
}
.to_tokens(tokens);
let mut mask_type_match_variant_fields = mask_type_fields.clone();
for Field { ty, .. } in &mut mask_type_match_variant_fields.named {
*ty = parse_quote_spanned! {span=>
::fayalite::expr::Expr<#ty>
};
}
ItemStruct {
let mask_type_match_variant_struct = ItemStruct {
attrs: vec![
common_derives(span),
common_derives(span, false),
parse_quote_spanned! {span=>
#[allow(non_camel_case_types, dead_code)]
},
@ -564,17 +585,19 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(mask_type_match_variant_fields),
semi_token: None,
}
.to_tokens(tokens);
};
mask_type_match_variant_struct.to_tokens(tokens);
create_struct_debug_impl(&mask_type_match_variant_struct, mask_type_name, None)
.to_tokens(tokens);
let mut match_variant_fields = FieldsNamed::from(fields.clone());
for Field { ty, .. } in &mut match_variant_fields.named {
*ty = parse_quote_spanned! {span=>
::fayalite::expr::Expr<#ty>
};
}
ItemStruct {
let match_variant_struct = ItemStruct {
attrs: vec![
common_derives(span),
common_derives(span, false),
parse_quote_spanned! {span=>
#[allow(non_camel_case_types, dead_code)]
},
@ -585,19 +608,19 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(match_variant_fields),
semi_token: None,
}
.to_tokens(tokens);
};
match_variant_struct.to_tokens(tokens);
create_struct_debug_impl(&match_variant_struct, &struct_name, None).to_tokens(tokens);
let mut mask_type_sim_value_fields = mask_type_fields;
for Field { ty, .. } in &mut mask_type_sim_value_fields.named {
*ty = parse_quote_spanned! {span=>
::fayalite::sim::value::SimValue<#ty>
};
}
ItemStruct {
let mask_type_sim_value_struct = ItemStruct {
attrs: vec![
parse_quote_spanned! {span=>
#[::fayalite::__std::prelude::v1::derive(
::fayalite::__std::fmt::Debug,
::fayalite::__std::clone::Clone,
)]
},
@ -611,19 +634,34 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(mask_type_sim_value_fields),
semi_token: None,
};
mask_type_sim_value_struct.to_tokens(tokens);
if custom_debug_mask_sim.is_none() {
create_struct_debug_impl(
&mask_type_struct,
mask_type_name,
Some(CustomDebugTrait {
trait_path: &parse_quote_spanned! {span=>
::fayalite::ty::SimValueDebug
},
fn_name: &format_ident!("sim_value_debug", span = span),
this_arg: &parse_quote_spanned! {span=>
value: &<Self as ::fayalite::ty::Type>::SimValue
},
}),
)
.to_tokens(tokens);
}
.to_tokens(tokens);
let mut sim_value_fields = FieldsNamed::from(fields.clone());
for Field { ty, .. } in &mut sim_value_fields.named {
*ty = parse_quote_spanned! {span=>
::fayalite::sim::value::SimValue<#ty>
};
}
ItemStruct {
let sim_value_struct = ItemStruct {
attrs: vec![
parse_quote_spanned! {span=>
#[::fayalite::__std::prelude::v1::derive(
::fayalite::__std::fmt::Debug,
::fayalite::__std::clone::Clone,
)]
},
@ -637,8 +675,36 @@ impl ToTokens for ParsedBundle {
generics: generics.into(),
fields: Fields::Named(sim_value_fields),
semi_token: None,
};
sim_value_struct.to_tokens(tokens);
if custom_debug_sim.is_none() {
create_struct_debug_impl(
&type_struct,
&struct_name,
Some(CustomDebugTrait {
trait_path: &parse_quote_spanned! {span=>
::fayalite::ty::SimValueDebug
},
fn_name: &format_ident!("sim_value_debug", span = span),
this_arg: &parse_quote_spanned! {span=>
value: &<Self as ::fayalite::ty::Type>::SimValue
},
}),
)
.to_tokens(tokens);
}
if custom_sim_display.is_some() {
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::fayalite::__std::fmt::Display for #sim_value_ident #type_generics
#where_clause
{
fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
<#target #type_generics as ::fayalite::ty::SimValueDisplay>::sim_value_display(self, f)
}
}
}.to_tokens(tokens);
}
.to_tokens(tokens);
let this_token = Ident::new("__this", span);
let fields_token = Ident::new("__fields", span);
let self_token = Token![self](span);
@ -820,6 +886,14 @@ impl ToTokens for ParsedBundle {
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::__std::fmt::Debug for #mask_type_sim_value_ident #type_generics
#where_clause
{
fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
<#mask_type_ident #type_generics as ::fayalite::ty::SimValueDebug>::sim_value_debug(self, f)
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::expr::ValueType for #mask_type_sim_value_ident #type_generics
#where_clause
{
@ -980,6 +1054,14 @@ impl ToTokens for ParsedBundle {
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::__std::fmt::Debug for #sim_value_ident #type_generics
#where_clause
{
fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
<#target #type_generics as ::fayalite::ty::SimValueDebug>::sim_value_debug(self, f)
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::expr::ValueType for #sim_value_ident #type_generics
#where_clause
{
@ -1141,7 +1223,7 @@ impl ToTokens for ParsedBundle {
valueless_eq_body = quote_spanned! {span=>
let __lhs = ::fayalite::expr::ValueType::ty(&__lhs);
let __rhs = ::fayalite::expr::ValueType::ty(&__rhs);
#(#fields_valueless_eq)|*
#(#fields_valueless_eq)&*
};
valueless_ne_body = quote_spanned! {span=>
let __lhs = ::fayalite::expr::ValueType::ty(&__lhs);

View file

@ -3,8 +3,9 @@
use crate::{
Errors, HdlAttr, PairsIterExt,
hdl_type_common::{
ItemOptions, MakeHdlTypeExpr, MaybeParsed, ParsedGenerics, ParsedType, SplitForImpl,
TypesParser, WrappedInConst, common_derives, get_target,
CustomDebugOptions, ItemOptions, MakeHdlTypeExpr, MaybeParsed, ParsedGenerics, ParsedType,
SplitForImpl, TypesParser, WrappedInConst, common_derives, create_struct_debug_impl,
get_target,
},
kw,
};
@ -158,15 +159,32 @@ impl ParsedEnum {
custom_bounds,
no_static: _,
no_runtime_generics: _,
cmp_eq,
cmp_eq: _,
ref get,
custom_debug: _,
custom_sim_display: _,
} = options.body;
if let Some((cmp_eq,)) = cmp_eq {
errors.error(cmp_eq, "#[hdl(cmp_eq)] is not yet implemented for enums");
}
if let Some((get, ..)) = get {
errors.error(get, "#[hdl(get(...))] is not allowed on enums");
}
let CustomDebugOptions {
type_: _,
sim: _,
mask_type,
mask_sim,
} = options.body.custom_debug();
if let Some((mask_type,)) = mask_type {
errors.error(
mask_type,
"#[hdl(custom_debug(mask_type)] is not allowed on enums",
);
}
if let Some((mask_sim,)) = mask_sim {
errors.error(
mask_sim,
"#[hdl(custom_debug(mask_sim)] is not allowed on enums",
);
}
attrs.retain(|attr| {
if attr.path().is_ident("repr") {
errors.error(attr, "#[repr] is not supported on #[hdl] enums");
@ -228,12 +246,21 @@ impl ToTokens for ParsedEnum {
custom_bounds: _,
no_static,
no_runtime_generics,
cmp_eq: _, // TODO: implement cmp_eq for enums
cmp_eq,
get: _,
custom_debug: _,
custom_sim_display,
} = &options.body;
let CustomDebugOptions {
type_: custom_debug_type,
sim: custom_debug_sim,
mask_type: _,
mask_sim: _,
} = options.body.custom_debug();
let target = get_target(target, ident);
let enum_name = ident.to_string();
let mut struct_attrs = attrs.clone();
struct_attrs.push(common_derives(span));
struct_attrs.push(common_derives(span, false));
struct_attrs.push(parse_quote_spanned! {span=>
#[allow(non_snake_case)]
});
@ -273,7 +300,7 @@ impl ToTokens for ParsedEnum {
}
},
));
ItemStruct {
let type_struct = ItemStruct {
attrs: struct_attrs,
vis: vis.clone(),
struct_token: Token![struct](enum_token.span),
@ -288,8 +315,8 @@ impl ToTokens for ParsedEnum {
})
},
semi_token: None,
}
.to_tokens(tokens);
};
type_struct.to_tokens(tokens);
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
if let (MaybeParsed::Parsed(generics), None) = (generics, no_runtime_generics) {
generics.make_runtime_generics(tokens, vis, ident, &target, |context| {
@ -373,6 +400,9 @@ impl ToTokens for ParsedEnum {
}
.to_tokens(tokens);
}
if custom_debug_type.is_none() {
create_struct_debug_impl(&type_struct, &enum_name, None).to_tokens(tokens);
}
let mut enum_attrs = attrs.clone();
enum_attrs.push(parse_quote_spanned! {span=>
#[allow(dead_code, non_camel_case_types)]
@ -453,7 +483,6 @@ impl ToTokens for ParsedEnum {
let mut enum_attrs = attrs.clone();
enum_attrs.push(parse_quote_spanned! {span=>
#[::fayalite::__std::prelude::v1::derive(
::fayalite::__std::fmt::Debug,
::fayalite::__std::clone::Clone,
)]
});
@ -838,6 +867,240 @@ impl ToTokens for ParsedEnum {
},
)),
);
if custom_debug_sim.is_none() {
let debug_match_arms = Vec::from_iter(
variants
.iter()
.map(
|ParsedVariant {
attrs: _,
options: _,
ident,
field,
}| {
let variant_name = ident.to_string();
if let Some(_) = field {
quote_spanned! {span=>
#sim_value_ident::#ident(field, _) => {
f.debug_tuple(#variant_name).field(field).finish()
}
}
} else {
quote_spanned! {span=>
#sim_value_ident::#ident(_) => {
f.write_str(#variant_name)
}
}
}
},
)
.chain(sim_value_unknown_variant_name.as_ref().map(
|sim_value_unknown_variant_name| {
let sim_value_unknown_variant_name_str =
sim_value_unknown_variant_name.to_string();
quote_spanned! {span=>
#sim_value_ident::#sim_value_unknown_variant_name(_) => {
f.write_str(#sim_value_unknown_variant_name_str)
}
}
},
)),
);
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::fayalite::ty::SimValueDebug for #target #type_generics
#where_clause
{
fn sim_value_debug(
value: &<Self as ::fayalite::ty::Type>::SimValue,
f: &mut ::fayalite::__std::fmt::Formatter<'_>,
) -> ::fayalite::__std::fmt::Result {
match value {
#(#debug_match_arms)*
}
}
}
}
.to_tokens(tokens);
}
if custom_sim_display.is_some() {
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::fayalite::__std::fmt::Display for #sim_value_ident #type_generics
#where_clause
{
fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
<#target #type_generics as ::fayalite::ty::SimValueDisplay>::sim_value_display(self, f)
}
}
}.to_tokens(tokens);
}
if let Some((cmp_eq,)) = cmp_eq {
let mut cmp_eq_where_clause =
Generics::from(generics)
.where_clause
.unwrap_or_else(|| syn::WhereClause {
where_token: Token![where](span),
predicates: Punctuated::new(),
});
let mut variants_value_eq = vec![];
let mut variants_expr_eq = vec![];
let mut fields_valueless_eq = vec![];
for (
variant_index,
ParsedVariant {
attrs: _,
options: variant_options,
ident: variant_ident,
field,
},
) in variants.iter().enumerate()
{
let VariantOptions {} = variant_options.body;
if let Some(ParsedVariantField {
paren_token: _,
attrs: _,
options: field_options,
ty: field_ty,
comma_token: _,
}) = field
{
let FieldOptions {} = field_options.body;
cmp_eq_where_clause
.predicates
.push(parse_quote_spanned! {cmp_eq.span=>
#field_ty: ::fayalite::expr::HdlPartialEqImpl<#field_ty>
});
variants_value_eq.push(quote_spanned! {span=>
(#sim_value_ident::#variant_ident(__lhs_field, _), #sim_value_ident::#variant_ident(__rhs_field, _)) => {
::fayalite::expr::HdlPartialEqImpl::cmp_value_eq(
__lhs.#variant_ident,
::fayalite::__std::borrow::Cow::Borrowed(__lhs_field),
__rhs.#variant_ident,
::fayalite::__std::borrow::Cow::Borrowed(__rhs_field),
)
}
});
variants_expr_eq.push(quote_spanned! {span=>
{
let (#match_variant_ident::#variant_ident(__lhs), __scope) =
::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope(
::fayalite::__std::iter::Iterator::next(&mut __lhs_match_variant_iter)
.expect("known to have enough variants"),
)
else {
::fayalite::__std::unreachable!();
};
let (#match_variant_ident::#variant_ident(__rhs), __scope) =
::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope(
::fayalite::__std::iter::Iterator::nth(
&mut ::fayalite::module::match_(__rhs),
#variant_index,
)
.expect("known to have variant"),
)
else {
::fayalite::__std::unreachable!();
};
::fayalite::module::connect(__retval, ::fayalite::expr::HdlPartialEqImpl::cmp_expr_eq(__lhs, __rhs));
}
});
fields_valueless_eq.push(quote_spanned! {span=>
::fayalite::expr::HdlPartialEqImpl::cmp_valueless_eq(
::fayalite::expr::Valueless::new(__lhs.#variant_ident),
::fayalite::expr::Valueless::new(__rhs.#variant_ident),
)
});
} else {
variants_value_eq.push(quote_spanned! {span=>
(#sim_value_ident::#variant_ident(_), #sim_value_ident::#variant_ident(_)) => true,
});
variants_expr_eq.push(quote_spanned! {span=>
{
let (#match_variant_ident::#variant_ident, __scope) =
::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope(
::fayalite::__std::iter::Iterator::next(&mut __lhs_match_variant_iter)
.expect("known to have enough variants"),
)
else {
::fayalite::__std::unreachable!();
};
let (#match_variant_ident::#variant_ident, __scope) =
::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope(
::fayalite::__std::iter::Iterator::nth(
&mut ::fayalite::module::match_(__rhs),
#variant_index,
)
.expect("known to have variant"),
)
else {
::fayalite::__std::unreachable!();
};
::fayalite::module::connect(__retval, true);
}
});
}
}
if let Some(sim_value_unknown_variant_name) = &sim_value_unknown_variant_name {
variants_value_eq.push(quote_spanned! {span=>
(#sim_value_ident::#sim_value_unknown_variant_name(__lhs_unknown), #sim_value_ident::#sim_value_unknown_variant_name(__rhs_unknown)) => {
__lhs_unknown == __rhs_unknown
}
});
}
let valueless_eq_body = if fields_valueless_eq.is_empty() {
quote_spanned! {span=>
::fayalite::expr::Valueless::new(::fayalite::int::Bool)
}
} else {
quote_spanned! {span=>
let __lhs = ::fayalite::expr::ValueType::ty(&__lhs);
let __rhs = ::fayalite::expr::ValueType::ty(&__rhs);
#(#fields_valueless_eq)&*
}
};
let cmp_expr_eq_wire_name = format!("{ident}_cmp_eq");
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::fayalite::expr::HdlPartialEqImpl<Self> for #target #type_generics
#cmp_eq_where_clause
{
#[track_caller]
fn cmp_value_eq(
__lhs: Self,
__lhs_value: ::fayalite::__std::borrow::Cow<'_, <Self as ::fayalite::ty::Type>::SimValue>,
__rhs: Self,
__rhs_value: ::fayalite::__std::borrow::Cow<'_, <Self as ::fayalite::ty::Type>::SimValue>,
) -> ::fayalite::__std::primitive::bool {
match (&*__lhs_value, &*__rhs_value) {
#(#variants_value_eq)*
_ => false,
}
}
#[track_caller]
fn cmp_expr_eq(
__lhs: ::fayalite::expr::Expr<Self>,
__rhs: ::fayalite::expr::Expr<Self>,
) -> ::fayalite::expr::Expr<::fayalite::int::Bool> {
let __retval = ::fayalite::module::wire(::fayalite::module::ImplicitName(#cmp_expr_eq_wire_name), ::fayalite::int::Bool);
::fayalite::module::connect(__retval, false);
let mut __lhs_match_variant_iter = ::fayalite::module::match_(__lhs);
#(#variants_expr_eq)*
__retval
}
#[track_caller]
fn cmp_valueless_eq(
__lhs: ::fayalite::expr::Valueless<Self>,
__rhs: ::fayalite::expr::Valueless<Self>,
) -> ::fayalite::expr::Valueless<::fayalite::int::Bool> {
#valueless_eq_body
}
}
}
.to_tokens(tokens);
}
let variants_len = variants.len();
quote_spanned! {span=>
#[automatically_derived]
@ -934,6 +1197,14 @@ impl ToTokens for ParsedEnum {
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::__std::fmt::Debug for #sim_value_ident #type_generics
#where_clause
{
fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
<#target #type_generics as ::fayalite::ty::SimValueDebug>::sim_value_debug(self, f)
}
}
#[automatically_derived]
impl #impl_generics ::fayalite::sim::value::ToSimValueWithType<#target #type_generics>
for #sim_value_ident #type_generics
#where_clause

View file

@ -215,6 +215,8 @@ impl ParsedTypeAlias {
no_runtime_generics,
cmp_eq,
get: _,
ref custom_debug,
custom_sim_display,
} = options.body;
if let Some((no_static,)) = no_static {
errors.error(no_static, "no_static is not valid on type aliases");
@ -234,6 +236,15 @@ impl ParsedTypeAlias {
if let Some((cmp_eq,)) = cmp_eq {
errors.error(cmp_eq, "cmp_eq is not valid on type aliases");
}
if let Some((custom_debug, _, _)) = custom_debug {
errors.error(custom_debug, "custom_debug is not valid on type aliases");
}
if let Some((custom_sim_display,)) = custom_sim_display {
errors.error(
custom_sim_display,
"custom_sim_display is not valid on type aliases",
);
}
if let Some((custom_bounds,)) = custom_bounds {
errors.error(
custom_bounds,
@ -287,6 +298,8 @@ impl ParsedTypeAlias {
no_runtime_generics: _,
cmp_eq,
ref mut get,
ref custom_debug,
custom_sim_display,
} = options.body;
if let Some(get) = get.take() {
return Self::parse_phantom_const_accessor(
@ -311,6 +324,15 @@ impl ParsedTypeAlias {
if let Some((cmp_eq,)) = cmp_eq {
errors.error(cmp_eq, "cmp_eq is not valid on type aliases");
}
if let Some((custom_debug, _, _)) = custom_debug {
errors.error(custom_debug, "custom_debug is not valid on type aliases");
}
if let Some((custom_sim_display,)) = custom_sim_display {
errors.error(
custom_sim_display,
"custom_sim_display is not valid on type aliases",
);
}
let generics = if custom_bounds.is_some() {
MaybeParsed::Unrecognized(generics)
} else if let Some(generics) = errors.ok(ParsedGenerics::parse(&mut generics)) {
@ -356,6 +378,8 @@ impl ToTokens for ParsedTypeAlias {
no_runtime_generics,
cmp_eq: _,
get: _,
custom_debug: _,
custom_sim_display: _,
} = &options.body;
let target = get_target(target, ident);
let mut type_attrs = attrs.clone();
@ -402,6 +426,8 @@ impl ToTokens for ParsedTypeAlias {
no_runtime_generics: _,
cmp_eq: _,
get: _,
custom_debug: _,
custom_sim_display: _,
} = &options.body;
let span = ident.span();
let mut type_attrs = attrs.clone();
@ -427,7 +453,7 @@ impl ToTokens for ParsedTypeAlias {
format_ident!("__{}__GenericsAccumulation", ident);
ItemStruct {
attrs: vec![
common_derives(span),
common_derives(span, true),
parse_quote_spanned! {span=>
#[allow(non_camel_case_types)]
},

View file

@ -7,10 +7,10 @@ use std::{collections::HashMap, fmt, mem};
use syn::{
AngleBracketedGenericArguments, Attribute, Block, ConstParam, Expr, ExprBlock, ExprGroup,
ExprIndex, ExprParen, ExprPath, ExprTuple, Field, FieldMutability, Fields, FieldsNamed,
FieldsUnnamed, GenericArgument, GenericParam, Generics, Ident, ImplGenerics, Index, ItemStruct,
Path, PathArguments, PathSegment, PredicateType, QSelf, Stmt, Token, TraitBound, Turbofish,
Type, TypeGenerics, TypeGroup, TypeParam, TypeParamBound, TypeParen, TypePath, TypeTuple,
Visibility, WhereClause, WherePredicate,
FieldsUnnamed, FnArg, GenericArgument, GenericParam, Generics, Ident, ImplGenerics, Index,
ItemStruct, Path, PathArguments, PathSegment, PredicateType, QSelf, Stmt, Token, TraitBound,
Turbofish, Type, TypeGenerics, TypeGroup, TypeParam, TypeParamBound, TypeParen, TypePath,
TypeTuple, Visibility, WhereClause, WherePredicate,
parse::{Parse, ParseStream},
parse_quote, parse_quote_spanned,
punctuated::{Pair, Punctuated},
@ -18,6 +18,17 @@ use syn::{
token::{Brace, Bracket, Paren},
};
crate::options! {
#[options = CustomDebugOptions]
#[no_ident_fragment]
pub(crate) enum CustomDebugOption {
Type(type_),
Sim(sim),
MaskType(mask_type),
MaskSim(mask_sim),
}
}
crate::options! {
#[options = ItemOptions]
pub(crate) enum ItemOption {
@ -28,6 +39,8 @@ crate::options! {
NoRuntimeGenerics(no_runtime_generics),
CmpEq(cmp_eq),
Get(get, Expr),
CustomDebug(custom_debug, CustomDebugOptions),
CustomSimDisplay(custom_sim_display),
}
}
@ -41,8 +54,36 @@ impl ItemOptions {
{
self.no_static = Some((kw::no_static(custom_bounds.span),));
}
if let Some((kw, _, custom_debug)) = &mut self.custom_debug {
if let CustomDebugOptions {
type_: None,
sim: None,
mask_type: None,
mask_sim: None,
} = custom_debug
{
*custom_debug = CustomDebugOptions {
type_: Some((kw::type_(kw.span),)),
sim: Some((kw::sim(kw.span),)),
mask_type: None,
mask_sim: None,
};
}
}
Ok(())
}
pub(crate) fn custom_debug(&self) -> &CustomDebugOptions {
self.custom_debug.as_ref().map(|v| &v.2).unwrap_or(
const {
&CustomDebugOptions {
type_: None,
sim: None,
mask_type: None,
mask_sim: None,
}
},
)
}
}
pub(crate) struct WrappedInConst<'a> {
@ -84,10 +125,17 @@ pub(crate) fn get_target(target: &Option<(kw::target, Paren, Path)>, item_ident:
}
}
pub(crate) fn common_derives(span: Span) -> Attribute {
pub(crate) fn common_derives(span: Span, include_debug: bool) -> Attribute {
let debug = include_debug
.then(|| {
quote_spanned! {span=>
::fayalite::__std::fmt::Debug
}
})
.into_iter();
parse_quote_spanned! {span=>
#[::fayalite::__std::prelude::v1::derive(
::fayalite::__std::fmt::Debug,
#(#debug,)*
::fayalite::__std::cmp::Eq,
::fayalite::__std::cmp::PartialEq,
::fayalite::__std::hash::Hash,
@ -2975,7 +3023,7 @@ impl ParsedGenerics {
let span = ident.span();
ItemStruct {
attrs: vec![
common_derives(span),
common_derives(span, true),
parse_quote_spanned! {span=>
#[allow(non_camel_case_types)]
},
@ -4733,3 +4781,109 @@ impl ParsedVisibility {
.map(|ord| if ord.is_lt() { self } else { other })
}
}
pub(crate) struct CustomDebugTrait<'a> {
pub(crate) trait_path: &'a Path,
pub(crate) fn_name: &'a Ident,
pub(crate) this_arg: &'a FnArg,
}
#[must_use]
pub(crate) fn create_struct_debug_impl(
item_struct: &ItemStruct,
debug_struct_name: &str,
custom_debug_trait: Option<CustomDebugTrait<'_>>,
) -> TokenStream {
let ident = &item_struct.ident;
let span = ident.span();
let (impl_generics, type_generics, where_clause) = item_struct.generics.split_for_impl();
let trait_path;
let fn_name;
let this_arg;
let CustomDebugTrait {
trait_path,
fn_name,
this_arg,
} = match custom_debug_trait {
Some(v) => v,
None => {
trait_path = parse_quote_spanned! {span=>
::fayalite::__std::fmt::Debug
};
fn_name = parse_quote_spanned! {span=>
fmt
};
this_arg = parse_quote_spanned! {span=>
&self
};
CustomDebugTrait {
trait_path: &trait_path,
fn_name: &fn_name,
this_arg: &this_arg,
}
}
};
let this_arg_name = match this_arg {
FnArg::Receiver(this_arg) => this_arg.self_token.to_token_stream(),
FnArg::Typed(this_arg) => match &*this_arg.pat {
syn::Pat::Ident(pat_ident) => pat_ident.ident.to_token_stream(),
_ => unreachable!(),
},
};
match &item_struct.fields {
Fields::Named(fields) => {
let field_idents = fields
.named
.iter()
.map(|v| v.ident.as_ref().expect("known to have field name"));
let field_names = field_idents.clone().map(|v| v.to_string());
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics #trait_path for #ident #type_generics
#where_clause
{
fn #fn_name(#this_arg, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
let _ = #this_arg_name;
f.debug_struct(#debug_struct_name)
#(.field(#field_names, &#this_arg_name.#field_idents))*
.finish()
}
}
}
}
Fields::Unnamed(fields) => {
let field_members = fields
.unnamed
.iter()
.enumerate()
.map(|(index, _)| syn::Index {
index: index as _,
span,
});
quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics #trait_path for #ident #type_generics
#where_clause
{
fn #fn_name(#this_arg, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
let _ = #this_arg_name;
f.debug_tuple(#debug_struct_name)
#(.field(&#this_arg_name.#field_members))*
.finish()
}
}
}
}
Fields::Unit => quote_spanned! {ident.span()=>
#[automatically_derived]
impl #impl_generics #trait_path for #ident #type_generics
#where_clause
{
fn #fn_name(#this_arg, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result {
let _ = #this_arg_name;
f.write_str(#debug_struct_name)
}
}
},
}
}

View file

@ -42,6 +42,7 @@ pub(crate) trait CustomToken:
mod kw {
pub(crate) use syn::token::Extern as extern_;
pub(crate) use syn::token::Type as type_;
macro_rules! custom_keyword {
($kw:ident) => {
@ -75,6 +76,8 @@ mod kw {
custom_keyword!(cmp_eq);
custom_keyword!(connect_inexact);
custom_keyword!(custom_bounds);
custom_keyword!(custom_debug);
custom_keyword!(custom_sim_display);
custom_keyword!(flip);
custom_keyword!(get);
custom_keyword!(hdl);
@ -83,6 +86,8 @@ mod kw {
custom_keyword!(input);
custom_keyword!(instance);
custom_keyword!(m);
custom_keyword!(mask_sim);
custom_keyword!(mask_type);
custom_keyword!(memory);
custom_keyword!(memory_array);
custom_keyword!(memory_with_init);

View file

@ -1096,11 +1096,9 @@ impl Visitor<'_> {
let (#(#bindings,)*) = {
type __MatchTy<T> = <T as ::fayalite::ty::Type>::SimValue;
let __match_value = #expr;
let __match_value = {
use ::fayalite::sim::value::match_sim_value::*;
// use method syntax to deduce the correct trait to call
::fayalite::sim::value::match_sim_value::MatchSimValueHelper::new(__match_value).__fayalite_match_sim_value()
};
// use method syntax to deduce what type to convert to
let __match_value = ::fayalite::sim::value::match_sim_value::MatchSimValueHelper::new(__match_value)
.__fayalite_match_sim_value();
#let_token #pat #eq_token __match_value #semi_token
(#(#bindings_idents,)*)
};
@ -1172,11 +1170,9 @@ impl Visitor<'_> {
{
type __MatchTy<T> = <T as ::fayalite::ty::Type>::SimValue;
let __match_value = #expr;
let __match_value = {
use ::fayalite::sim::value::match_sim_value::*;
// use method syntax to deduce the correct trait to call
::fayalite::sim::value::match_sim_value::MatchSimValueHelper::new(__match_value).__fayalite_match_sim_value()
};
// use method syntax to deduce what type to convert to
let __match_value = ::fayalite::sim::value::match_sim_value::MatchSimValueHelper::new(__match_value)
.__fayalite_match_sim_value();
#match_token __match_value {
#(#arms)*
}

View file

@ -95,7 +95,23 @@
//! }
//!
//! #[hdl]
//! fn destructure_to_sim_value<'a, T: Type>(v: impl ToSimValue<Type = MyStruct<T>>) {
//! fn destructure_inner<T: Type>(v: <MyStruct<T> as Type>::SimValue) {
//! #[hdl(sim)]
//! let MyStruct::<T> {
//! a,
//! mut b,
//! c,
//! } = v;
//!
//! // that gives these types:
//! let _: SimValue<UInt<8>> = a;
//! let _: SimValue<Bool> = b;
//! let _: SimValue<T> = c;
//! *b = false; // can modify b since mut was used
//! }
//!
//! #[hdl]
//! fn destructure_inner_ref<'a, T: Type>(v: &'a <MyStruct<T> as Type>::SimValue) {
//! #[hdl(sim)]
//! let MyStruct::<T> {
//! a,
@ -104,8 +120,25 @@
//! } = v;
//!
//! // that gives these types:
//! let _: SimValue<UInt<8>> = a;
//! let _: SimValue<Bool> = b;
//! let _: SimValue<T> = c;
//! let _: &'a SimValue<UInt<8>> = a;
//! let _: &'a SimValue<Bool> = b;
//! let _: &'a SimValue<T> = c;
//! }
//!
//! #[hdl]
//! fn destructure_inner_mut<'a, T: Type>(v: &'a mut <MyStruct<T> as Type>::SimValue) {
//! #[hdl(sim)]
//! let MyStruct::<T> {
//! a,
//! b,
//! c,
//! } = v;
//!
//! **b = true; // you can modify v by modifying b which borrows from it
//!
//! // that gives these types:
//! let _: &'a mut SimValue<UInt<8>> = a;
//! let _: &'a mut SimValue<Bool> = b;
//! let _: &'a mut SimValue<T> = c;
//! }
//! ```

View file

@ -72,15 +72,47 @@
//! }
//!
//! #[hdl]
//! fn match_to_sim_value<'a, T: Type>(v: impl ToSimValue<Type = MyEnum<T>>) {
//! fn match_inner_move<T: Type>(v: <MyEnum<T> as Type>::SimValue) -> String {
//! #[hdl(sim)]
//! match v {
//! MyEnum::<T>::A => println!("got A"),
//! MyEnum::<T>::B(b) => {
//! MyEnum::<T>::A => String::from("got A"),
//! MyEnum::<T>::B(mut b) => {
//! let _: SimValue<Bool> = b; // b has this type
//! println!("got B({b})");
//! let text = format!("got B({b})");
//! *b = true; // can modify b since mut was used
//! text
//! }
//! _ => println!("something else"),
//! _ => String::from("something else"),
//! }
//! }
//!
//! #[hdl]
//! fn match_inner_ref<'a, T: Type>(v: &'a <MyEnum<T> as Type>::SimValue) -> u32 {
//! #[hdl(sim)]
//! match v {
//! MyEnum::<T>::A => 1,
//! MyEnum::<T>::B(b) => {
//! let _: &'a SimValue<Bool> = b; // b has this type
//! println!("got B({b})");
//! 5
//! }
//! _ => 42,
//! }
//! }
//!
//! #[hdl]
//! fn match_inner_mut<'a, T: Type>(v: &'a mut <MyEnum<T> as Type>::SimValue) -> Option<&'a mut SimValue<T>> {
//! #[hdl(sim)]
//! match v {
//! MyEnum::<T>::A => None,
//! MyEnum::<T>::B(b) => {
//! println!("got B({b})");
//! **b = true; // you can modify v by modifying b which borrows from it
//! let _: &'a mut SimValue<Bool> = b; // b has this type
//! None
//! }
//! MyEnum::<T>::C(v) => Some(v), // you can return matched values
//! _ => None, // HDL enums can have invalid discriminants, so we need this extra match arm
//! }
//! }
//! ```

View file

@ -13,13 +13,13 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, MatchVariantWithoutScope, OpaqueSimValueSlice, OpaqueSimValueWriter,
OpaqueSimValueWritten, StaticType, Type, TypeProperties, TypeWithDeref,
OpaqueSimValueWritten, SimValueDebug, StaticType, Type, TypeProperties, TypeWithDeref,
serde_impls::SerdeCanonicalType,
},
util::ConstUsize,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error};
use std::{borrow::Cow, iter::FusedIterator, ops::Index};
use std::{borrow::Cow, fmt, iter::FusedIterator, ops::Index};
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct ArrayType<T: Type = CanonicalType, Len: Size = DynSize> {
@ -28,8 +28,8 @@ pub struct ArrayType<T: Type = CanonicalType, Len: Size = DynSize> {
type_properties: TypeProperties,
}
impl<T: Type, Len: Size> std::fmt::Debug for ArrayType<T, Len> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl<T: Type, Len: Size> fmt::Debug for ArrayType<T, Len> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Array<{:?}, {}>", self.element, self.len())
}
}
@ -182,6 +182,15 @@ impl<T: Type + Visit<State>, Len: Size, State: Visitor + ?Sized> Visit<State>
}
}
impl<T: Type, Len: Size> SimValueDebug for ArrayType<T, Len> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<T: Type, Len: Size> Type for ArrayType<T, Len> {
type BaseType = Array;
type MaskType = ArrayType<T::MaskType, Len>;

View file

@ -14,8 +14,8 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, MatchVariantWithoutScope, OpaqueSimValue, OpaqueSimValueSize,
OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten, StaticType, Type,
TypeProperties, TypeWithDeref, impl_match_variant_as_self,
OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten, SimValueDebug,
StaticType, Type, TypeProperties, TypeWithDeref, impl_match_variant_as_self,
},
util::HashMap,
};
@ -271,6 +271,15 @@ impl Type for Bundle {
}
}
impl SimValueDebug for Bundle {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
pub trait BundleType: Type<BaseType = Bundle> {
type Builder: Default;
fn fields(&self) -> Interned<[BundleField]>;
@ -471,6 +480,14 @@ macro_rules! impl_tuples {
#[var($var)]
})*]
}
impl<$($T: Type,)*> SimValueDebug for ($($T,)*) {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<$($T: Type,)*> Type for ($($T,)*) {
type BaseType = Bundle;
type MaskType = ($($T::MaskType,)*);
@ -773,6 +790,15 @@ impl_tuples! {
]
}
impl<T: ?Sized + Send + Sync + 'static> SimValueDebug for PhantomData<T> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<T: ?Sized + Send + Sync + 'static> Type for PhantomData<T> {
type BaseType = Bundle;
type MaskType = ();

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information
use crate::{
expr::{Expr, ValueType},
hdl,
@ -9,10 +10,12 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, OpaqueSimValueSize, OpaqueSimValueSlice, OpaqueSimValueWriter,
OpaqueSimValueWritten, StaticType, Type, TypeProperties, impl_match_variant_as_self,
OpaqueSimValueWritten, SimValueDebug, StaticType, Type, TypeProperties,
impl_match_variant_as_self,
},
};
use bitvec::{bits, order::Lsb0};
use std::fmt;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct Clock;
@ -69,6 +72,15 @@ impl Type for Clock {
}
}
impl SimValueDebug for Clock {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl Clock {
pub fn type_properties(self) -> TypeProperties {
Self::TYPE_PROPERTIES

View file

@ -2,7 +2,7 @@
// See Notices.txt for copyright information
use crate::{
expr::{Expr, HdlPartialEq, HdlPartialEqImpl, ToExpr, ValueType, ops::VariantAccess},
expr::{Expr, ToExpr, ValueType, ops::VariantAccess},
hdl,
int::{Bool, UIntValue},
intern::{Intern, Interned},
@ -10,18 +10,18 @@ use crate::{
EnumMatchVariantAndInactiveScopeImpl, EnumMatchVariantsIterImpl, Scope, connect,
enum_match_variants_helper, incomplete_wire, wire,
},
sim::value::SimValue,
sim::value::{SimValue, ToSimValue, ToSimValueWithType},
source_location::SourceLocation,
ty::{
CanonicalType, MatchVariantAndInactiveScope, OpaqueSimValue, OpaqueSimValueSize,
OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten, StaticType, Type,
TypeProperties,
OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten, SimValueDebug,
StaticType, Type, TypeProperties,
},
util::HashMap,
};
use bitvec::{order::Lsb0, slice::BitSlice, view::BitView};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, convert::Infallible, fmt, iter::FusedIterator, sync::Arc};
use std::{convert::Infallible, fmt, iter::FusedIterator, sync::Arc};
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub struct EnumVariant {
@ -410,6 +410,15 @@ impl Type for Enum {
}
}
impl SimValueDebug for Enum {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct EnumPaddingSimValue {
bits: Option<UIntValue>,
@ -723,95 +732,12 @@ pub fn enum_type_to_sim_builder<T: EnumType>(v: T) -> T::SimBuilder {
v.into()
}
#[hdl]
#[hdl(cmp_eq)]
pub enum HdlOption<T: Type> {
HdlNone,
HdlSome(T),
}
impl<Lhs: Type + HdlPartialEqImpl<Rhs>, Rhs: Type> HdlPartialEqImpl<HdlOption<Rhs>>
for HdlOption<Lhs>
{
fn cmp_value_eq(
lhs: Self,
lhs_value: Cow<'_, Self::SimValue>,
rhs: HdlOption<Rhs>,
rhs_value: Cow<'_, <HdlOption<Rhs> as Type>::SimValue>,
) -> bool {
type SimValueMatch<T> = <T as Type>::SimValue;
match (&*lhs_value, &*rhs_value) {
(SimValueMatch::<Self>::HdlNone(_), SimValueMatch::<HdlOption<Rhs>>::HdlNone(_)) => {
true
}
(SimValueMatch::<Self>::HdlSome(..), SimValueMatch::<HdlOption<Rhs>>::HdlNone(_))
| (SimValueMatch::<Self>::HdlNone(_), SimValueMatch::<HdlOption<Rhs>>::HdlSome(..)) => {
false
}
(
SimValueMatch::<Self>::HdlSome(l, _),
SimValueMatch::<HdlOption<Rhs>>::HdlSome(r, _),
) => HdlPartialEqImpl::cmp_value_eq(
lhs.HdlSome,
Cow::Borrowed(&**l),
rhs.HdlSome,
Cow::Borrowed(&**r),
),
}
}
#[hdl]
fn cmp_expr_eq(lhs: Expr<Self>, rhs: Expr<HdlOption<Rhs>>) -> Expr<Bool> {
#[hdl]
let cmp_eq = wire();
#[hdl]
match lhs {
HdlSome(lhs) =>
{
#[hdl]
match rhs {
HdlSome(rhs) => connect(cmp_eq, lhs.cmp_eq(rhs)),
HdlNone => connect(cmp_eq, false),
}
}
HdlNone =>
{
#[hdl]
match rhs {
HdlSome(_) => connect(cmp_eq, false),
HdlNone => connect(cmp_eq, true),
}
}
}
cmp_eq
}
#[hdl]
fn cmp_expr_ne(lhs: Expr<Self>, rhs: Expr<HdlOption<Rhs>>) -> Expr<Bool> {
#[hdl]
let cmp_ne = wire();
#[hdl]
match lhs {
HdlSome(lhs) =>
{
#[hdl]
match rhs {
HdlSome(rhs) => connect(cmp_ne, lhs.cmp_ne(rhs)),
HdlNone => connect(cmp_ne, true),
}
}
HdlNone =>
{
#[hdl]
match rhs {
HdlSome(_) => connect(cmp_ne, true),
HdlNone => connect(cmp_ne, false),
}
}
}
cmp_ne
}
}
#[allow(non_snake_case)]
pub fn HdlNone<T: StaticType>() -> Expr<HdlOption<T>> {
HdlOption[T::TYPE].HdlNone()
@ -823,6 +749,123 @@ pub fn HdlSome<T: Type>(value: impl ToExpr<Type = T>) -> Expr<HdlOption<T>> {
HdlOption[value.ty()].HdlSome(value)
}
impl<T: Type> From<SimValue<HdlOption<T>>> for Option<SimValue<T>> {
#[hdl]
fn from(value: SimValue<HdlOption<T>>) -> Self {
#[hdl(sim)]
match value {
HdlSome(v) => Some(v),
HdlNone => None,
}
}
}
impl<'a, T: Type> From<&'a SimValue<HdlOption<T>>> for Option<&'a SimValue<T>> {
#[hdl]
fn from(value: &'a SimValue<HdlOption<T>>) -> Self {
#[hdl(sim)]
match value {
HdlSome(v) => Some(v),
HdlNone => None,
}
}
}
impl<'a, T: Type> From<&'a mut SimValue<HdlOption<T>>> for Option<&'a mut SimValue<T>> {
#[hdl]
fn from(value: &'a mut SimValue<HdlOption<T>>) -> Self {
#[hdl(sim)]
match value {
HdlSome(v) => Some(v),
HdlNone => None,
}
}
}
impl<T: ValueType<Type: StaticType<MaskType: StaticType>>> ValueType for Option<T> {
type Type = HdlOption<T::Type>;
type ValueCategory = T::ValueCategory;
fn ty(&self) -> Self::Type {
StaticType::TYPE
}
}
impl<T: Type, V: ToSimValueWithType<T>> ToSimValueWithType<HdlOption<T>> for Option<V> {
#[hdl]
fn to_sim_value_with_type(&self, ty: HdlOption<T>) -> SimValue<HdlOption<T>> {
match self {
Some(v) =>
{
#[hdl(sim)]
ty.HdlSome(v)
}
None =>
{
#[hdl(sim)]
ty.HdlNone()
}
}
}
#[hdl]
fn into_sim_value_with_type(self, ty: HdlOption<T>) -> SimValue<HdlOption<T>> {
match self {
Some(v) =>
{
#[hdl(sim)]
ty.HdlSome(v)
}
None =>
{
#[hdl(sim)]
ty.HdlNone()
}
}
}
}
impl<T: ToSimValue<Type: StaticType<MaskType: StaticType>>> ToSimValue for Option<T> {
#[hdl]
fn to_sim_value(&self) -> SimValue<Self::Type> {
match self {
Some(v) =>
{
#[hdl(sim)]
HdlSome(v)
}
None =>
{
#[hdl(sim)]
HdlNone()
}
}
}
#[hdl]
fn into_sim_value(self) -> SimValue<Self::Type> {
match self {
Some(v) =>
{
#[hdl(sim)]
HdlSome(v)
}
None =>
{
#[hdl(sim)]
HdlNone()
}
}
}
}
impl<T: ToExpr<Type: StaticType<MaskType: StaticType>>> ToExpr for Option<T> {
fn to_expr(&self) -> Expr<Self::Type> {
match self {
Some(v) => HdlSome(v),
None => HdlNone(),
}
}
}
impl<T: Type> HdlOption<T> {
#[track_caller]
pub fn try_map<R: Type, E>(

View file

@ -17,7 +17,7 @@ use crate::{
reg::Reg,
reset::{AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset},
sim::value::{SimValue, ToSimValue, ToSimValueWithType},
ty::{CanonicalType, OpaqueSimValue, StaticType, Type, TypeWithDeref},
ty::{CanonicalType, OpaqueSimValue, StaticType, TraceAsString, Type, TypeWithDeref},
util::{ConstBool, ConstUsize},
wire::Wire,
};
@ -218,6 +218,8 @@ expr_enum! {
SliceSInt(ops::SliceSInt),
CastToBits(ops::CastToBits),
CastBitsTo(ops::CastBitsTo),
AsTraceAsString(ops::AsTraceAsString),
TraceAsStringAsInner(ops::TraceAsStringAsInner),
ModuleIO(ModuleIO<CanonicalType>),
Instance(Instance<Bundle>),
Wire(Wire<CanonicalType>),
@ -389,6 +391,35 @@ impl<T: Type> Expr<T> {
__flow: this.__flow,
}
}
#[track_caller]
pub fn as_trace_as_string(this: Self, ty: TraceAsString<T>) -> Expr<TraceAsString<T>> {
assert_eq!(this.ty(), ty.inner_ty());
ops::AsTraceAsString::new(Expr::canonical(this), ty).to_expr()
}
}
impl Expr<CanonicalType> {
pub fn unwrap_transparent_types(mut this: Self) -> Expr<CanonicalType> {
loop {
match this.ty() {
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
| CanonicalType::Array(_)
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::AsyncReset(_)
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => return this,
CanonicalType::TraceAsString(_) => {
this = *Expr::<TraceAsString>::from_canonical(this);
}
}
}
}
}
impl<T: Type> ToLiteralBits for Expr<T> {

View file

@ -11,8 +11,9 @@ use crate::{
HdlPartialEqImpl, HdlPartialOrd, HdlPartialOrdImpl, NotALiteralExpr, ReduceBitsImpl,
ToExpr, ToLiteralBits, ToSimValueInner, ToValueless, ValueType, Valueless,
target::{
GetTarget, Target, TargetPathArrayElement, TargetPathBundleField,
TargetPathDynArrayElement, TargetPathElement,
GetTarget, Target, TargetPathArrayElement, TargetPathAsTraceAsString,
TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement,
TargetPathTraceAsStringInner,
},
value_category::ValueCategoryExpr,
},
@ -27,7 +28,7 @@ use crate::{
ToSyncReset,
},
sim::value::{SimValue, ToSimValue},
ty::{CanonicalType, StaticType, Type},
ty::{CanonicalType, StaticType, TraceAsString, Type},
util::ConstUsize,
};
use bitvec::{order::Lsb0, slice::BitSlice, vec::BitVec, view::BitView};
@ -4694,3 +4695,185 @@ impl<This: ExprFromIterator<A>, A> FromIterator<A> for Expr<This> {
This::expr_from_iter(iter)
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct AsTraceAsString<T: Type = CanonicalType> {
inner: Expr<CanonicalType>,
ty: TraceAsString<T>,
literal_bits: Result<Interned<BitSlice>, NotALiteralExpr>,
target: Option<Interned<Target>>,
}
impl<T: Type> fmt::Debug for AsTraceAsString<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
inner,
ty: _,
literal_bits: _,
target: _,
} = self;
f.debug_struct("AsTraceAsString")
.field("inner", inner)
.finish_non_exhaustive()
}
}
impl<T: Type> AsTraceAsString<T> {
pub fn new(inner: Expr<CanonicalType>, ty: TraceAsString<T>) -> Self {
assert_eq!(inner.ty(), ty.inner_ty().canonical());
let literal_bits = inner.to_literal_bits();
let target = inner.target().map(|base| {
Intern::intern_sized(
base.join(TargetPathElement::intern_sized(
TargetPathAsTraceAsString {
ty: ty.canonical_trace_as_string(),
}
.into(),
)),
)
});
Self {
inner,
ty,
literal_bits,
target,
}
}
pub fn inner(self) -> Expr<CanonicalType> {
self.inner
}
}
impl<T: Type> GetTarget for AsTraceAsString<T> {
fn target(&self) -> Option<Interned<Target>> {
self.target
}
}
impl<T: Type> ToLiteralBits for AsTraceAsString<T> {
fn to_literal_bits(&self) -> Result<Interned<BitSlice>, NotALiteralExpr> {
self.literal_bits
}
}
impl<T: Type> ValueType for AsTraceAsString<T> {
type Type = TraceAsString<T>;
type ValueCategory = ValueCategoryExpr;
fn ty(&self) -> Self::Type {
self.ty
}
}
impl<T: Type> ToExpr for AsTraceAsString<T> {
fn to_expr(&self) -> Expr<Self::Type> {
Expr {
__enum: ExprEnum::AsTraceAsString(AsTraceAsString {
inner: self.inner,
ty: self.ty.canonical_trace_as_string(),
literal_bits: self.literal_bits,
target: self.target,
})
.intern(),
__ty: self.ty,
__flow: Expr::flow(self.inner),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct TraceAsStringAsInner<T: Type = CanonicalType> {
arg: Expr<TraceAsString<CanonicalType>>,
ty: T,
literal_bits: Result<Interned<BitSlice>, NotALiteralExpr>,
target: Option<Interned<Target>>,
}
impl<T: Type> fmt::Debug for TraceAsStringAsInner<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
arg,
ty: _,
literal_bits: _,
target: _,
} = self;
f.debug_struct("TraceAsStringAsInner")
.field("arg", arg)
.finish_non_exhaustive()
}
}
impl<T: Type> TraceAsStringAsInner<T> {
pub fn from_arg_and_ty(arg: Expr<TraceAsString<CanonicalType>>, ty: T) -> Self {
assert_eq!(arg.ty().inner_ty(), ty.canonical());
let literal_bits = arg.to_literal_bits();
let target = arg.target().map(|base| {
Intern::intern_sized(base.join(TargetPathElement::intern_sized(
TargetPathTraceAsStringInner {}.into(),
)))
});
Self {
arg,
ty,
literal_bits,
target,
}
}
pub fn new(arg: Expr<TraceAsString<T>>) -> Self {
Self::from_arg_and_ty(
Expr {
__enum: arg.__enum,
__ty: arg.__ty.canonical_trace_as_string(),
__flow: arg.__flow,
},
arg.ty().inner_ty(),
)
}
pub fn arg(self) -> Expr<TraceAsString<CanonicalType>> {
self.arg
}
pub fn arg_typed(self) -> Expr<TraceAsString<T>> {
Expr {
__enum: self.arg.__enum,
__ty: TraceAsString::from_canonical_trace_as_string(self.arg.__ty),
__flow: self.arg.__flow,
}
}
}
impl<T: Type> GetTarget for TraceAsStringAsInner<T> {
fn target(&self) -> Option<Interned<Target>> {
self.target
}
}
impl<T: Type> ToLiteralBits for TraceAsStringAsInner<T> {
fn to_literal_bits(&self) -> Result<Interned<BitSlice>, NotALiteralExpr> {
self.literal_bits
}
}
impl<T: Type> ValueType for TraceAsStringAsInner<T> {
type Type = T;
type ValueCategory = ValueCategoryExpr;
fn ty(&self) -> Self::Type {
self.ty
}
}
impl<T: Type> ToExpr for TraceAsStringAsInner<T> {
fn to_expr(&self) -> Expr<Self::Type> {
Expr {
__enum: ExprEnum::TraceAsStringAsInner(TraceAsStringAsInner {
arg: self.arg,
ty: self.ty.canonical(),
literal_bits: self.literal_bits,
target: self.target,
})
.intern(),
__ty: self.ty,
__flow: Expr::flow(self.arg),
}
}
}

View file

@ -10,7 +10,7 @@ use crate::{
reg::Reg,
reset::{AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset},
source_location::SourceLocation,
ty::{CanonicalType, Type},
ty::{CanonicalType, TraceAsString, Type},
wire::Wire,
};
use std::fmt;
@ -46,11 +46,33 @@ impl fmt::Display for TargetPathDynArrayElement {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TargetPathTraceAsStringInner {}
impl fmt::Display for TargetPathTraceAsStringInner {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, ".<inner>")
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TargetPathAsTraceAsString {
pub ty: TraceAsString<CanonicalType>,
}
impl fmt::Display for TargetPathAsTraceAsString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, ".as_trace_as_string(...)")
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TargetPathElement {
BundleField(TargetPathBundleField),
ArrayElement(TargetPathArrayElement),
DynArrayElement(TargetPathDynArrayElement),
TraceAsStringInner(TargetPathTraceAsStringInner),
AsTraceAsString(TargetPathAsTraceAsString),
}
impl From<TargetPathBundleField> for TargetPathElement {
@ -71,12 +93,26 @@ impl From<TargetPathDynArrayElement> for TargetPathElement {
}
}
impl From<TargetPathTraceAsStringInner> for TargetPathElement {
fn from(value: TargetPathTraceAsStringInner) -> Self {
Self::TraceAsStringInner(value)
}
}
impl From<TargetPathAsTraceAsString> for TargetPathElement {
fn from(value: TargetPathAsTraceAsString) -> Self {
Self::AsTraceAsString(value)
}
}
impl fmt::Display for TargetPathElement {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::BundleField(v) => v.fmt(f),
Self::ArrayElement(v) => v.fmt(f),
Self::DynArrayElement(v) => v.fmt(f),
Self::TraceAsStringInner(v) => v.fmt(f),
Self::AsTraceAsString(v) => v.fmt(f),
}
}
}
@ -100,6 +136,15 @@ impl TargetPathElement {
let parent_ty = Array::<CanonicalType>::from_canonical(parent.canonical_ty());
parent_ty.element()
}
Self::TraceAsStringInner(_) => {
let parent_ty =
TraceAsString::<CanonicalType>::from_canonical(parent.canonical_ty());
parent_ty.inner_ty()
}
&Self::AsTraceAsString(TargetPathAsTraceAsString { ty }) => {
assert_eq!(parent.canonical_ty(), ty.inner_ty());
ty.canonical()
}
}
}
pub fn flow(&self, parent: Interned<Target>) -> Flow {
@ -111,13 +156,18 @@ impl TargetPathElement {
.expect("field name is known to be a valid field of parent type");
parent.flow().flip_if(field.flipped)
}
Self::ArrayElement(_) => parent.flow(),
Self::DynArrayElement(_) => parent.flow(),
Self::ArrayElement(_)
| Self::DynArrayElement(_)
| Self::TraceAsStringInner(_)
| Self::AsTraceAsString(_) => parent.flow(),
}
}
pub fn is_static(&self) -> bool {
match self {
Self::BundleField(_) | Self::ArrayElement(_) => true,
Self::BundleField(_)
| Self::ArrayElement(_)
| Self::TraceAsStringInner(_)
| Self::AsTraceAsString(_) => true,
Self::DynArrayElement(_) => false,
}
}

View file

@ -16,6 +16,7 @@ use crate::{
ops::{self, VariantAccess},
target::{
Target, TargetBase, TargetPathArrayElement, TargetPathBundleField, TargetPathElement,
TargetPathTraceAsStringInner,
},
},
formal::FormalKind,
@ -471,7 +472,7 @@ impl TypeState {
Ok(self.enum_def(ty)?.1.variants.borrow_mut().get(name))
}
fn ty<T: Type>(&self, ty: T) -> Result<String, FirrtlError> {
Ok(match ty.canonical() {
Ok(match ty.canonical().unwrap_transparent_types() {
CanonicalType::Bundle(ty) => self.bundle_ty(ty)?.to_string(),
CanonicalType::Enum(ty) => self.enum_ty(ty)?.to_string(),
CanonicalType::Array(ty) => {
@ -490,6 +491,7 @@ impl TypeState {
CanonicalType::DynSimOnly(_) => {
return Err(FirrtlError::SimOnlyValuesAreNotPermitted);
}
CanonicalType::TraceAsString(_) => unreachable!("handled by unwrap_transparent_types"),
})
}
}
@ -1191,7 +1193,7 @@ impl<'a> Exporter<'a> {
definitions: &RcDefinitions,
extra_indent: Indent<'_>,
) -> Result<String> {
match ty {
match ty.unwrap_transparent_types() {
CanonicalType::Bundle(ty) => {
self.expr_cast_bundle_to_bits(value_str, ty, definitions, extra_indent)
}
@ -1210,6 +1212,7 @@ impl<'a> Exporter<'a> {
| CanonicalType::Reset(_) => Ok(format!("asUInt({value_str})")),
CanonicalType::PhantomConst(_) => Ok("UInt<0>(0)".into()),
CanonicalType::DynSimOnly(_) => Err(FirrtlError::SimOnlyValuesAreNotPermitted.into()),
CanonicalType::TraceAsString(_) => unreachable!("handled by unwrap_transparent_types"),
}
}
fn expr_cast_bits_to_bundle(
@ -1407,7 +1410,7 @@ impl<'a> Exporter<'a> {
definitions: &RcDefinitions,
extra_indent: Indent<'_>,
) -> Result<String> {
match ty {
match ty.unwrap_transparent_types() {
CanonicalType::Bundle(ty) => {
self.expr_cast_bits_to_bundle(value_str, ty, definitions, extra_indent)
}
@ -1431,6 +1434,7 @@ impl<'a> Exporter<'a> {
return Ok(retval.to_string());
}
CanonicalType::DynSimOnly(_) => Err(FirrtlError::SimOnlyValuesAreNotPermitted.into()),
CanonicalType::TraceAsString(_) => unreachable!("handled by unwrap_transparent_types"),
}
}
fn expr_unary<T: Type>(
@ -1798,6 +1802,10 @@ impl<'a> Exporter<'a> {
write!(out, "[{index}]").unwrap();
Ok(out)
}
ExprEnum::AsTraceAsString(expr) => self.expr(expr.inner(), definitions, const_ty),
ExprEnum::TraceAsStringAsInner(expr) => {
self.expr(Expr::canonical(expr.arg()), definitions, const_ty)
}
ExprEnum::ModuleIO(expr) => Ok(self.module.ns.get(expr.name_id()).to_string()),
ExprEnum::Instance(expr) => {
assert!(!const_ty, "not a constant");
@ -1957,6 +1965,10 @@ impl<'a> Exporter<'a> {
.segments
.push(AnnotationTargetRefSegment::Index { index }),
TargetPathElement::DynArrayElement(_) => unreachable!(),
TargetPathElement::AsTraceAsString(_)
| TargetPathElement::TraceAsStringInner(_) => {
// ignored
}
}
Ok(retval)
}
@ -3211,6 +3223,8 @@ impl ScalarizeTreeNode {
TargetPathElement::DynArrayElement(_) => {
unreachable!("annotations are only on static targets");
}
TargetPathElement::AsTraceAsString(_)
| TargetPathElement::TraceAsStringInner(_) => parent,
}
}
}
@ -3337,6 +3351,13 @@ impl ScalarizeTreeBuilder {
CanonicalType::DynSimOnly(_) => {
return Err(ScalarizedModuleABIError::SimOnlyValuesAreNotPermitted);
}
CanonicalType::TraceAsString(_) => self.build(
target
.join(TargetPathElement::intern_sized(
TargetPathTraceAsStringInner {}.into(),
))
.intern_sized(),
)?,
})
}
}

View file

@ -15,8 +15,8 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, FillInDefaultedGenerics, OpaqueSimValueSize, OpaqueSimValueSlice,
OpaqueSimValueWriter, OpaqueSimValueWritten, StaticType, Type, TypeProperties,
impl_match_variant_as_self,
OpaqueSimValueWriter, OpaqueSimValueWritten, SimValueDebug, SimValueDisplay, StaticType,
Type, TypeProperties, impl_match_variant_as_self,
},
util::{ConstBool, ConstUsize, GenericConstBool, GenericConstUsize, interned_bit, slice_range},
};
@ -1019,6 +1019,24 @@ macro_rules! impl_int {
}
}
impl<Width: Size> SimValueDebug for $name<Width> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<Width: Size> SimValueDisplay for $name<Width> {
fn sim_value_display(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Display::fmt(value, f)
}
}
impl<Width: KnownSize> Default for $name<Width> {
fn default() -> Self {
Self::TYPE
@ -1259,6 +1277,9 @@ macro_rules! impl_int {
pub fn bitvec_mut(&mut self) -> &mut BitVec {
Arc::make_mut(&mut self.bits)
}
pub fn arc_bitvec_mut(&mut self) -> &mut Arc<BitVec> {
&mut self.bits
}
}
};
}
@ -1899,6 +1920,15 @@ impl Type for Bool {
}
}
impl SimValueDebug for Bool {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl StaticType for Bool {
const TYPE: Self = Bool;
const MASK_TYPE: Self::MaskType = Bool;

View file

@ -14,7 +14,7 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten,
StaticType, Type, TypeProperties, impl_match_variant_as_self,
SimValueDebug, StaticType, Type, TypeProperties, impl_match_variant_as_self,
},
};
use bitvec::{order::Lsb0, view::BitView};
@ -94,6 +94,15 @@ impl Type for UIntInRangeMaskType {
}
}
impl SimValueDebug for UIntInRangeMaskType {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl BundleType for UIntInRangeMaskType {
type Builder = NoBuilder;
@ -339,6 +348,15 @@ macro_rules! define_uint_in_range_type {
}
}
impl<Start: Size, End: Size> SimValueDebug for $UIntInRangeType<Start, End> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<Start: Size, End: Size> fmt::Debug for $UIntInRangeType<Start, End> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { value, range } = self;

View file

@ -1093,6 +1093,7 @@ pub fn splat_mask<T: Type>(ty: T, value: Expr<Bool>) -> Expr<AsMask<T>> {
.to_expr(),
)),
CanonicalType::PhantomConst(_) => Expr::from_canonical(Expr::canonical(().to_expr())),
CanonicalType::TraceAsString(ty) => Expr::from_canonical(splat_mask(ty.inner_ty(), value)),
}
}

View file

@ -12,7 +12,7 @@ use crate::{
ops::VariantAccess,
target::{
GetTarget, Target, TargetBase, TargetPathArrayElement, TargetPathBundleField,
TargetPathElement,
TargetPathElement, TargetPathTraceAsStringInner,
},
value_category::ValueCategoryExpr,
},
@ -1111,7 +1111,10 @@ fn validate_clock_for_past<S: ModuleBuildingStatus>(
let mut target = clock_for_past;
while let Target::Child(child) = target {
match *child.path_element() {
TargetPathElement::BundleField(_) | TargetPathElement::ArrayElement(_) => {}
TargetPathElement::BundleField(_)
| TargetPathElement::ArrayElement(_)
| TargetPathElement::AsTraceAsString(_)
| TargetPathElement::TraceAsStringInner(_) => {}
TargetPathElement::DynArrayElement(_) => {
panic!(
"clock_for_past: clock must be a static target (you can't use `Expr<UInt>` array indexes):\n{clock_for_past:?}"
@ -1586,6 +1589,14 @@ impl TargetState {
declared_in_block,
written_in_blocks: RefCell::default(),
},
CanonicalType::TraceAsString(_) => {
return Self::new(
target
.join(Intern::intern_sized(TargetPathTraceAsStringInner {}.into()))
.intern_sized(),
declared_in_block,
);
}
},
}
}
@ -1605,44 +1616,58 @@ impl AssertValidityState {
}
fn get_target_states<'a>(
&'a self,
target: &Target,
mut target: &Target,
process_target_state: &dyn Fn(&'a TargetState, bool),
) -> Result<(), ()> {
match target {
Target::Base(target_base) => {
let target_state = self.get_base_state(*target_base)?;
process_target_state(target_state, false);
Ok(())
}
Target::Child(target_child) => self.get_target_states(
&target_child.parent(),
&|target_state, exact_target_unknown| {
let TargetStateInner::Decomposed { subtargets } = &target_state.inner else {
unreachable!(
"TargetState::new makes TargetState tree match the Target type"
);
};
match *target_child.path_element() {
TargetPathElement::BundleField(_) => process_target_state(
subtargets
.get(&target_child.path_element())
.expect("bundle fields filled in by TargetState::new"),
exact_target_unknown,
),
TargetPathElement::ArrayElement(_) => process_target_state(
subtargets
.get(&target_child.path_element())
.expect("array elements filled in by TargetState::new"),
exact_target_unknown,
),
TargetPathElement::DynArrayElement(_) => {
for target_state in subtargets.values() {
process_target_state(target_state, true);
loop {
break match target {
Target::Base(target_base) => {
let target_state = self.get_base_state(*target_base)?;
process_target_state(target_state, false);
Ok(())
}
Target::Child(target_child) => match *target_child.path_element() {
TargetPathElement::BundleField(_)
| TargetPathElement::ArrayElement(_)
| TargetPathElement::DynArrayElement(_) => self.get_target_states(
&target_child.parent(),
&|target_state, exact_target_unknown| {
let TargetStateInner::Decomposed { subtargets } = &target_state.inner
else {
unreachable!(
"TargetState::new makes TargetState tree match the Target type"
);
};
match *target_child.path_element() {
TargetPathElement::BundleField(_) => process_target_state(
subtargets
.get(&target_child.path_element())
.expect("bundle fields filled in by TargetState::new"),
exact_target_unknown,
),
TargetPathElement::ArrayElement(_) => process_target_state(
subtargets
.get(&target_child.path_element())
.expect("array elements filled in by TargetState::new"),
exact_target_unknown,
),
TargetPathElement::DynArrayElement(_) => {
for target_state in subtargets.values() {
process_target_state(target_state, true);
}
}
TargetPathElement::TraceAsStringInner(_)
| TargetPathElement::AsTraceAsString(_) => unreachable!(),
}
}
},
),
TargetPathElement::TraceAsStringInner(_)
| TargetPathElement::AsTraceAsString(_) => {
target = Interned::into_inner(target_child.parent());
continue;
}
},
),
};
}
}
fn get_base_state(&self, target_base: Interned<TargetBase>) -> Result<&TargetState, ()> {
@ -1716,6 +1741,8 @@ impl AssertValidityState {
TargetPathElement::DynArrayElement { .. } => {
Self::set_connect_target_written(sub_target_state, is_lhs, block, true);
}
TargetPathElement::TraceAsStringInner(_)
| TargetPathElement::AsTraceAsString(_) => unreachable!("never added"),
}
}
}

View file

@ -9,8 +9,9 @@ use crate::{
ExprEnum, ValueType,
ops::{self, ArrayLiteral},
target::{
Target, TargetBase, TargetChild, TargetPathArrayElement, TargetPathBundleField,
TargetPathDynArrayElement, TargetPathElement,
Target, TargetBase, TargetChild, TargetPathArrayElement, TargetPathAsTraceAsString,
TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement,
TargetPathTraceAsStringInner,
},
},
formal::FormalKind,
@ -26,6 +27,7 @@ use crate::{
prelude::*,
reset::{ResetType, ResetTypeDispatch},
sim::ExternModuleSimulation,
ty::TraceAsString,
util::{HashMap, HashSet},
};
use hashbrown::hash_map::Entry;
@ -103,6 +105,10 @@ enum ResetsLayout {
element: Interned<ResetsLayout>,
reset_count: usize,
},
Transparent {
inner: Interned<ResetsLayout>,
reset_count: usize,
},
}
impl ResetsLayout {
@ -112,7 +118,8 @@ impl ResetsLayout {
ResetsLayout::Reset | ResetsLayout::SyncReset | ResetsLayout::AsyncReset => 1,
ResetsLayout::Bundle { reset_count, .. }
| ResetsLayout::Enum { reset_count, .. }
| ResetsLayout::Array { reset_count, .. } => reset_count,
| ResetsLayout::Array { reset_count, .. }
| ResetsLayout::Transparent { reset_count, .. } => reset_count,
}
}
fn new(ty: CanonicalType) -> Self {
@ -166,6 +173,13 @@ impl ResetsLayout {
CanonicalType::Clock(_) => ResetsLayout::NoResets,
CanonicalType::PhantomConst(_) => ResetsLayout::NoResets,
CanonicalType::DynSimOnly(_) => ResetsLayout::NoResets,
CanonicalType::TraceAsString(ty) => {
let inner = ResetsLayout::new(ty.inner_ty()).intern_sized();
ResetsLayout::Transparent {
inner,
reset_count: inner.reset_count(),
}
}
}
}
}
@ -315,6 +329,12 @@ impl ResetGraph {
} => {
self.append_new_nodes_for_layout(*element, node_indexes, source_location);
}
ResetsLayout::Transparent {
inner,
reset_count: _,
} => {
self.append_new_nodes_for_layout(*inner, node_indexes, source_location);
}
}
}
}
@ -357,6 +377,21 @@ impl Resets {
node_indexes: self.node_indexes,
}
}
fn trace_as_string_inner(self) -> Self {
let trace_as_string = TraceAsString::from_canonical(self.ty);
let ResetsLayout::Transparent {
inner,
reset_count: _,
} = self.layout
else {
unreachable!();
};
Self {
ty: trace_as_string.inner_ty(),
layout: *inner,
node_indexes: self.node_indexes,
}
}
fn bundle_fields(self) -> impl Iterator<Item = Self> {
let bundle = Bundle::from_canonical(self.ty);
let ResetsLayout::Bundle {
@ -480,6 +515,17 @@ impl Resets {
CanonicalType::SyncReset(SyncReset)
},
),
CanonicalType::TraceAsString(ty) => Ok(CanonicalType::TraceAsString(
ty.with_new_inner_ty(
self.array_elements()
.substituted_type(
reset_graph,
fallback_to_sync_reset,
fallback_error_source_location,
)?
.intern_sized(),
),
)),
}
}
}
@ -1013,7 +1059,8 @@ fn cast_bit_op<P: Pass, T: Type, A: Type>(
| CanonicalType::Bundle(_)
| CanonicalType::Reset(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => unreachable!(),
| CanonicalType::DynSimOnly(_)
| CanonicalType::TraceAsString(_) => unreachable!(),
$(CanonicalType::$Variant(ty) => Expr::expr_enum($arg.cast_to(ty)),)*
}
};
@ -1024,7 +1071,8 @@ fn cast_bit_op<P: Pass, T: Type, A: Type>(
CanonicalType::Array(_)
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::Reset(_) => unreachable!(),
| CanonicalType::Reset(_)
| CanonicalType::TraceAsString(_) => unreachable!(),
CanonicalType::PhantomConst(_) |
CanonicalType::DynSimOnly(_) => Expr::expr_enum(arg),
$(CanonicalType::$Variant(_) => {
@ -1156,6 +1204,10 @@ impl<P: Pass> RunPass<P> for ExprEnum {
ExprEnum::SliceSInt(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::CastToBits(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::CastBitsTo(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::TraceAsStringAsInner(expr) => {
Ok(expr.run_pass(pass_args)?.map(ExprEnum::from))
}
ExprEnum::AsTraceAsString(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::ModuleIO(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::Instance(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
ExprEnum::Wire(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)),
@ -1536,6 +1588,67 @@ impl RunPassExpr for ops::CastBitsTo {
}
}
impl RunPassExpr for ops::TraceAsStringAsInner {
type Args<'a> = [Expr<CanonicalType>; 1];
fn args<'a>(&'a self) -> Self::Args<'a> {
[Expr::canonical(self.arg())]
}
fn source_location(&self) -> Option<SourceLocation> {
None
}
fn union_parts(
&self,
resets: Resets,
args_resets: Vec<Resets>,
mut pass_args: PassArgs<'_, BuildResetGraph>,
) -> Result<(), DeduceResetsError> {
pass_args.union(resets, args_resets[0].trace_as_string_inner(), None)
}
fn new(
&self,
_ty: CanonicalType,
new_args: Vec<Expr<CanonicalType>>,
) -> Result<Self, DeduceResetsError> {
Ok(Self::new(Expr::from_canonical(new_args[0])))
}
}
impl RunPassExpr for ops::AsTraceAsString {
type Args<'a> = [Expr<CanonicalType>; 1];
fn args<'a>(&'a self) -> Self::Args<'a> {
[Expr::canonical(self.inner())]
}
fn source_location(&self) -> Option<SourceLocation> {
None
}
fn union_parts(
&self,
resets: Resets,
args_resets: Vec<Resets>,
mut pass_args: PassArgs<'_, BuildResetGraph>,
) -> Result<(), DeduceResetsError> {
pass_args.union(resets.trace_as_string_inner(), args_resets[0], None)
}
fn new(
&self,
_ty: CanonicalType,
new_args: Vec<Expr<CanonicalType>>,
) -> Result<Self, DeduceResetsError> {
Ok(Self::new(
new_args[0],
self.ty().with_new_inner_ty(new_args[0].ty().intern_sized()),
))
}
}
impl RunPassExpr for ModuleIO<CanonicalType> {
type Args<'a> = [Expr<CanonicalType>; 0];
@ -1691,7 +1804,8 @@ impl RunPassDispatch for AnyReg {
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => unreachable!(),
| CanonicalType::DynSimOnly(_)
| CanonicalType::TraceAsString(_) => unreachable!(),
}
})
}
@ -2173,30 +2287,6 @@ impl<P: Pass> RunPass<P> for StmtDeclaration {
}
}
impl_run_pass_for_struct! {
impl[] RunPass for TargetPathBundleField {
name: _,
}
}
impl_run_pass_for_struct! {
impl[] RunPass for TargetPathArrayElement {
index: _,
}
}
impl_run_pass_for_struct! {
impl[] RunPass for TargetPathDynArrayElement {}
}
impl_run_pass_for_enum! {
impl[] RunPass for TargetPathElement {
BundleField(v),
ArrayElement(v),
DynArrayElement(v),
}
}
impl_run_pass_for_enum! {
impl[] RunPass for Target {
Base(v),
@ -2204,11 +2294,28 @@ impl_run_pass_for_enum! {
}
}
impl_run_pass_for_struct! {
#[constructor = TargetChild::new(parent, path_element)]
impl[] RunPass for TargetChild {
parent(): _,
path_element(): _,
impl<P: Pass> RunPass<P> for TargetChild {
fn run_pass(
&self,
mut pass_args: PassArgs<'_, P>,
) -> Result<PassOutput<Self, P>, DeduceResetsError> {
Ok(self.parent().run_pass(pass_args.as_mut())?.map(|parent| {
let path_element = match *self.path_element() {
TargetPathElement::BundleField(TargetPathBundleField { name: _ })
| TargetPathElement::ArrayElement(TargetPathArrayElement { index: _ })
| TargetPathElement::DynArrayElement(TargetPathDynArrayElement {})
| TargetPathElement::TraceAsStringInner(TargetPathTraceAsStringInner {}) => {
self.path_element()
}
TargetPathElement::AsTraceAsString(TargetPathAsTraceAsString { ty }) => {
TargetPathElement::from(TargetPathAsTraceAsString {
ty: ty.with_new_inner_ty(parent.canonical_ty().intern_sized()),
})
.intern_sized()
}
};
TargetChild::new(parent, path_element)
}))
}
}

View file

@ -17,7 +17,7 @@ use crate::{
transform::visit::{Fold, Folder},
},
source_location::SourceLocation,
ty::{CanonicalType, Type},
ty::{CanonicalType, TraceAsString, Type},
util::HashMap,
wire::Wire,
};
@ -64,6 +64,7 @@ fn contains_any_enum_types(ty: CanonicalType) -> bool {
.fields()
.iter()
.any(|field| contains_any_enum_types(field.ty)),
CanonicalType::TraceAsString(ty) => contains_any_enum_types(ty.inner_ty()),
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
@ -313,6 +314,24 @@ impl State {
}
Ok(())
}
fn handle_stmt_connect_trace_as_string(
&mut self,
unfolded_lhs_ty: TraceAsString,
unfolded_rhs_ty: TraceAsString,
folded_lhs: Expr<TraceAsString>,
folded_rhs: Expr<TraceAsString>,
source_location: SourceLocation,
output_stmts: &mut Vec<Stmt>,
) -> Result<(), SimplifyEnumsError> {
self.handle_stmt_connect(
unfolded_lhs_ty.inner_ty(),
unfolded_rhs_ty.inner_ty(),
ops::TraceAsStringAsInner::new(folded_lhs).to_expr(),
ops::TraceAsStringAsInner::new(folded_rhs).to_expr(),
source_location,
output_stmts,
)
}
fn handle_stmt_connect_bundle(
&mut self,
unfolded_lhs_ty: Bundle,
@ -509,6 +528,15 @@ impl State {
source_location,
output_stmts,
),
CanonicalType::TraceAsString(unfolded_lhs_ty) => self
.handle_stmt_connect_trace_as_string(
unfolded_lhs_ty,
TraceAsString::from_canonical(unfolded_rhs_ty),
Expr::from_canonical(folded_lhs),
Expr::from_canonical(folded_rhs),
source_location,
output_stmts,
),
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
@ -528,6 +556,8 @@ fn connect_port(
rhs: Expr<CanonicalType>,
source_location: SourceLocation,
) {
let lhs = Expr::unwrap_transparent_types(lhs);
let rhs = Expr::unwrap_transparent_types(rhs);
if lhs.ty() == rhs.ty() {
stmts.push(
StmtConnect {
@ -573,6 +603,9 @@ fn connect_port(
connect_port(stmts, lhs[index], rhs[index], source_location);
}
}
(CanonicalType::TraceAsString(_), CanonicalType::TraceAsString(_)) => {
unreachable!("handled by unwrap_transparent_types")
}
(CanonicalType::Bundle(_), _)
| (CanonicalType::Enum(_), _)
| (CanonicalType::Array(_), _)
@ -584,7 +617,8 @@ fn connect_port(
| (CanonicalType::SyncReset(_), _)
| (CanonicalType::Reset(_), _)
| (CanonicalType::PhantomConst(_), _)
| (CanonicalType::DynSimOnly(_), _) => unreachable!(
| (CanonicalType::DynSimOnly(_), _)
| (CanonicalType::TraceAsString(_), _) => unreachable!(
"trying to connect memory ports:\n{:?}\n{:?}",
lhs.ty(),
rhs.ty(),
@ -772,6 +806,8 @@ impl Folder for State {
| ExprEnum::SliceSInt(_)
| ExprEnum::CastToBits(_)
| ExprEnum::CastBitsTo(_)
| ExprEnum::TraceAsStringAsInner(_)
| ExprEnum::AsTraceAsString(_)
| ExprEnum::ModuleIO(_)
| ExprEnum::Instance(_)
| ExprEnum::Wire(_)
@ -936,7 +972,8 @@ impl Folder for State {
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => canonical_type.default_fold(self),
| CanonicalType::DynSimOnly(_)
| CanonicalType::TraceAsString(_) => canonical_type.default_fold(self),
}
}

View file

@ -90,7 +90,7 @@ impl MemSplit {
}
}
fn new(element_type: CanonicalType) -> Self {
match element_type {
match element_type.unwrap_transparent_types() {
CanonicalType::Bundle(bundle_ty) => MemSplit::Bundle {
fields: bundle_ty
.fields()
@ -195,6 +195,7 @@ impl MemSplit {
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_) => unreachable!("memory element type is a storable type"),
CanonicalType::DynSimOnly(_) => todo!("memory containing sim-only values"),
CanonicalType::TraceAsString(_) => unreachable!("handled by unwrap_transparent_types"),
}
}
}
@ -306,7 +307,9 @@ impl SplitMemState<'_, '_> {
let outer_mem_name_path_len = self.mem_name_path.len();
match self.split {
MemSplit::Bundle { fields } => {
let CanonicalType::Bundle(bundle_type) = self.element_type else {
let CanonicalType::Bundle(bundle_type) =
self.element_type.unwrap_transparent_types()
else {
unreachable!();
};
for ((field, field_offset), split) in bundle_type
@ -321,7 +324,10 @@ impl SplitMemState<'_, '_> {
let field_ty_bit_width = field.ty.bit_width();
self.split_state_stack.push_map(
|e: Expr<CanonicalType>| {
Expr::field(Expr::<Bundle>::from_canonical(e), &field.name)
Expr::field(
Expr::<Bundle>::from_canonical(Expr::unwrap_transparent_types(e)),
&field.name,
)
},
|initial_value_element| {
let Some(field_offset) = field_offset.only_bit_width() else {
@ -377,8 +383,8 @@ impl SplitMemState<'_, '_> {
};
self.output_stmts.push(
StmtConnect {
lhs: Expr::field(port_expr, name),
rhs: Expr::field(wire_expr, name),
lhs: Expr::unwrap_transparent_types(Expr::field(port_expr, name)),
rhs: Expr::unwrap_transparent_types(Expr::field(wire_expr, name)),
source_location: port.source_location(),
}
.into(),
@ -389,7 +395,8 @@ impl SplitMemState<'_, '_> {
self.output_mems.push(new_mem);
}
MemSplit::Array { elements } => {
let CanonicalType::Array(array_type) = self.element_type else {
let CanonicalType::Array(array_type) = self.element_type.unwrap_transparent_types()
else {
unreachable!();
};
let element_type = array_type.element();
@ -398,7 +405,7 @@ impl SplitMemState<'_, '_> {
self.mem_name_path.truncate(outer_mem_name_path_len);
write!(self.mem_name_path, "_{index}").unwrap();
self.split_state_stack.push_map(
|e| Expr::<Array>::from_canonical(e)[index],
|e| Expr::<Array>::from_canonical(Expr::unwrap_transparent_types(e))[index],
|initial_value_element| {
&initial_value_element[index * element_bit_width..][..element_bit_width]
},
@ -464,7 +471,7 @@ impl ModuleState {
assert_eq!(memory_element_array_range_len % input_array_type.len(), 0);
let chunk_size = memory_element_array_range_len / input_array_type.len();
for index in 0..input_array_type.len() {
let map = |e| Expr::<Array>::from_canonical(e)[index];
let map = |e| Expr::<Array>::from_canonical(Expr::unwrap_transparent_types(e))[index];
let wire_rdata = wire_rdata.map(map);
let wire_wdata = wire_wdata.map(map);
let wire_wmask = wire_wmask.map(map);
@ -505,8 +512,8 @@ impl ModuleState {
port_read: Expr<CanonicalType>| {
output_stmts.push(
StmtConnect {
lhs: wire_read,
rhs: port_read,
lhs: Expr::unwrap_transparent_types(wire_read),
rhs: Expr::unwrap_transparent_types(port_read),
source_location,
}
.into(),
@ -517,8 +524,8 @@ impl ModuleState {
port_write: Expr<CanonicalType>| {
output_stmts.push(
StmtConnect {
lhs: port_write,
rhs: wire_write,
lhs: Expr::unwrap_transparent_types(port_write),
rhs: Expr::unwrap_transparent_types(wire_write),
source_location,
}
.into(),
@ -530,7 +537,8 @@ impl ModuleState {
connect_read(
output_stmts,
wire_read,
Expr::<UInt>::from_canonical(port_read).cast_bits_to(wire_read.ty()),
Expr::<UInt>::from_canonical(Expr::unwrap_transparent_types(port_read))
.cast_bits_to(wire_read.ty()),
);
};
let connect_write_enum =
@ -544,7 +552,7 @@ impl ModuleState {
);
};
loop {
match input_element_type {
match input_element_type.unwrap_transparent_types() {
CanonicalType::Bundle(_) => {
unreachable!("bundle types are always split")
}
@ -625,6 +633,9 @@ impl ModuleState {
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_) => unreachable!("memory element type is a storable type"),
CanonicalType::DynSimOnly(_) => todo!("memory containing sim-only values"),
CanonicalType::TraceAsString(_) => {
unreachable!("handled by unwrap_transparent_types")
}
}
break;
}

View file

@ -13,8 +13,9 @@ use crate::{
expr::{
Expr, ExprEnum, ValueType, ops,
target::{
Target, TargetBase, TargetChild, TargetPathArrayElement, TargetPathBundleField,
TargetPathDynArrayElement, TargetPathElement,
Target, TargetBase, TargetChild, TargetPathArrayElement, TargetPathAsTraceAsString,
TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement,
TargetPathTraceAsStringInner,
},
},
formal::FormalKind,
@ -32,7 +33,7 @@ use crate::{
reset::{AsyncReset, Reset, ResetType, SyncReset},
sim::{ExternModuleSimulation, value::DynSimOnly},
source_location::SourceLocation,
ty::{CanonicalType, Type},
ty::{CanonicalType, TraceAsString, Type},
vendor::xilinx::{
XdcCreateClockAnnotation, XdcIOStandardAnnotation, XdcLocationAnnotation, XilinxAnnotation,
},

View file

@ -9,7 +9,7 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, OpaqueSimValueSlice, OpaqueSimValueWriter, OpaqueSimValueWritten,
StaticType, Type, TypeProperties, impl_match_variant_as_self,
SimValueDebug, StaticType, Type, TypeProperties, impl_match_variant_as_self,
serde_impls::{SerdeCanonicalType, SerdePhantomConst},
},
};
@ -327,6 +327,15 @@ impl<T: ?Sized + PhantomConstValue> Type for PhantomConst<T> {
}
}
impl<T: ?Sized + PhantomConstValue> SimValueDebug for PhantomConst<T> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<T: ?Sized + PhantomConstValue> Default for PhantomConst<T>
where
Interned<T>: Default,

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information
use crate::{
clock::Clock,
expr::{CastToImpl, Expr, ValueType},
@ -8,11 +9,13 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, OpaqueSimValueSize, OpaqueSimValueSlice, OpaqueSimValueWriter,
OpaqueSimValueWritten, StaticType, Type, TypeProperties, impl_match_variant_as_self,
OpaqueSimValueWritten, SimValueDebug, StaticType, Type, TypeProperties,
impl_match_variant_as_self,
},
util::ConstUsize,
};
use bitvec::{bits, order::Lsb0};
use std::fmt;
mod sealed {
pub trait ResetTypeSealed {}
@ -100,6 +103,15 @@ macro_rules! reset_type {
}
}
impl SimValueDebug for $name {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl $name {
pub fn type_properties(self) -> TypeProperties {
Self::TYPE_PROPERTIES

View file

@ -9,6 +9,7 @@ use crate::{
Flow,
target::{
GetTarget, Target, TargetPathArrayElement, TargetPathBundleField, TargetPathElement,
TargetPathTraceAsStringInner,
},
},
int::BoolOrIntType,
@ -38,7 +39,7 @@ use crate::{
},
ty::{
OpaqueSimValue, OpaqueSimValueSize, OpaqueSimValueSizeRange, OpaqueSimValueSlice,
OpaqueSimValueWriter,
OpaqueSimValueWriter, TraceAsString,
},
util::{BitSliceWriteWithBase, DebugAsDisplay, HashMap, HashSet, copy_le_bytes_to_bitslice},
};
@ -432,6 +433,15 @@ impl_trace_decl! {
ty: DynSimOnly,
flow: Flow,
}),
TraceAsString(TraceTraceAsString {
fn location(self) -> _ {
self.location
}
location: TraceLocation,
name: Interned<str>,
ty: TraceAsString,
flow: Flow,
}),
}),
}
@ -543,6 +553,7 @@ pub trait TraceWriter: fmt::Debug + 'static {
id: TraceScalarId,
value: &DynSimOnlyValue,
) -> Result<(), Self::Error>;
fn set_signal_string(&mut self, id: TraceScalarId, value: &str) -> Result<(), Self::Error>;
}
pub struct DynTraceWriterDecls(Box<dyn TraceWriterDeclsDynTrait>);
@ -607,6 +618,7 @@ trait TraceWriterDynTrait: fmt::Debug + 'static {
id: TraceScalarId,
value: &DynSimOnlyValue,
) -> std::io::Result<()>;
fn set_signal_string_dyn(&mut self, id: TraceScalarId, value: &str) -> std::io::Result<()>;
}
impl<T: TraceWriter> TraceWriterDynTrait for T {
@ -680,6 +692,9 @@ impl<T: TraceWriter> TraceWriterDynTrait for T {
) -> std::io::Result<()> {
Ok(TraceWriter::set_signal_sim_only_value(self, id, value).map_err(err_into_io)?)
}
fn set_signal_string_dyn(&mut self, id: TraceScalarId, value: &str) -> std::io::Result<()> {
Ok(TraceWriter::set_signal_string(self, id, value).map_err(err_into_io)?)
}
}
pub struct DynTraceWriter(Box<dyn TraceWriterDynTrait>);
@ -758,6 +773,9 @@ impl TraceWriter for DynTraceWriter {
) -> Result<(), Self::Error> {
self.0.set_signal_sim_only_value_dyn(id, value)
}
fn set_signal_string(&mut self, id: TraceScalarId, value: &str) -> Result<(), Self::Error> {
self.0.set_signal_string_dyn(id, value)
}
}
#[derive(Debug)]
@ -828,6 +846,7 @@ where
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) struct SimTrace<K, S> {
kind: K,
maybe_changed: bool,
state: S,
last_state: S,
}
@ -848,12 +867,14 @@ impl<K: fmt::Debug> SimTraceDebug<TraceScalarId> for SimTrace<K, ()> {
fn fmt(&self, id: TraceScalarId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
kind,
maybe_changed,
state,
last_state,
} = self;
f.debug_struct("SimTrace")
.field("id", &id)
.field("kind", kind)
.field("maybe_changed", maybe_changed)
.field("state", state)
.field("last_state", last_state)
.finish()
@ -864,12 +885,14 @@ impl<K: fmt::Debug> SimTraceDebug<TraceScalarId> for SimTrace<K, SimTraceState>
fn fmt(&self, id: TraceScalarId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
kind,
maybe_changed,
state,
last_state,
} = self;
f.debug_struct("SimTrace")
.field("id", &id)
.field("kind", kind)
.field("maybe_changed", maybe_changed)
.field("state", state)
.field("last_state", last_state)
.finish()
@ -929,6 +952,10 @@ pub(crate) enum SimTraceKind {
PhantomConst {
ty: PhantomConst,
},
TraceAsString {
layout: compiler::CompiledTypeLayout<TraceAsString>,
range: TypeIndexRange,
},
}
#[derive(PartialEq, Eq)]
@ -936,6 +963,7 @@ pub(crate) enum SimTraceState {
Bits(BitVec),
SimOnly(DynSimOnlyValue),
PhantomConst,
OpaqueSimValue(OpaqueSimValue),
}
impl Clone for SimTraceState {
@ -944,6 +972,7 @@ impl Clone for SimTraceState {
Self::Bits(v) => Self::Bits(v.clone()),
Self::SimOnly(v) => Self::SimOnly(v.clone()),
Self::PhantomConst => Self::PhantomConst,
Self::OpaqueSimValue(v) => Self::OpaqueSimValue(v.clone()),
}
}
fn clone_from(&mut self, source: &Self) {
@ -951,6 +980,9 @@ impl Clone for SimTraceState {
(SimTraceState::Bits(dest), SimTraceState::Bits(source)) => {
dest.clone_from_bitslice(source);
}
(SimTraceState::OpaqueSimValue(dest), SimTraceState::OpaqueSimValue(source)) => {
dest.clone_from(source);
}
_ => *self = source.clone(),
}
}
@ -985,6 +1017,20 @@ impl SimTraceState {
unreachable!()
}
}
fn unwrap_opaque_sim_value_ref(&self) -> &OpaqueSimValue {
if let SimTraceState::OpaqueSimValue(v) = self {
v
} else {
unreachable!()
}
}
fn unwrap_opaque_sim_value_mut(&mut self) -> &mut OpaqueSimValue {
if let SimTraceState::OpaqueSimValue(v) = self {
v
} else {
unreachable!()
}
}
}
impl fmt::Debug for SimTraceState {
@ -993,6 +1039,7 @@ impl fmt::Debug for SimTraceState {
SimTraceState::Bits(v) => BitSliceWriteWithBase(v).fmt(f),
SimTraceState::SimOnly(v) => v.fmt(f),
SimTraceState::PhantomConst => f.debug_tuple("PhantomConst").finish(),
SimTraceState::OpaqueSimValue(v) => v.fmt(f),
}
}
}
@ -1021,6 +1068,13 @@ impl SimTraceKind {
}
SimTraceKind::PhantomConst { .. } => SimTraceState::PhantomConst,
SimTraceKind::SimOnly { index: _, ty } => SimTraceState::SimOnly(ty.default_value()),
SimTraceKind::TraceAsString { layout, range: _ } => {
let type_properties = layout.ty.type_properties();
SimTraceState::OpaqueSimValue(OpaqueSimValue::from_bits_and_sim_only_values(
UIntValue::new_dyn(Arc::new(BitVec::repeat(false, type_properties.bit_width))),
Vec::with_capacity(type_properties.sim_only_values_len),
))
}
}
}
}
@ -1175,6 +1229,31 @@ impl SimulationModuleState {
true
}
}
CompiledTypeLayoutBody::Transparent { .. } => {
let value = value.map_ty(|ty| match ty {
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
| CanonicalType::Array(_)
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::AsyncReset(_)
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => unreachable!(),
CanonicalType::TraceAsString(ty) => ty,
});
let sub_target = target
.join(TargetPathElement::from(TargetPathTraceAsStringInner {}).intern_sized());
if self.parse_io(sub_target, value.inner()) {
self.uninitialized_ios.insert(target, vec![sub_target]);
true
} else {
false
}
}
}
}
fn mark_target_as_initialized(&mut self, mut target: Target) {
@ -1225,7 +1304,10 @@ impl SimulationModuleState {
Target::Base(_) => break,
Target::Child(child) => {
match *child.path_element() {
TargetPathElement::BundleField(_) | TargetPathElement::ArrayElement(_) => {}
TargetPathElement::BundleField(_)
| TargetPathElement::ArrayElement(_)
| TargetPathElement::TraceAsStringInner(_)
| TargetPathElement::AsTraceAsString(_) => {}
TargetPathElement::DynArrayElement(_) => panic!(
"simulator read/write expression must not have dynamic array indexes"
),
@ -1268,7 +1350,8 @@ impl SimulationModuleState {
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => unreachable!(),
| CanonicalType::DynSimOnly(_)
| CanonicalType::TraceAsString(_) => unreachable!(),
CanonicalType::AsyncReset(_) => true,
CanonicalType::SyncReset(_) => false,
}
@ -1433,6 +1516,26 @@ impl SimulationExternModuleClockForPast {
);
}
}
CompiledTypeLayoutBody::Transparent { .. } => {
let map_ty_fn = |ty| match ty {
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
| CanonicalType::Array(_)
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::AsyncReset(_)
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => unreachable!(),
CanonicalType::TraceAsString(ty) => ty,
};
let current = current.map_ty(map_ty_fn);
let past = past.map_ty(map_ty_fn);
self.add_current_to_past_mapping(current.inner(), past.inner());
}
}
}
}
@ -1901,6 +2004,7 @@ struct SimulationImpl {
),
>,
waiting_sensitivity_sets_by_address: HashMap<*const SensitivitySet, Rc<SensitivitySet>>,
trace_as_string_buf: String,
}
impl fmt::Debug for SimulationImpl {
@ -1990,6 +2094,7 @@ impl SimulationImpl {
next_sensitivity_set_debug_id: _,
waiting_sensitivity_sets_by_compiled_value,
waiting_sensitivity_sets_by_address,
trace_as_string_buf: _,
} = self;
f.debug_struct("Simulation")
.field("state", state)
@ -2078,10 +2183,12 @@ impl SimulationImpl {
traces: SimTraces(Box::from_iter(compiled.traces.0.iter().map(
|&SimTrace {
kind,
maybe_changed: _,
state: _,
last_state: _,
}| SimTrace {
kind,
maybe_changed: true,
state: kind.make_state(),
last_state: kind.make_state(),
},
@ -2094,6 +2201,7 @@ impl SimulationImpl {
next_sensitivity_set_debug_id: 0,
waiting_sensitivity_sets_by_compiled_value: HashMap::default(),
waiting_sensitivity_sets_by_address: HashMap::default(),
trace_as_string_buf: String::with_capacity(256),
}
}
fn write_traces<const ONLY_IF_CHANGED: bool>(
@ -2126,13 +2234,16 @@ impl SimulationImpl {
id,
&SimTrace {
kind,
maybe_changed,
ref state,
ref last_state,
},
) in self.traces.0.iter().enumerate()
{
if ONLY_IF_CHANGED && state == last_state {
continue;
if ONLY_IF_CHANGED {
if !(maybe_changed && state != last_state) {
continue;
}
}
let id = TraceScalarId(id);
match kind {
@ -2171,6 +2282,15 @@ impl SimulationImpl {
SimTraceKind::SimOnly { .. } => {
trace_writer.set_signal_sim_only_value(id, state.unwrap_sim_only_ref())?
}
SimTraceKind::TraceAsString { layout, .. } => {
self.trace_as_string_buf.clear();
layout.ty.trace_fmt_append_to_string(
&mut self.trace_as_string_buf,
state.unwrap_opaque_sim_value_ref().as_slice(),
);
trace_writer.set_signal_string(id, &self.trace_as_string_buf)?;
self.trace_as_string_buf.clear();
}
}
}
Ok(trace_writer)
@ -2193,10 +2313,48 @@ impl SimulationImpl {
fn read_traces<const IS_INITIAL_STEP: bool>(&mut self) {
for &mut SimTrace {
kind,
ref mut maybe_changed,
ref mut state,
ref mut last_state,
} in &mut self.traces.0
{
let new_maybe_changed = match kind {
SimTraceKind::BigUInt { index, ty: _ }
| SimTraceKind::BigSInt { index, ty: _ }
| SimTraceKind::BigBool { index }
| SimTraceKind::BigAsyncReset { index }
| SimTraceKind::BigSyncReset { index }
| SimTraceKind::BigClock { index } => self
.state
.big_slots
.state_index_fetch_maybe_modified_flag(index),
SimTraceKind::SmallUInt { index, ty: _ }
| SimTraceKind::SmallSInt { index, ty: _ }
| SimTraceKind::SmallBool { index }
| SimTraceKind::SmallAsyncReset { index }
| SimTraceKind::SmallSyncReset { index }
| SimTraceKind::SmallClock { index }
| SimTraceKind::EnumDiscriminant { index, ty: _ } => self
.state
.small_slots
.state_index_fetch_maybe_modified_flag(index),
SimTraceKind::SimOnly { index, ty: _ } => self
.state
.sim_only_slots
.state_index_fetch_maybe_modified_flag(index),
SimTraceKind::PhantomConst { ty: _ } => IS_INITIAL_STEP,
SimTraceKind::TraceAsString { layout: _, range } => self
.state
.type_index_range_fetch_maybe_modified_flags(range),
};
if !new_maybe_changed && !IS_INITIAL_STEP {
if *maybe_changed {
last_state.clone_from(state);
}
*maybe_changed = false;
continue;
}
*maybe_changed = new_maybe_changed;
if !IS_INITIAL_STEP {
mem::swap(state, last_state);
}
@ -2241,11 +2399,26 @@ impl SimulationImpl {
.unwrap_sim_only_mut()
.clone_from(&self.state.sim_only_slots[index]);
}
SimTraceKind::TraceAsString { layout, range } => {
let CompiledTypeLayoutBody::Transparent { inner } = layout.body else {
unreachable!()
};
Self::read_opaque_no_settle(
&mut self.state,
CompiledValue {
layout: *inner,
range,
write: None,
},
state.unwrap_opaque_sim_value_mut(),
);
}
}
if IS_INITIAL_STEP {
last_state.clone_from(state);
}
}
self.state.clear_all_maybe_modified_flags();
}
#[track_caller]
fn advance_time(this_ref: &Rc<RefCell<Self>>, duration: SimDuration) {
@ -2772,6 +2945,7 @@ impl SimulationImpl {
+ Copy,
read_write_sim_only_scalar: impl Fn(usize, &mut Opaque, &mut DynSimOnlyValue) + Copy,
) {
let compiled_value = compiled_value.unwrap_transparent_types();
match compiled_value.layout.body {
CompiledTypeLayoutBody::Scalar => {
let signed = match compiled_value.layout.ty {
@ -2787,6 +2961,7 @@ impl SimulationImpl {
CanonicalType::Clock(_) => false,
CanonicalType::PhantomConst(_) => unreachable!(),
CanonicalType::DynSimOnly(_) => false,
CanonicalType::TraceAsString(_) => unreachable!(),
};
let indexes = OpaqueSimValueSizeRange::from(
start_index..start_index + compiled_value.layout.ty.size(),
@ -2863,14 +3038,17 @@ impl SimulationImpl {
);
}
}
CompiledTypeLayoutBody::Transparent { .. } => {
unreachable!("handled by unwrap_transparent_types")
}
}
}
#[track_caller]
fn read_no_settle_helper(
fn read_opaque_no_settle(
state: &mut interpreter::State,
io: Expr<CanonicalType>,
compiled_value: CompiledValue<CanonicalType>,
) -> SimValue<CanonicalType> {
opaque: &mut OpaqueSimValue,
) {
#[track_caller]
fn read_write_sim_only_scalar(
index: usize,
@ -2891,8 +3069,7 @@ impl SimulationImpl {
},
);
}
let size = io.ty().size();
let mut opaque = OpaqueSimValue::with_capacity(size);
let size = compiled_value.layout.ty.size();
opaque.rewrite_with(size, |mut writer| {
SimulationImpl::read_write_sim_value_helper(
state,
@ -2924,6 +3101,16 @@ impl SimulationImpl {
);
writer.fill_cloned_from_slice(OpaqueSimValueSlice::empty())
});
}
#[track_caller]
fn read_no_settle_helper(
state: &mut interpreter::State,
io: Expr<CanonicalType>,
compiled_value: CompiledValue<CanonicalType>,
) -> SimValue<CanonicalType> {
let size = io.ty().size();
let mut opaque = OpaqueSimValue::with_capacity(size);
Self::read_opaque_no_settle(state, compiled_value, &mut opaque);
SimValue::from_opaque(io.ty(), opaque)
}
/// doesn't modify `opaque`

View file

@ -9,8 +9,8 @@ use crate::{
expr::{
ExprEnum, Flow, ValueType, ops,
target::{
GetTarget, Target, TargetBase, TargetPathArrayElement, TargetPathBundleField,
TargetPathElement,
GetTarget, Target, TargetBase, TargetPathArrayElement, TargetPathAsTraceAsString,
TargetPathBundleField, TargetPathElement, TargetPathTraceAsStringInner,
},
},
int::BoolOrIntType,
@ -29,7 +29,8 @@ use crate::{
TraceBool, TraceBundle, TraceClock, TraceDecl, TraceEnumDiscriminant, TraceEnumWithFields,
TraceFieldlessEnum, TraceInstance, TraceLocation, TraceMem, TraceMemPort, TraceMemoryId,
TraceMemoryLocation, TraceModule, TraceModuleIO, TracePhantomConst, TraceReg, TraceSInt,
TraceScalarId, TraceScope, TraceSimOnly, TraceSyncReset, TraceUInt, TraceWire,
TraceScalarId, TraceScope, TraceSimOnly, TraceSyncReset, TraceTraceAsString, TraceUInt,
TraceWire,
interpreter::{
self, Insn, InsnField, InsnFieldKind, InsnFieldType, InsnOrLabel, Insns, InsnsBuilding,
InsnsBuildingDone, InsnsBuildingKind, Label, PrefixLinesWrapper, SmallUInt,
@ -42,7 +43,7 @@ use crate::{
},
},
},
ty::{OpaqueSimValueSize, StaticType},
ty::{OpaqueSimValueSize, StaticType, TraceAsString},
util::{HashMap, chain},
};
use bitvec::vec::BitVec;
@ -110,6 +111,9 @@ pub(crate) enum CompiledTypeLayoutBody {
Bundle {
fields: Interned<[CompiledBundleField]>,
},
Transparent {
inner: Interned<CompiledTypeLayout<CanonicalType>>,
},
}
impl CompiledTypeLayoutBody {
@ -128,6 +132,9 @@ impl CompiledTypeLayoutBody {
.map(|field| field.with_prefixed_debug_names(prefix))
.collect(),
},
CompiledTypeLayoutBody::Transparent { inner } => CompiledTypeLayoutBody::Transparent {
inner: inner.with_prefixed_debug_names(prefix).intern_sized(),
},
}
}
fn with_anonymized_debug_info(self) -> Self {
@ -145,6 +152,9 @@ impl CompiledTypeLayoutBody {
.map(|field| field.with_anonymized_debug_info())
.collect(),
},
CompiledTypeLayoutBody::Transparent { inner } => CompiledTypeLayoutBody::Transparent {
inner: inner.with_anonymized_debug_info().intern_sized(),
},
}
}
}
@ -179,7 +189,7 @@ impl<T: Type> CompiledTypeLayout<T> {
impl Memoize for MyMemoize {
type Input = CanonicalType;
type InputOwned = CanonicalType;
type Output = CompiledTypeLayout<CanonicalType>;
type Output = (TypeLayout<InsnsBuildingDone>, CompiledTypeLayoutBody);
fn inner(self, input: &Self::Input) -> Self::Output {
match input {
@ -197,11 +207,7 @@ impl<T: Type> CompiledTypeLayout<T> {
ty: *input,
};
layout.big_slots = StatePartLayout::scalar(debug_data, ());
CompiledTypeLayout {
ty: *input,
layout: layout.into(),
body: CompiledTypeLayoutBody::Scalar,
}
(layout.into(), CompiledTypeLayoutBody::Scalar)
}
CanonicalType::Array(array) => {
let mut layout = TypeLayout::empty();
@ -215,19 +221,16 @@ impl<T: Type> CompiledTypeLayout<T> {
if array.is_empty() {
elements_non_empty.push(element.with_prefixed_debug_names("[<none>]"));
}
CompiledTypeLayout {
ty: *input,
layout: layout.into(),
body: CompiledTypeLayoutBody::Array {
(
layout.into(),
CompiledTypeLayoutBody::Array {
elements_non_empty: elements_non_empty.intern_deref(),
},
}
)
}
CanonicalType::PhantomConst(_) => {
(TypeLayout::empty(), CompiledTypeLayoutBody::PhantomConst)
}
CanonicalType::PhantomConst(_) => CompiledTypeLayout {
ty: *input,
layout: TypeLayout::empty(),
body: CompiledTypeLayoutBody::PhantomConst,
},
CanonicalType::Bundle(bundle) => {
let mut layout = TypeLayout::empty();
let fields = bundle
@ -246,11 +249,7 @@ impl<T: Type> CompiledTypeLayout<T> {
},
)
.collect();
CompiledTypeLayout {
ty: *input,
layout: layout.into(),
body: CompiledTypeLayoutBody::Bundle { fields },
}
(layout.into(), CompiledTypeLayoutBody::Bundle { fields })
}
CanonicalType::DynSimOnly(ty) => {
let mut layout = TypeLayout::empty();
@ -259,24 +258,30 @@ impl<T: Type> CompiledTypeLayout<T> {
ty: *input,
};
layout.sim_only_slots = StatePartLayout::scalar(debug_data, *ty);
CompiledTypeLayout {
ty: *input,
layout: layout.into(),
body: CompiledTypeLayoutBody::Scalar,
}
(layout.into(), CompiledTypeLayoutBody::Scalar)
}
CanonicalType::TraceAsString(ty) => {
let inner = CompiledTypeLayout::get(ty.inner_ty()).intern_sized();
(inner.layout, CompiledTypeLayoutBody::Transparent { inner })
}
}
}
}
let CompiledTypeLayout {
ty: _,
layout,
body,
} = MyMemoize.get_owned(ty.canonical());
let (layout, body) = MyMemoize.get_owned(ty.canonical());
Self { ty, layout, body }
}
}
impl CompiledTypeLayout<CanonicalType> {
#[must_use]
fn unwrap_transparent_types(mut self) -> Self {
while let CompiledTypeLayoutBody::Transparent { inner } = self.body {
self = *inner;
}
self
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub(crate) struct CompiledValue<T: Type> {
pub(crate) layout: CompiledTypeLayout<T>,
@ -324,6 +329,29 @@ impl<T: Type> CompiledValue<T> {
}
}
impl CompiledValue<CanonicalType> {
#[must_use]
pub(crate) fn unwrap_transparent_types(self) -> Self {
let Self {
layout,
range,
write,
} = self;
Self {
layout: layout.unwrap_transparent_types(),
range,
write: write.map(|(layout, range)| (layout.unwrap_transparent_types(), range)),
}
}
#[must_use]
pub(crate) fn wrap_in_trace_as_string(self, ty: TraceAsString) -> CompiledValue<TraceAsString> {
self.map(|layout, range| {
assert_eq!(layout.ty, ty.inner_ty());
(CompiledTypeLayout::get(ty), range)
})
}
}
pub(crate) struct DebugCompiledValueStateAsMap<'a> {
pub(crate) compiled_value: CompiledValue<CanonicalType>,
pub(crate) state_layout: &'a interpreter::parts::StateLayout<InsnsBuildingDone>,
@ -402,6 +430,17 @@ impl CompiledValue<Array> {
}
}
impl CompiledValue<TraceAsString> {
pub(crate) fn inner(self) -> CompiledValue<CanonicalType> {
self.map(|layout, range| {
let CompiledTypeLayoutBody::Transparent { inner } = layout.body else {
unreachable!();
};
(*inner, range)
})
}
}
macro_rules! make_type_array_indexes {
(
type_plural_fields = [$($type_plural_field:ident,)*];
@ -618,6 +657,16 @@ impl<T: Type> CompiledExpr<T> {
}
}
impl CompiledExpr<CanonicalType> {
#[must_use]
pub(crate) fn wrap_in_trace_as_string(self, ty: TraceAsString) -> CompiledExpr<TraceAsString> {
CompiledExpr {
static_part: self.static_part.wrap_in_trace_as_string(ty),
indexes: self.indexes,
}
}
}
impl CompiledExpr<Bundle> {
fn field_by_index(self, field_index: usize) -> CompiledExpr<CanonicalType> {
CompiledExpr {
@ -666,6 +715,15 @@ impl CompiledExpr<Array> {
}
}
impl CompiledExpr<TraceAsString> {
pub(crate) fn inner(self) -> CompiledExpr<CanonicalType> {
CompiledExpr {
static_part: self.static_part.inner(),
indexes: self.indexes,
}
}
}
macro_rules! make_assignment_graph {
(
type_plural_fields = [$($type_plural_field:ident,)*];
@ -1977,6 +2035,39 @@ macro_rules! impl_compiler {
flow,
}
.into(),
CanonicalType::TraceAsString(ty) => {
let location = match target {
MakeTraceDeclTarget::Expr(target) => {
let compiled_value = self.compile_expr(instantiated_module, target);
let CompiledValue { layout, range, write: _ } =
self.compiled_expr_to_value(compiled_value, source_location).map_ty(Type::from_canonical);
TraceLocation::Scalar(self.new_sim_trace(SimTraceKind::TraceAsString {
layout,
range,
}))
}
MakeTraceDeclTarget::Memory {
id,
depth,
stride,
start,
ty: _,
} => TraceLocation::Memory(TraceMemoryLocation {
id,
depth,
stride,
start,
len: ty.type_properties().bit_width,
}),
};
TraceTraceAsString {
location,
name,
ty,
flow,
}
.into()
}
}
}
fn compiled_expr_to_value(
@ -2234,6 +2325,7 @@ impl Compiler {
let id = TraceScalarId(self.traces.0.len());
self.traces.0.push(SimTrace {
kind,
maybe_changed: true,
state: (),
last_state: (),
});
@ -2420,7 +2512,8 @@ impl Compiler {
| CanonicalType::Reset(_)
| CanonicalType::Clock(_)
| CanonicalType::DynSimOnly(_)
| CanonicalType::PhantomConst(_) => {
| CanonicalType::PhantomConst(_)
| CanonicalType::TraceAsString(_) => {
self.make_trace_scalar(instantiated_module, target, name, source_location)
}
}
@ -2590,6 +2683,12 @@ impl Compiler {
parent.map_ty(Array::from_canonical).element(index)
}
TargetPathElement::DynArrayElement(_) => unreachable!(),
TargetPathElement::TraceAsStringInner(TargetPathTraceAsStringInner {}) => {
parent.map_ty(TraceAsString::from_canonical).inner()
}
TargetPathElement::AsTraceAsString(TargetPathAsTraceAsString { ty }) => parent
.wrap_in_trace_as_string(ty)
.map_ty(|ty| ty.canonical()),
}
}
};
@ -2822,6 +2921,12 @@ impl Compiler {
CanonicalType::PhantomConst(_) | CanonicalType::DynSimOnly(_) => {
self.compile_cast_aggregate_to_bits(instantiated_module, [])
}
CanonicalType::TraceAsString(_) => self.compile_cast_to_bits(
instantiated_module,
ops::CastToBits::new(
ops::TraceAsStringAsInner::new(Expr::from_canonical(expr.arg())).to_expr(),
),
),
}
}
fn compile_cast_bits_to_or_uninit(
@ -2911,6 +3016,16 @@ impl Compiler {
vec![]
});
}
CanonicalType::TraceAsString(ty) => Expr::canonical(
ops::AsTraceAsString::new(
match arg {
Some(arg) => arg.cast_bits_to(ty.inner_ty()),
None => ty.inner_ty().uninit(),
},
ty,
)
.to_expr(),
),
};
let retval = self.compile_expr(instantiated_module, Expr::canonical(retval));
self.compiled_expr_to_value(retval, instantiated_module.leaf_module().source_location())
@ -2962,6 +3077,7 @@ impl Compiler {
CanonicalType::Clock(_) => false,
CanonicalType::PhantomConst(_) => unreachable!(),
CanonicalType::DynSimOnly(_) => unreachable!(),
CanonicalType::TraceAsString(_) => unreachable!(),
};
let dest_signed = match expr.ty() {
CanonicalType::UInt(_) => false,
@ -2976,6 +3092,7 @@ impl Compiler {
CanonicalType::Clock(_) => false,
CanonicalType::PhantomConst(_) => unreachable!(),
CanonicalType::DynSimOnly(_) => unreachable!(),
CanonicalType::TraceAsString(_) => unreachable!(),
};
self.simple_nary_big_expr(instantiated_module, expr.ty(), [arg], |dest, [src]| match (
src_signed,
@ -3721,6 +3838,14 @@ impl Compiler {
ExprEnum::CastBitsTo(expr) => self
.compile_cast_bits_to_or_uninit(instantiated_module, Some(expr.arg()), expr.ty())
.into(),
ExprEnum::AsTraceAsString(expr) => self
.compile_expr(instantiated_module, expr.inner())
.wrap_in_trace_as_string(expr.ty())
.map_ty(|ty| ty.canonical()),
ExprEnum::TraceAsStringAsInner(expr) => self
.compile_expr(instantiated_module, Expr::canonical(expr.arg()))
.map_ty(TraceAsString::from_canonical)
.inner(),
ExprEnum::ModuleIO(expr) => self
.compile_value(TargetInInstantiatedModule {
instantiated_module,
@ -3868,6 +3993,21 @@ impl Compiler {
CanonicalType::DynSimOnly(_) => {
unreachable!("DynSimOnly mismatch");
}
CanonicalType::TraceAsString(_) => {
let lhs = Expr::<TraceAsString>::from_canonical(lhs);
let rhs = Expr::<TraceAsString>::from_canonical(rhs);
let lhs_expr = ops::TraceAsStringAsInner::new(lhs).to_expr();
let rhs_expr = ops::TraceAsStringAsInner::new(rhs).to_expr();
return self.compile_connect(
lhs_instantiated_module,
lhs_conditions,
lhs_expr,
rhs_instantiated_module,
rhs_conditions,
rhs_expr,
source_location,
);
}
}
}
let Some(target) = lhs.target() else {
@ -4243,6 +4383,8 @@ impl Compiler {
mut read: Option<MemoryPortReadInsns<'_>>,
mut write: Option<MemoryPortWriteInsns<'_>>,
) {
let data_layout = data_layout.unwrap_transparent_types();
let mask_layout = mask_layout.unwrap_transparent_types();
match data_layout.body {
CompiledTypeLayoutBody::Scalar => {
let CompiledTypeLayoutBody::Scalar = mask_layout.body else {
@ -4261,6 +4403,7 @@ impl Compiler {
CanonicalType::Clock(_) => false,
CanonicalType::PhantomConst(_) => unreachable!(),
CanonicalType::DynSimOnly(_) => false,
CanonicalType::TraceAsString(_) => unreachable!(),
};
let width = data_layout.ty.bit_width();
if let Some(MemoryPortReadInsns {
@ -4483,6 +4626,9 @@ impl Compiler {
start = start + field.ty.ty.bit_width();
}
}
CompiledTypeLayoutBody::Transparent { .. } => {
unreachable!("handled by unwrap_transparent_types")
}
}
}
fn compile_memory_port_rw(

View file

@ -6,9 +6,9 @@ use crate::{
int::{BoolOrIntType, SInt, UInt},
intern::{Intern, Interned, Memoize},
sim::interpreter::parts::{
StateLayout, StatePartIndex, StatePartKind, StatePartKindBigSlots, StatePartKindMemories,
StatePartKindSimOnlySlots, StatePartKindSmallSlots, StatePartLen, TypeIndexRange,
TypeLayout, get_state_part_kinds,
StateLayout, StatePartIndex, StatePartIndexRange, StatePartKind, StatePartKindBigSlots,
StatePartKindMemories, StatePartKindSimOnlySlots, StatePartKindSmallSlots, StatePartLen,
TypeIndexRange, TypeLayout, get_state_part_kinds,
},
source_location::SourceLocation,
util::{HashMap, HashSet},
@ -17,12 +17,11 @@ use bitvec::slice::BitSlice;
use num_bigint::BigInt;
use num_traits::{One, Signed, ToPrimitive, Zero};
use std::{
borrow::BorrowMut,
convert::Infallible,
fmt::{self, Write},
hash::Hash,
marker::PhantomData,
ops::{ControlFlow, Deref, DerefMut, Index, IndexMut},
ops::{ControlFlow, Deref, Index, IndexMut},
};
use vec_map::VecMap;
@ -915,6 +914,21 @@ impl<K: StatePartKind> StatePart<K> {
value: K::borrow_state(&mut self.value),
}
}
pub(crate) fn state_index_fetch_maybe_modified_flag(
&self,
part_index: StatePartIndex<K>,
) -> bool {
K::state_index_fetch_maybe_modified_flag(&self.value, part_index)
}
pub(crate) fn state_index_range_fetch_maybe_modified_flags(
&self,
part_index_range: StatePartIndexRange<K>,
) -> bool {
K::state_index_range_fetch_maybe_modified_flags(&self.value, part_index_range)
}
pub(crate) fn clear_all_maybe_modified_flags(&mut self) {
K::clear_all_maybe_modified_flags(&mut self.value)
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
@ -922,56 +936,38 @@ pub(crate) struct BorrowedStatePart<'a, K: StatePartKind> {
pub(crate) value: K::BorrowedState<'a>,
}
impl<
'a,
K: StatePartKind<
BorrowedState<'a>: DerefMut<Target: IndexMut<usize, Output = T> + BorrowMut<[T]>>,
>,
T,
> BorrowedStatePart<'a, K>
{
impl<K: StatePartKind> BorrowedStatePart<'_, K> {
pub(crate) fn get_disjoint_mut<const N: usize>(
&mut self,
indexes: [StatePartIndex<K>; N],
) -> [&mut T; N] {
(*self.value)
.borrow_mut()
.get_disjoint_mut(indexes.map(|v| v.value as usize))
.expect("indexes are disjoint")
) -> [&mut K::StateElement; N] {
K::borrowed_state_get_disjoint_mut(&mut self.value, indexes)
}
}
impl<K: StatePartKind<State: Deref<Target: Index<usize, Output = T>>>, T> Index<StatePartIndex<K>>
for StatePart<K>
{
type Output = T;
impl<K: StatePartKind> Index<StatePartIndex<K>> for StatePart<K> {
type Output = K::StateElement;
fn index(&self, index: StatePartIndex<K>) -> &Self::Output {
&self.value[index.value as usize]
K::state_index(&self.value, index)
}
}
impl<K: StatePartKind<State: DerefMut<Target: IndexMut<usize, Output = T>>>, T>
IndexMut<StatePartIndex<K>> for StatePart<K>
{
impl<K: StatePartKind> IndexMut<StatePartIndex<K>> for StatePart<K> {
fn index_mut(&mut self, index: StatePartIndex<K>) -> &mut Self::Output {
&mut self.value[index.value as usize]
K::state_index_mut(&mut self.value, index)
}
}
impl<'a, K: StatePartKind<BorrowedState<'a>: Deref<Target: Index<usize, Output = T>>>, T>
Index<StatePartIndex<K>> for BorrowedStatePart<'a, K>
{
type Output = T;
impl<K: StatePartKind> Index<StatePartIndex<K>> for BorrowedStatePart<'_, K> {
type Output = K::StateElement;
fn index(&self, index: StatePartIndex<K>) -> &Self::Output {
&self.value[index.value as usize]
K::borrowed_state_index(&self.value, index)
}
}
impl<'a, K: StatePartKind<BorrowedState<'a>: DerefMut<Target: IndexMut<usize, Output = T>>>, T>
IndexMut<StatePartIndex<K>> for BorrowedStatePart<'a, K>
{
impl<K: StatePartKind> IndexMut<StatePartIndex<K>> for BorrowedStatePart<'_, K> {
fn index_mut(&mut self, index: StatePartIndex<K>) -> &mut Self::Output {
&mut self.value[index.value as usize]
K::borrowed_state_index_mut(&mut self.value, index)
}
}
@ -1028,6 +1024,15 @@ macro_rules! make_state {
$($type_plural_field: self.$type_plural_field.borrow(),)*
}
}
pub(crate) fn type_index_range_fetch_maybe_modified_flags(&self, range: TypeIndexRange) -> bool {
$(self.$type_plural_field.state_index_range_fetch_maybe_modified_flags(
range.$type_plural_field,
))||*
}
pub(crate) fn clear_all_maybe_modified_flags(&mut self) {
$(self.$state_plural_field.clear_all_maybe_modified_flags();)*
$(self.$type_plural_field.clear_all_maybe_modified_flags();)*
}
}
#[derive(Debug)]

View file

@ -236,6 +236,7 @@ pub(crate) trait StatePartKind:
type LayoutData: Send + Sync + Eq + Hash + fmt::Debug + 'static + Copy;
type State: fmt::Debug + 'static + Clone;
type BorrowedState<'a>: 'a;
type StateElement;
fn new_state(layout_data: &[Self::LayoutData]) -> Self::State;
fn borrow_state<'a>(state: &'a mut Self::State) -> Self::BorrowedState<'a>;
fn part_debug_data<BK: InsnsBuildingKind>(
@ -247,6 +248,35 @@ pub(crate) trait StatePartKind:
index: StatePartIndex<Self>,
f: &mut impl fmt::Write,
) -> fmt::Result;
fn state_index<'a>(
state: &'a Self::State,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement;
fn state_index_mut<'a>(
state: &'a mut Self::State,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement;
fn state_index_fetch_maybe_modified_flag(
state: &Self::State,
part_index: StatePartIndex<Self>,
) -> bool;
fn state_index_range_fetch_maybe_modified_flags(
state: &Self::State,
part_index_range: StatePartIndexRange<Self>,
) -> bool;
fn clear_all_maybe_modified_flags(state: &mut Self::State);
fn borrowed_state_index<'a, 'b>(
state: &'a Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement;
fn borrowed_state_index_mut<'a, 'b>(
state: &'a mut Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement;
fn borrowed_state_get_disjoint_mut<'a, 'b, const N: usize>(
state: &'a mut Self::BorrowedState<'b>,
part_indexes: [StatePartIndex<Self>; N],
) -> [&'a mut Self::StateElement; N];
}
macro_rules! make_state_part_kinds {
@ -272,6 +302,7 @@ impl StatePartKind for StatePartKindMemories {
type LayoutData = MemoryData<Interned<BitSlice>>;
type State = Box<[MemoryData<BitBox>]>;
type BorrowedState<'a> = &'a mut [MemoryData<BitBox>];
type StateElement = MemoryData<BitBox>;
fn new_state(layout_data: &[Self::LayoutData]) -> Self::State {
layout_data
.iter()
@ -297,19 +328,95 @@ impl StatePartKind for StatePartKindMemories {
) -> fmt::Result {
write!(f, "{:#?}", &state.memories[index])
}
fn state_index<'a>(
state: &'a Self::State,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state[part_index.as_usize()]
}
fn state_index_mut<'a>(
state: &'a mut Self::State,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
&mut state[part_index.as_usize()]
}
fn state_index_fetch_maybe_modified_flag(
_state: &Self::State,
_part_index: StatePartIndex<Self>,
) -> bool {
true
}
fn state_index_range_fetch_maybe_modified_flags(
_state: &Self::State,
part_index_range: StatePartIndexRange<Self>,
) -> bool {
part_index_range.len.value > 0
}
fn clear_all_maybe_modified_flags(_state: &mut Self::State) {}
fn borrowed_state_index<'a, 'b>(
state: &'a Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state[part_index.as_usize()]
}
fn borrowed_state_index_mut<'a, 'b>(
state: &'a mut Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
&mut state[part_index.as_usize()]
}
fn borrowed_state_get_disjoint_mut<'a, 'b, const N: usize>(
state: &'a mut Self::BorrowedState<'b>,
part_indexes: [StatePartIndex<Self>; N],
) -> [&'a mut Self::StateElement; N] {
state
.get_disjoint_mut(part_indexes.map(StatePartIndex::as_usize))
.expect("indexes are disjoint")
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default)]
pub(crate) struct StateAndModified<T, M> {
pub(crate) state: T,
pub(crate) modified: M,
}
impl<T: Deref<Target = [E]>, M: Deref<Target = [bool]>, E: fmt::Debug> fmt::Debug
for StateAndModified<T, M>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list()
.entries(self.state.iter().zip(self.modified.iter().copied()).map(
|(state, modified)| {
fmt::from_fn(move |f| {
state.fmt(f)?;
if modified {
f.write_str(" (modified)")?;
}
Ok(())
})
},
))
.finish()
}
}
impl StatePartKind for StatePartKindSmallSlots {
const NAME: &'static str = "SmallSlots";
type DebugData = SlotDebugData;
type LayoutData = ();
type State = Box<[SmallUInt]>;
type BorrowedState<'a> = &'a mut [SmallUInt];
type State = StateAndModified<Box<[Self::StateElement]>, Box<[bool]>>;
type BorrowedState<'a> = StateAndModified<&'a mut [Self::StateElement], &'a mut [bool]>;
type StateElement = SmallUInt;
fn new_state(layout_data: &[Self::LayoutData]) -> Self::State {
vec![0; layout_data.len()].into_boxed_slice()
StateAndModified {
state: vec![0; layout_data.len()].into_boxed_slice(),
modified: vec![false; layout_data.len()].into_boxed_slice(),
}
}
fn borrow_state<'a>(state: &'a mut Self::State) -> Self::BorrowedState<'a> {
state
let StateAndModified { state, modified } = state;
StateAndModified { state, modified }
}
fn part_debug_data<BK: InsnsBuildingKind>(
state_layout: &StateLayout<BK>,
@ -330,19 +437,80 @@ impl StatePartKind for StatePartKindSmallSlots {
write!(f, "{value:#x} {}", value as SmallSInt)?;
Ok(())
}
fn state_index<'a>(
state: &'a Self::State,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn state_index_mut<'a>(
state: &'a mut Self::State,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn state_index_fetch_maybe_modified_flag(
state: &Self::State,
part_index: StatePartIndex<Self>,
) -> bool {
state.modified[part_index.as_usize()]
}
fn state_index_range_fetch_maybe_modified_flags(
state: &Self::State,
part_index_range: StatePartIndexRange<Self>,
) -> bool {
state.modified[part_index_range.start.as_usize()..]
[..part_index_range.len.as_index().as_usize()]
.contains(&true)
}
fn clear_all_maybe_modified_flags(state: &mut Self::State) {
state.modified.fill(false);
}
fn borrowed_state_index<'a, 'b>(
state: &'a Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn borrowed_state_index_mut<'a, 'b>(
state: &'a mut Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn borrowed_state_get_disjoint_mut<'a, 'b, const N: usize>(
state: &'a mut Self::BorrowedState<'b>,
part_indexes: [StatePartIndex<Self>; N],
) -> [&'a mut Self::StateElement; N] {
for part_index in part_indexes {
state.modified[part_index.as_usize()] = true;
}
state
.state
.get_disjoint_mut(part_indexes.map(StatePartIndex::as_usize))
.expect("indexes are disjoint")
}
}
impl StatePartKind for StatePartKindBigSlots {
const NAME: &'static str = "BigSlots";
type DebugData = SlotDebugData;
type LayoutData = ();
type State = Box<[BigInt]>;
type BorrowedState<'a> = &'a mut [BigInt];
type State = StateAndModified<Box<[Self::StateElement]>, Box<[bool]>>;
type BorrowedState<'a> = StateAndModified<&'a mut [Self::StateElement], &'a mut [bool]>;
type StateElement = BigInt;
fn new_state(layout_data: &[Self::LayoutData]) -> Self::State {
layout_data.iter().map(|_| BigInt::default()).collect()
let state: Box<[_]> = layout_data.iter().map(|_| BigInt::default()).collect();
StateAndModified {
modified: vec![false; state.len()].into_boxed_slice(),
state,
}
}
fn borrow_state<'a>(state: &'a mut Self::State) -> Self::BorrowedState<'a> {
state
let StateAndModified { state, modified } = state;
StateAndModified { state, modified }
}
fn part_debug_data<BK: InsnsBuildingKind>(
state_layout: &StateLayout<BK>,
@ -361,19 +529,80 @@ impl StatePartKind for StatePartKindBigSlots {
) -> fmt::Result {
write!(f, "{:#x}", state.big_slots[index])
}
fn state_index<'a>(
state: &'a Self::State,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn state_index_mut<'a>(
state: &'a mut Self::State,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn state_index_fetch_maybe_modified_flag(
state: &Self::State,
part_index: StatePartIndex<Self>,
) -> bool {
state.modified[part_index.as_usize()]
}
fn state_index_range_fetch_maybe_modified_flags(
state: &Self::State,
part_index_range: StatePartIndexRange<Self>,
) -> bool {
state.modified[part_index_range.start.as_usize()..]
[..part_index_range.len.as_index().as_usize()]
.contains(&true)
}
fn clear_all_maybe_modified_flags(state: &mut Self::State) {
state.modified.fill(false);
}
fn borrowed_state_index<'a, 'b>(
state: &'a Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn borrowed_state_index_mut<'a, 'b>(
state: &'a mut Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn borrowed_state_get_disjoint_mut<'a, 'b, const N: usize>(
state: &'a mut Self::BorrowedState<'b>,
part_indexes: [StatePartIndex<Self>; N],
) -> [&'a mut Self::StateElement; N] {
for part_index in part_indexes {
state.modified[part_index.as_usize()] = true;
}
state
.state
.get_disjoint_mut(part_indexes.map(StatePartIndex::as_usize))
.expect("indexes are disjoint")
}
}
impl StatePartKind for StatePartKindSimOnlySlots {
const NAME: &'static str = "SimOnlySlots";
type DebugData = SlotDebugData;
type LayoutData = DynSimOnly;
type State = Box<[DynSimOnlyValue]>;
type BorrowedState<'a> = &'a mut [DynSimOnlyValue];
type State = StateAndModified<Box<[Self::StateElement]>, Box<[bool]>>;
type BorrowedState<'a> = StateAndModified<&'a mut [Self::StateElement], &'a mut [bool]>;
type StateElement = DynSimOnlyValue;
fn new_state(layout_data: &[Self::LayoutData]) -> Self::State {
layout_data.iter().map(|ty| ty.default_value()).collect()
let state: Box<[_]> = layout_data.iter().map(|ty| ty.default_value()).collect();
StateAndModified {
modified: vec![false; state.len()].into_boxed_slice(),
state,
}
}
fn borrow_state<'a>(state: &'a mut Self::State) -> Self::BorrowedState<'a> {
state
let StateAndModified { state, modified } = state;
StateAndModified { state, modified }
}
fn part_debug_data<BK: InsnsBuildingKind>(
state_layout: &StateLayout<BK>,
@ -392,6 +621,61 @@ impl StatePartKind for StatePartKindSimOnlySlots {
) -> fmt::Result {
write!(f, "{:?}", state.sim_only_slots[index])
}
fn state_index<'a>(
state: &'a Self::State,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn state_index_mut<'a>(
state: &'a mut Self::State,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn state_index_fetch_maybe_modified_flag(
state: &Self::State,
part_index: StatePartIndex<Self>,
) -> bool {
state.modified[part_index.as_usize()]
}
fn state_index_range_fetch_maybe_modified_flags(
state: &Self::State,
part_index_range: StatePartIndexRange<Self>,
) -> bool {
state.modified[part_index_range.start.as_usize()..]
[..part_index_range.len.as_index().as_usize()]
.contains(&true)
}
fn clear_all_maybe_modified_flags(state: &mut Self::State) {
state.modified.fill(false);
}
fn borrowed_state_index<'a, 'b>(
state: &'a Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a Self::StateElement {
&state.state[part_index.as_usize()]
}
fn borrowed_state_index_mut<'a, 'b>(
state: &'a mut Self::BorrowedState<'b>,
part_index: StatePartIndex<Self>,
) -> &'a mut Self::StateElement {
state.modified[part_index.as_usize()] = true;
&mut state.state[part_index.as_usize()]
}
fn borrowed_state_get_disjoint_mut<'a, 'b, const N: usize>(
state: &'a mut Self::BorrowedState<'b>,
part_indexes: [StatePartIndex<Self>; N],
) -> [&'a mut Self::StateElement; N] {
for part_index in part_indexes {
state.modified[part_index.as_usize()] = true;
}
state
.state
.get_disjoint_mut(part_indexes.map(StatePartIndex::as_usize))
.expect("indexes are disjoint")
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]

View file

@ -15,7 +15,8 @@ use crate::{
source_location::SourceLocation,
ty::{
CanonicalType, OpaqueSimValue, OpaqueSimValueSize, OpaqueSimValueSlice,
OpaqueSimValueWriter, StaticType, Type, TypeProperties, impl_match_variant_as_self,
OpaqueSimValueWriter, SimValueDebug, StaticType, Type, TypeProperties,
impl_match_variant_as_self,
},
util::{
ConstUsize, HashMap,
@ -551,113 +552,119 @@ impl_sim_value_cmp_as_bool!(AsyncReset);
#[doc(hidden)]
pub mod match_sim_value {
use crate::{
sim::value::{SimValue, ToSimValue},
ty::Type,
};
use crate::{sim::value::SimValue, ty::Type};
use std::ops::{Deref, DerefMut};
macro_rules! wrapper {
(
$(pub struct $wrapper:ident<$T:ident>($inner:ty);)*
) => {
$(#[doc(hidden)]
pub struct $wrapper<$T>($inner);
impl<$T> $wrapper<$T> {
#[inline(always)]
pub fn new(value: $T) -> Self {
Self(<$inner>::new(value))
}
}
impl<$T> Deref for $wrapper<$T> {
type Target = $inner;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<$T> DerefMut for $wrapper<$T> {
#[inline(always)]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
})*
};
}
wrapper! {
pub struct MatchSimValueHelperCheckSimValue<T>(MatchSimValueHelperCheckMutSimValue<T>);
pub struct MatchSimValueHelperCheckMutSimValue<T>(MatchSimValueHelperCheckRefSimValue<T>);
pub struct MatchSimValueHelperCheckRefSimValue<T>(MatchSimValueHelperCheckRefRefSimValue<T>);
pub struct MatchSimValueHelperCheckRefRefSimValue<T>(MatchSimValueHelperCheckRefMutSimValue<T>);
pub struct MatchSimValueHelperCheckRefMutSimValue<T>(MatchSimValueHelperCheckMutRefSimValue<T>);
pub struct MatchSimValueHelperCheckMutRefSimValue<T>(MatchSimValueHelperCheckMutMutSimValue<T>);
pub struct MatchSimValueHelperCheckMutMutSimValue<T>(MatchSimValueHelperIdentity<T>);
}
impl<T: Type> MatchSimValueHelperCheckSimValue<SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> T::SimValue {
SimValue::into_value(self.take())
}
}
impl<'a, T: Type> MatchSimValueHelperCheckMutSimValue<&'a mut SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'a mut T::SimValue {
self.take()
}
}
impl<'a, T: Type> MatchSimValueHelperCheckRefSimValue<&'a SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'a T::SimValue {
self.take()
}
}
impl<'a, 'b, T: Type> MatchSimValueHelperCheckRefRefSimValue<&'a &'b SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'b T::SimValue {
self.take()
}
}
impl<'a, 'b, T: Type> MatchSimValueHelperCheckRefMutSimValue<&'a &'b mut SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'a T::SimValue {
self.take()
}
}
impl<'a, 'b, T: Type> MatchSimValueHelperCheckMutRefSimValue<&'a mut &'b SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'b T::SimValue {
self.take()
}
}
impl<'a, 'b, T: Type> MatchSimValueHelperCheckMutMutSimValue<&'a mut &'b mut SimValue<T>> {
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> &'a mut T::SimValue {
self.take()
}
}
#[doc(hidden)]
pub struct MatchSimValueHelper<T>(Option<T>);
pub struct MatchSimValueHelperIdentity<T>(Option<T>);
impl<T> MatchSimValueHelper<T> {
pub fn new(v: T) -> Self {
impl<T> MatchSimValueHelperIdentity<T> {
fn new(v: T) -> Self {
Self(Some(v))
}
}
#[doc(hidden)]
pub trait MatchSimValue {
type MatchValue;
/// use `self` so it comes first in the method resolution order
fn __fayalite_match_sim_value(self) -> Self::MatchValue
where
Self: Sized;
}
impl<T: Type> MatchSimValue for MatchSimValueHelper<SimValue<T>> {
type MatchValue = T::SimValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
SimValue::into_value(self.0.expect("should be Some"))
#[inline(always)]
fn take(&mut self) -> T {
self.0.take().expect("known to be Some")
}
}
impl<'a, T: Type> MatchSimValue for MatchSimValueHelper<&'a SimValue<T>> {
type MatchValue = &'a T::SimValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
SimValue::value(self.0.expect("should be Some"))
}
}
impl<'a, T: Type> MatchSimValue for MatchSimValueHelper<&'a mut SimValue<T>> {
type MatchValue = &'a mut T::SimValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
SimValue::value_mut(self.0.expect("should be Some"))
}
}
impl<'a, T> MatchSimValue for MatchSimValueHelper<&'_ &'a T>
where
MatchSimValueHelper<&'a T>: MatchSimValue,
{
type MatchValue = <MatchSimValueHelper<&'a T> as MatchSimValue>::MatchValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
MatchSimValue::__fayalite_match_sim_value(MatchSimValueHelper(self.0.map(|v| *v)))
}
}
impl<'a, T> MatchSimValue for MatchSimValueHelper<&'_ mut &'a T>
where
MatchSimValueHelper<&'a T>: MatchSimValue,
{
type MatchValue = <MatchSimValueHelper<&'a T> as MatchSimValue>::MatchValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
MatchSimValue::__fayalite_match_sim_value(MatchSimValueHelper(self.0.map(|v| *v)))
}
}
impl<'a, T> MatchSimValue for MatchSimValueHelper<&'a &'_ mut T>
where
MatchSimValueHelper<&'a T>: MatchSimValue,
{
type MatchValue = <MatchSimValueHelper<&'a T> as MatchSimValue>::MatchValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
MatchSimValue::__fayalite_match_sim_value(MatchSimValueHelper(self.0.map(|v| &**v)))
}
}
impl<'a, T> MatchSimValue for MatchSimValueHelper<&'a mut &'_ mut T>
where
MatchSimValueHelper<&'a mut T>: MatchSimValue,
{
type MatchValue = <MatchSimValueHelper<&'a mut T> as MatchSimValue>::MatchValue;
fn __fayalite_match_sim_value(self) -> Self::MatchValue {
MatchSimValue::__fayalite_match_sim_value(MatchSimValueHelper(self.0.map(|v| &mut **v)))
#[inline(always)]
pub fn __fayalite_match_sim_value(&mut self) -> T {
self.take()
}
}
#[doc(hidden)]
pub trait MatchSimValueFallback {
type MatchValue;
/// use `&mut self` so it comes later in the method resolution order than MatchSimValue
fn __fayalite_match_sim_value(&mut self) -> Self::MatchValue;
}
impl<T: ToSimValue> MatchSimValueFallback for MatchSimValueHelper<T> {
type MatchValue = <T::Type as Type>::SimValue;
fn __fayalite_match_sim_value(&mut self) -> Self::MatchValue {
SimValue::into_value(self.0.take().expect("should be Some").into_sim_value())
}
}
pub type MatchSimValueHelper<T> = MatchSimValueHelperCheckSimValue<T>;
}
pub trait ToSimValue: ToSimValueWithType<<Self as ValueType>::Type> + ValueType {
@ -1091,7 +1098,8 @@ impl ToSimValueWithType<CanonicalType> for bool {
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => {
| CanonicalType::DynSimOnly(_)
| CanonicalType::TraceAsString(_) => {
panic!("can't create SimValue from bool: expected value of type: {ty:?}");
}
CanonicalType::Bool(_)
@ -1394,6 +1402,15 @@ impl Type for DynSimOnly {
}
}
impl SimValueDebug for DynSimOnly {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<T: SimOnlyValueTrait> Type for SimOnly<T> {
type BaseType = DynSimOnly;
type MaskType = Bool;
@ -1459,6 +1476,15 @@ impl<T: SimOnlyValueTrait> Type for SimOnly<T> {
}
}
impl<T: SimOnlyValueTrait> SimValueDebug for SimOnly<T> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
impl<T: SimOnlyValueTrait> StaticType for SimOnly<T> {
const TYPE: Self = Self::new();

View file

@ -12,11 +12,12 @@ use crate::{
TraceEnumDiscriminant, TraceEnumWithFields, TraceFieldlessEnum, TraceInstance,
TraceLocation, TraceMem, TraceMemPort, TraceMemoryId, TraceMemoryLocation, TraceModule,
TraceModuleIO, TracePhantomConst, TraceReg, TraceSInt, TraceScalar, TraceScalarId,
TraceScope, TraceSimOnly, TraceSyncReset, TraceUInt, TraceWire, TraceWriter,
TraceWriterDecls,
TraceScope, TraceSimOnly, TraceSyncReset, TraceTraceAsString, TraceUInt, TraceWire,
TraceWriter, TraceWriterDecls,
time::{SimDuration, SimInstant},
value::DynSimOnlyValue,
},
ty::{OpaqueSimValueSlice, TraceAsString},
util::HashMap,
};
use bitvec::{order::Lsb0, slice::BitSlice};
@ -26,6 +27,7 @@ use std::{
collections::BTreeMap,
fmt::{self, Write as _},
io, mem,
num::NonZeroU64,
};
#[derive(Default, Clone)]
@ -186,6 +188,26 @@ impl<W: io::Write> fmt::Debug for VcdWriterDecls<W> {
}
}
/// pass in scope to ensure it's not available in child scope
fn try_write_vcd_scope<W: io::Write, R>(
writer: &mut W,
scope_type: &str,
scope_name: Interned<str>,
scope: Option<&mut Scope>,
f: impl FnOnce(&mut W, Option<&mut Scope>) -> io::Result<R>,
) -> io::Result<R> {
let Some(scope) = scope else {
return f(writer, None);
};
write_vcd_scope(
writer,
scope_type,
scope_name,
scope,
move |writer, scope| f(writer, Some(scope)),
)
}
/// pass in scope to ensure it's not available in child scope
fn write_vcd_scope<W: io::Write, R>(
writer: &mut W,
@ -237,6 +259,7 @@ trait_arg! {
struct ArgModule<'a> {
properties: &'a mut VcdWriterProperties,
scope: &'a mut Scope,
instance_name: Option<Interned<str>>,
}
impl<'a> ArgModule<'a> {
@ -244,6 +267,7 @@ impl<'a> ArgModule<'a> {
ArgModule {
properties: self.properties,
scope: self.scope,
instance_name: self.instance_name,
}
}
}
@ -267,7 +291,7 @@ struct ArgInType<'a> {
sink_var_type: &'static str,
duplex_var_type: &'static str,
properties: &'a mut VcdWriterProperties,
scope: &'a mut Scope,
scope: Option<&'a mut Scope>,
}
impl<'a> ArgInType<'a> {
@ -277,7 +301,7 @@ impl<'a> ArgInType<'a> {
sink_var_type: self.sink_var_type,
duplex_var_type: self.duplex_var_type,
properties: self.properties,
scope: self.scope,
scope: self.scope.as_deref_mut(),
}
}
}
@ -308,13 +332,14 @@ impl WriteTrace for TraceScalar {
Self::AsyncReset(v) => v.write_trace(writer, arg),
Self::PhantomConst(v) => v.write_trace(writer, arg),
Self::SimOnly(v) => v.write_trace(writer, arg),
Self::TraceAsString(v) => v.write_trace(writer, arg),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[repr(transparent)]
struct VcdId(u64);
struct VcdId(NonZeroU64);
impl VcdId {
const CHAR_RANGE: std::ops::RangeInclusive<u8> = b'!'..=b'~';
@ -344,11 +369,14 @@ impl VcdId {
};
retval = v;
}
let Some(retval) = NonZeroU64::new(retval) else {
return None;
};
Some(Self(retval))
}
#[must_use]
const fn write(self, out: &mut [u8]) -> usize {
let mut id = self.0;
let mut id = self.0.get();
let mut len = 0;
loop {
let digit = (id % Self::BASE as u64) as u8 + *Self::CHAR_RANGE.start();
@ -363,7 +391,7 @@ impl VcdId {
}
len
}
const MAX_ID_LEN: usize = Self(u64::MAX).write(&mut []);
const MAX_ID_LEN: usize = Self(NonZeroU64::MAX).write(&mut []);
}
/// check that VcdId properly round-trips
@ -423,7 +451,7 @@ impl<T: fmt::Display> fmt::Display for Escaped<T> {
fn write_vcd_var<W: io::Write>(
properties: &mut VcdWriterProperties,
scope: &mut Scope,
scope: Option<&mut Scope>,
memory_element_part_body: MemoryElementPartBody,
writer: &mut W,
var_type: &str,
@ -431,8 +459,6 @@ fn write_vcd_var<W: io::Write>(
location: TraceLocation,
name: Interned<str>,
) -> io::Result<()> {
let path_hash = scope.path_hash.clone().joined(name);
let name = scope.new_identifier(name);
let id = match location {
TraceLocation::Scalar(id) => id.as_usize(),
TraceLocation::Memory(TraceMemoryLocation {
@ -464,12 +490,21 @@ fn write_vcd_var<W: io::Write>(
first_id + *element_index
}
};
let id = properties
.scalar_id_to_vcd_id_map
.builder_get_or_insert(id, &path_hash);
write!(writer, "$var {var_type} {size} ")?;
write_vcd_id(writer, id)?;
writeln!(writer, " {name} $end")
if let Some(scope) = scope {
let path_hash = scope.path_hash.clone().joined(name);
let name = scope.new_identifier(name);
let id = properties
.scalar_id_to_vcd_id_map
.builder_get_or_insert(id, &path_hash);
write!(writer, "$var {var_type} {size} ")?;
write_vcd_id(writer, id)?;
writeln!(writer, " {name} $end")
} else {
properties
.scalar_id_to_vcd_id_map
.builder_unused_scalar_id(id);
Ok(())
}
}
impl WriteTrace for TraceUInt {
@ -693,6 +728,34 @@ impl WriteTrace for TraceSimOnly {
}
}
impl WriteTrace for TraceTraceAsString {
fn write_trace<W: io::Write, A: Arg>(self, writer: &mut W, mut arg: A) -> io::Result<()> {
let ArgInType {
source_var_type: _,
sink_var_type: _,
duplex_var_type: _,
properties,
scope,
} = arg.in_type();
let Self {
location,
name,
ty,
flow: _,
} = self;
write_vcd_var(
properties,
scope,
MemoryElementPartBody::TraceAsString { ty },
writer,
"string",
1,
location,
name,
)
}
}
impl WriteTrace for TraceScope {
fn write_trace<W: io::Write, A: Arg>(self, writer: &mut W, arg: A) -> io::Result<()> {
match self {
@ -712,14 +775,24 @@ impl WriteTrace for TraceScope {
impl WriteTrace for TraceModule {
fn write_trace<W: io::Write, A: Arg>(self, writer: &mut W, mut arg: A) -> io::Result<()> {
let ArgModule { properties, scope } = arg.module();
let ArgModule {
properties,
scope,
instance_name,
} = arg.module();
let Self { name, children } = self;
write_vcd_scope(writer, "module", name, scope, |writer, scope| {
for child in children {
child.write_trace(writer, ArgModuleBody { properties, scope })?;
}
Ok(())
})
write_vcd_scope(
writer,
"module",
instance_name.unwrap_or(name),
scope,
|writer, scope| {
for child in children {
child.write_trace(writer, ArgModuleBody { properties, scope })?;
}
Ok(())
},
)
}
}
@ -727,7 +800,7 @@ impl WriteTrace for TraceInstance {
fn write_trace<W: io::Write, A: Arg>(self, writer: &mut W, mut arg: A) -> io::Result<()> {
let ArgModuleBody { properties, scope } = arg.module_body();
let Self {
name: _,
name,
instance_io,
module,
ty: _,
@ -739,10 +812,17 @@ impl WriteTrace for TraceInstance {
sink_var_type: "wire",
duplex_var_type: "wire",
properties,
scope,
scope: None,
},
)?;
module.write_trace(writer, ArgModule { properties, scope })
module.write_trace(
writer,
ArgModule {
properties,
scope,
instance_name: Some(name),
},
)
}
}
@ -781,7 +861,7 @@ impl WriteTrace for TraceMem {
sink_var_type: "reg",
duplex_var_type: "reg",
properties,
scope,
scope: Some(scope),
},
)
},
@ -813,7 +893,7 @@ impl WriteTrace for TraceMemPort {
sink_var_type: "wire",
duplex_var_type: "wire",
properties,
scope,
scope: Some(scope),
},
)
}
@ -834,7 +914,7 @@ impl WriteTrace for TraceWire {
sink_var_type: "wire",
duplex_var_type: "wire",
properties,
scope,
scope: Some(scope),
},
)
}
@ -855,7 +935,7 @@ impl WriteTrace for TraceReg {
sink_var_type: "reg",
duplex_var_type: "reg",
properties,
scope,
scope: Some(scope),
},
)
}
@ -877,7 +957,7 @@ impl WriteTrace for TraceModuleIO {
sink_var_type: "wire",
duplex_var_type: "wire",
properties,
scope,
scope: Some(scope),
},
)
}
@ -898,7 +978,7 @@ impl WriteTrace for TraceBundle {
ty: _,
flow: _,
} = self;
write_vcd_scope(writer, "struct", name, scope, |writer, scope| {
try_write_vcd_scope(writer, "struct", name, scope, |writer, mut scope| {
for field in fields {
field.write_trace(
writer,
@ -907,7 +987,7 @@ impl WriteTrace for TraceBundle {
sink_var_type,
duplex_var_type,
properties,
scope,
scope: scope.as_deref_mut(),
},
)?;
}
@ -931,7 +1011,7 @@ impl WriteTrace for TraceArray {
ty: _,
flow: _,
} = self;
write_vcd_scope(writer, "struct", name, scope, |writer, scope| {
try_write_vcd_scope(writer, "struct", name, scope, |writer, mut scope| {
for element in elements {
element.write_trace(
writer,
@ -940,7 +1020,7 @@ impl WriteTrace for TraceArray {
sink_var_type,
duplex_var_type,
properties,
scope,
scope: scope.as_deref_mut(),
},
)?;
}
@ -965,7 +1045,7 @@ impl WriteTrace for TraceEnumWithFields {
ty: _,
flow: _,
} = self;
write_vcd_scope(writer, "struct", name, scope, |writer, scope| {
try_write_vcd_scope(writer, "struct", name, scope, |writer, mut scope| {
discriminant.write_trace(
writer,
ArgInType {
@ -973,7 +1053,7 @@ impl WriteTrace for TraceEnumWithFields {
sink_var_type,
duplex_var_type,
properties,
scope,
scope: scope.as_deref_mut(),
},
)?;
for field in non_empty_fields {
@ -984,7 +1064,7 @@ impl WriteTrace for TraceEnumWithFields {
sink_var_type,
duplex_var_type,
properties,
scope,
scope: scope.as_deref_mut(),
},
)?;
}
@ -1026,6 +1106,7 @@ impl<W: io::Write> TraceWriterDecls for VcdWriterDecls<W> {
ArgModule {
properties: &mut properties,
scope: &mut Scope::new(PathHash::default()),
instance_name: None,
},
)?;
let ScalarIdToVcdIdMapOrBuilder::Builder(scalar_id_to_vcd_id_map_builder) =
@ -1042,6 +1123,7 @@ impl<W: io::Write> TraceWriterDecls for VcdWriterDecls<W> {
finished_init: false,
timescale,
properties,
trace_as_string_buf: String::with_capacity(256),
})
}
}
@ -1049,6 +1131,7 @@ impl<W: io::Write> TraceWriterDecls for VcdWriterDecls<W> {
enum MemoryElementPartBody {
Scalar,
EnumDiscriminant { ty: Enum },
TraceAsString { ty: TraceAsString },
}
struct MemoryElementPart {
@ -1065,23 +1148,29 @@ struct MemoryProperties {
}
struct ScalarIdToVcdIdMap {
scalar_id_to_vcd_id_map: Box<[VcdId]>,
scalar_id_to_vcd_id_map: Box<[Option<VcdId>]>,
}
#[derive(Default)]
struct ScalarIdToVcdIdMapBuilder {
scalar_id_to_vcd_id_map: BTreeMap<usize, VcdId>,
scalar_id_to_vcd_id_map: BTreeMap<usize, Option<VcdId>>,
lower_half_to_next_upper_half_map: HashMap<u64, u64>,
}
impl ScalarIdToVcdIdMapBuilder {
fn unused_scalar_id(&mut self, scalar_id: usize) {
self.scalar_id_to_vcd_id_map
.entry(scalar_id)
.or_insert(None);
}
/// `VcdId`s are based off of `path_hash` (and not `scalar_id`) since the hash doesn't change
/// when unrelated variables are added/removed, making the generated VCD more friendly for git diff.
fn get_or_insert(&mut self, scalar_id: usize, path_hash: &PathHash) -> VcdId {
*self
.scalar_id_to_vcd_id_map
.entry(scalar_id)
.or_insert_with(|| {
.or_insert(None)
.get_or_insert_with(|| {
let hash = u128::from_le_bytes(
*path_hash
.0
@ -1094,7 +1183,7 @@ impl ScalarIdToVcdIdMapBuilder {
let next_upper_half = self
.lower_half_to_next_upper_half_map
.entry(lower_half)
.or_insert(0);
.or_insert(if lower_half == 0 { 1 } else { 0 });
let upper_half = *next_upper_half;
*next_upper_half += 1;
let Some(id) = upper_half
@ -1103,7 +1192,7 @@ impl ScalarIdToVcdIdMapBuilder {
else {
panic!("too many VcdIds");
};
VcdId(id)
VcdId(NonZeroU64::new(id).expect("known to not be zero"))
})
}
fn build(self) -> ScalarIdToVcdIdMap {
@ -1129,7 +1218,7 @@ enum ScalarIdToVcdIdMapOrBuilder {
}
impl ScalarIdToVcdIdMapOrBuilder {
fn built_scalar_id_to_vcd_id(&self, scalar_id: usize) -> VcdId {
fn built_scalar_id_to_vcd_id(&self, scalar_id: usize) -> Option<VcdId> {
let Self::Built(v) = self else {
panic!("ScalarIdToVcdIdMap isn't built yet");
};
@ -1141,6 +1230,12 @@ impl ScalarIdToVcdIdMapOrBuilder {
};
v.get_or_insert(scalar_id, path_hash)
}
fn builder_unused_scalar_id(&mut self, scalar_id: usize) {
let Self::Builder(v) = self else {
panic!("ScalarIdToVcdIdMap is already built");
};
v.unused_scalar_id(scalar_id)
}
}
struct VcdWriterProperties {
@ -1154,6 +1249,7 @@ pub struct VcdWriter<W: io::Write + 'static> {
finished_init: bool,
timescale: SimDuration,
properties: VcdWriterProperties,
trace_as_string_buf: String,
}
impl<W: io::Write + 'static> VcdWriter<W> {
@ -1165,8 +1261,11 @@ impl<W: io::Write + 'static> VcdWriter<W> {
fn write_string_value_change(
writer: &mut impl io::Write,
value: impl fmt::Display,
id: VcdId,
id: Option<VcdId>,
) -> io::Result<()> {
let Some(id) = id else {
return Ok(());
};
write!(writer, "s{} ", Escaped(value))?;
write_vcd_id(writer, id)?;
writer.write_all(b"\n")
@ -1175,8 +1274,11 @@ fn write_string_value_change(
fn write_bits_value_change(
writer: &mut impl io::Write,
value: &BitSlice,
id: VcdId,
id: Option<VcdId>,
) -> io::Result<()> {
let Some(id) = id else {
return Ok(());
};
match value.len() {
0 => writer.write_all(b"s0 ")?,
1 => writer.write_all(if value[0] { b"1" } else { b"0" })?,
@ -1205,7 +1307,7 @@ fn write_enum_discriminant_value_change(
writer: &mut impl io::Write,
variant_index: usize,
ty: Enum,
id: VcdId,
id: Option<VcdId>,
) -> io::Result<()> {
write_string_value_change(
writer,
@ -1257,6 +1359,21 @@ impl<W: io::Write> TraceWriter for VcdWriter<W> {
.built_scalar_id_to_vcd_id(first_id + element_index),
)?
}
MemoryElementPartBody::TraceAsString { ty } => {
self.trace_as_string_buf.clear();
ty.trace_fmt_append_to_string(
&mut self.trace_as_string_buf,
OpaqueSimValueSlice::from_bitslice(&element_data[start..start + len]),
);
write_string_value_change(
&mut self.writer,
&self.trace_as_string_buf,
self.properties
.scalar_id_to_vcd_id_map
.built_scalar_id_to_vcd_id(first_id + element_index),
)?;
self.trace_as_string_buf.clear();
}
}
}
Ok(())
@ -1350,6 +1467,16 @@ impl<W: io::Write> TraceWriter for VcdWriter<W> {
.built_scalar_id_to_vcd_id(id.as_usize()),
)
}
fn set_signal_string(&mut self, id: TraceScalarId, value: &str) -> Result<(), Self::Error> {
write_string_value_change(
&mut self.writer,
value,
self.properties
.scalar_id_to_vcd_id_map
.built_scalar_id_to_vcd_id(id.as_usize()),
)
}
}
impl<W: io::Write> fmt::Debug for VcdWriter<W> {
@ -1359,6 +1486,7 @@ impl<W: io::Write> fmt::Debug for VcdWriter<W> {
finished_init,
timescale,
properties: _,
trace_as_string_buf: _,
} = self;
f.debug_struct("VcdWriter")
.field("finished_init", finished_init)

View file

@ -3,22 +3,27 @@
use crate::{
array::Array,
bundle::Bundle,
bundle::{Bundle, BundleField, BundleType},
clock::Clock,
enum_::Enum,
expr::Expr,
enum_::{Enum, EnumType, EnumVariant},
expr::{Expr, ToExpr, ValueType, ops},
int::{Bool, SInt, UInt, UIntValue},
intern::{Intern, Interned},
intern::{Intern, Interned, LazyInterned, Memoize, SupportsPtrEqWithTypeId},
module::transform::visit::{Fold, Folder, Visit, Visitor},
phantom_const::PhantomConst,
reset::{AsyncReset, Reset, SyncReset},
sim::value::{DynSimOnly, DynSimOnlyValue, SimValue, ToSimValueWithType},
sim::value::{DynSimOnly, DynSimOnlyValue, SimValue, ToSimValue, ToSimValueWithType},
source_location::SourceLocation,
util::{ConstUsize, slice_range, try_slice_range},
util::{
ConstUsize, iter_eq_by,
serde_by_id::{SerdeByIdProperties, SerdeByIdTable, SerdeByIdTrait},
slice_range, try_slice_range,
},
};
use bitvec::{slice::BitSlice, vec::BitVec};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::DeserializeOwned};
use std::{
fmt,
fmt::{self, Write},
hash::Hash,
iter::{FusedIterator, Sum},
marker::PhantomData,
@ -69,6 +74,7 @@ pub enum CanonicalType {
Clock(Clock),
PhantomConst(PhantomConst),
DynSimOnly(DynSimOnly),
TraceAsString(TraceAsString),
}
impl fmt::Debug for CanonicalType {
@ -86,6 +92,7 @@ impl fmt::Debug for CanonicalType {
Self::Clock(v) => v.fmt(f),
Self::PhantomConst(v) => v.fmt(f),
Self::DynSimOnly(v) => v.fmt(f),
Self::TraceAsString(v) => v.fmt(f),
}
}
}
@ -123,6 +130,7 @@ impl CanonicalType {
CanonicalType::Clock(v) => v.type_properties(),
CanonicalType::PhantomConst(v) => v.type_properties(),
CanonicalType::DynSimOnly(v) => v.type_properties(),
CanonicalType::TraceAsString(v) => v.type_properties(),
}
}
pub fn is_passive(self) -> bool {
@ -217,11 +225,132 @@ impl CanonicalType {
};
lhs.can_connect(rhs)
}
CanonicalType::TraceAsString(lhs) => {
let CanonicalType::TraceAsString(rhs) = rhs else {
return false;
};
lhs.can_connect(rhs)
}
}
}
pub(crate) fn as_serde_unexpected_str(self) -> &'static str {
serde_impls::SerdeCanonicalType::from(self).as_serde_unexpected_str()
}
/// Unwrap transparent types until reaching a non-transparent type. Currently [`TraceAsString`] is the only transparent type.
pub fn unwrap_transparent_types(mut self) -> Self {
loop {
self = match self {
Self::UInt(_)
| Self::SInt(_)
| Self::Bool(_)
| Self::Array(_)
| Self::Enum(_)
| Self::Bundle(_)
| Self::AsyncReset(_)
| Self::SyncReset(_)
| Self::Reset(_)
| Self::Clock(_)
| Self::PhantomConst(_)
| Self::DynSimOnly(_) => return self,
Self::TraceAsString(ty) => ty.inner_ty(),
};
}
}
pub fn is_layout_equivalent(self, other: Self) -> bool {
fn is_bit(ty: CanonicalType) -> bool {
match ty {
CanonicalType::UInt(ty) => ty.width() == 1,
CanonicalType::SInt(_) => false, // SInt<1> doesn't count since it would be -1/0 instead of 1/0
CanonicalType::Bool(_)
| CanonicalType::AsyncReset(_)
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::Clock(_) => true,
CanonicalType::Array(_)
| CanonicalType::Enum(_)
| CanonicalType::Bundle(_)
| CanonicalType::PhantomConst(_)
| CanonicalType::DynSimOnly(_) => false,
CanonicalType::TraceAsString(_) => {
unreachable!("handled by unwrap_transparent_types")
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
struct MyMemoize;
impl Memoize for MyMemoize {
type Input = (CanonicalType, CanonicalType);
type InputOwned = (CanonicalType, CanonicalType);
type Output = bool;
fn inner(self, input: &Self::Input) -> Self::Output {
let (this, other) = *input;
let this = this.unwrap_transparent_types();
let other = other.unwrap_transparent_types();
let this_is_bit = is_bit(this);
let other_is_bit = is_bit(other);
if this_is_bit || other_is_bit {
return this_is_bit && other_is_bit;
}
let this_is_empty = this.size().is_empty();
let other_is_empty = other.size().is_empty();
if this_is_empty || other_is_empty {
return this_is_empty && other_is_empty;
}
match this {
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::DynSimOnly(_) => this == other,
CanonicalType::Array(this) => {
let CanonicalType::Array(other) = other else {
return false;
};
this.len() == other.len()
&& this.element().is_layout_equivalent(other.element())
}
CanonicalType::Enum(this) => {
let CanonicalType::Enum(other) = other else {
return false;
};
iter_eq_by(
this.variants(),
other.variants(),
|EnumVariant { name, ty }, other_variant| {
name == other_variant.name
&& ty.unwrap_or_else(|| ().canonical()).is_layout_equivalent(
other_variant.ty.unwrap_or_else(|| ().canonical()),
)
},
)
}
CanonicalType::Bundle(this) => {
let CanonicalType::Bundle(other) = other else {
return false;
};
iter_eq_by(
this.fields().iter().filter(|f| !f.ty.size().is_empty()),
other.fields().iter().filter(|f| !f.ty.size().is_empty()),
|&BundleField { name, flipped, ty }, other_field| {
name == other_field.name
&& flipped == other_field.flipped
&& ty.is_layout_equivalent(other_field.ty)
},
)
}
CanonicalType::Bool(_)
| CanonicalType::AsyncReset(_)
| CanonicalType::SyncReset(_)
| CanonicalType::Reset(_)
| CanonicalType::Clock(_) => unreachable!("handled by is_bit"),
CanonicalType::PhantomConst(_) => unreachable!("handled by is_empty"),
CanonicalType::TraceAsString(_) => {
unreachable!("handled by unwrap_transparent_types")
}
}
}
}
MyMemoize.get_owned((self, other))
}
}
pub trait MatchVariantAndInactiveScope: Sized {
@ -328,6 +457,7 @@ impl_base_type!(Reset);
impl_base_type!(Clock);
impl_base_type!(PhantomConst);
impl_base_type!(DynSimOnly);
impl_base_type!(TraceAsString);
impl_base_type_serde!(Bool, "a Bool");
impl_base_type_serde!(Enum, "an Enum");
@ -336,6 +466,7 @@ impl_base_type_serde!(AsyncReset, "an AsyncReset");
impl_base_type_serde!(SyncReset, "a SyncReset");
impl_base_type_serde!(Reset, "a Reset");
impl_base_type_serde!(Clock, "a Clock");
impl_base_type_serde!(TraceAsString, "a TraceAsString");
impl sealed::BaseTypeSealed for CanonicalType {}
@ -367,7 +498,15 @@ impl<D: Type> TypeOrDefault<D> for crate::__ {
}
pub trait Type:
Copy + Hash + Eq + fmt::Debug + Send + Sync + 'static + FillInDefaultedGenerics<Type = Self>
Copy
+ Hash
+ Eq
+ fmt::Debug
+ Send
+ Sync
+ 'static
+ FillInDefaultedGenerics<Type = Self>
+ SimValueDebug
{
type BaseType: BaseType;
type MaskType: Type<MaskType = Self::MaskType>;
@ -402,6 +541,16 @@ pub trait Type:
) -> OpaqueSimValueWritten<'w>;
}
pub trait SimValueDebug {
fn sim_value_debug(value: &<Self as Type>::SimValue, f: &mut fmt::Formatter<'_>) -> fmt::Result
where
Self: Type;
}
pub trait SimValueDisplay: Type {
fn sim_value_display(value: &Self::SimValue, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}
pub trait BaseType:
Type<
BaseType = Self,
@ -455,6 +604,7 @@ impl Type for CanonicalType {
CanonicalType::Clock(v) => v.mask_type().canonical(),
CanonicalType::PhantomConst(v) => v.mask_type().canonical(),
CanonicalType::DynSimOnly(v) => v.mask_type().canonical(),
CanonicalType::TraceAsString(v) => v.mask_type().canonical(),
}
}
fn canonical(&self) -> CanonicalType {
@ -490,6 +640,15 @@ impl Type for CanonicalType {
}
}
impl SimValueDebug for CanonicalType {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(value, f)
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, Default)]
#[non_exhaustive]
pub struct OpaqueSimValueSizeRange {
@ -730,13 +889,34 @@ impl Sum for OpaqueSimValueSize {
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub struct OpaqueSimValue {
bits: UIntValue,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
sim_only_values: Vec<DynSimOnlyValue>,
}
impl Clone for OpaqueSimValue {
fn clone(&self) -> Self {
Self {
bits: self.bits.clone(),
sim_only_values: self.sim_only_values.clone(),
}
}
fn clone_from(&mut self, source: &Self) {
let Self {
bits,
sim_only_values,
} = self;
if let Some(bits) = Arc::get_mut(bits.arc_bitvec_mut()) {
bits.clone_from(source.bits.bits());
} else {
*bits = source.bits.clone();
}
sim_only_values.clone_from(&source.sim_only_values);
}
}
impl OpaqueSimValue {
pub fn empty() -> Self {
Self {
@ -815,6 +995,9 @@ impl OpaqueSimValue {
pub fn sim_only_values(&self) -> &[DynSimOnlyValue] {
&self.sim_only_values
}
pub(crate) fn sim_only_values_vec(&self) -> &Vec<DynSimOnlyValue> {
&self.sim_only_values
}
pub fn sim_only_values_mut(&mut self) -> &mut Vec<DynSimOnlyValue> {
&mut self.sim_only_values
}
@ -1116,3 +1299,413 @@ impl<T: Type> Index<T> for AsMaskWithoutGenerics {
Interned::into_inner(Intern::intern_sized(ty.mask_type()))
}
}
trait TraceAsStringTrait: fmt::Debug + 'static + Send + Sync + SupportsPtrEqWithTypeId {
fn trace_fmt(&self, opaque: OpaqueSimValueSlice<'_>, f: &mut fmt::Formatter<'_>)
-> fmt::Result;
fn serde_by_id_properties(&self) -> SerdeByIdProperties<Interned<dyn TraceAsStringTrait>> {
SerdeByIdProperties::of::<Self>()
}
fn can_substitute_type(&self, new_type: CanonicalType) -> bool;
}
impl<T: Type> TraceAsStringTrait for T {
fn trace_fmt(
&self,
opaque: OpaqueSimValueSlice<'_>,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt::Debug::fmt(&Type::sim_value_from_opaque(self, opaque), f)
}
fn can_substitute_type(&self, new_type: CanonicalType) -> bool {
self.canonical().is_layout_equivalent(new_type)
}
}
impl crate::intern::InternedCompare for dyn TraceAsStringTrait {
type InternedCompareKey = crate::intern::PtrEqWithTypeId;
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey {
this.get_ptr_eq_with_type_id()
}
}
impl SerdeByIdTrait for Interned<dyn TraceAsStringTrait> {
fn serde_by_id_properties(&self) -> SerdeByIdProperties<Self> {
TraceAsStringTrait::serde_by_id_properties(&**self)
}
fn static_table() -> &'static SerdeByIdTable<Self> {
static TABLE: SerdeByIdTable<Interned<dyn TraceAsStringTrait>> = SerdeByIdTable::new();
&TABLE
}
const NAME: &'static str = "dyn TraceAsStringTrait";
}
/// When running the fayalite simulator, outputs a single string signal containing a formatted version of the inner value (uses [`fmt::Debug`] by default).
/// This is a transparent type, meaning [`CanonicalType::unwrap_transparent_types`] will unwrap this type.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct TraceAsString<T: Type = CanonicalType> {
inner_ty: LazyInterned<T>,
trace_as_string: LazyInterned<dyn TraceAsStringTrait>,
}
#[expect(non_upper_case_globals)]
pub const TraceAsString: TraceAsStringWithoutGenerics = TraceAsStringWithoutGenerics;
impl<T: Type> fmt::Debug for TraceAsString<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
inner_ty,
trace_as_string: _,
} = self;
f.debug_struct("TraceAsString")
.field("inner_ty", &inner_ty.interned())
.finish_non_exhaustive()
}
}
impl<T: Type> TraceAsString<T> {
pub fn new(inner_ty: T) -> Self {
Self::new_interned(inner_ty.intern_sized())
}
pub fn new_interned(inner_ty: Interned<T>) -> Self {
Self {
inner_ty: LazyInterned::Interned(inner_ty),
trace_as_string: LazyInterned::Interned(Interned::cast_unchecked(
inner_ty,
|v| -> &dyn TraceAsStringTrait { v },
)),
}
}
pub fn interned_inner_ty(self) -> Interned<T> {
self.inner_ty.interned()
}
pub fn inner_ty(self) -> T {
*self.interned_inner_ty()
}
/// create a new `TraceAsString` but try to keep the old formatting method
pub fn with_new_inner_ty<U: Type>(self, inner_ty: Interned<U>) -> TraceAsString<U> {
if self
.trace_as_string
.can_substitute_type(inner_ty.canonical())
{
TraceAsString {
inner_ty: LazyInterned::Interned(inner_ty),
trace_as_string: self.trace_as_string,
}
} else {
TraceAsString::new_interned(inner_ty)
}
}
pub fn canonical_trace_as_string(self) -> TraceAsString<CanonicalType> {
let Self {
inner_ty,
trace_as_string,
} = self;
TraceAsString {
inner_ty: LazyInterned::Interned(inner_ty.interned().canonical().intern_sized()),
trace_as_string,
}
}
pub fn from_canonical_trace_as_string(canonical: TraceAsString<CanonicalType>) -> Self {
let TraceAsString {
inner_ty,
trace_as_string,
} = canonical;
Self {
inner_ty: LazyInterned::Interned(
T::from_canonical(*inner_ty.interned()).intern_sized(),
),
trace_as_string,
}
}
pub fn type_properties(self) -> TypeProperties {
self.interned_inner_ty().canonical().type_properties()
}
pub fn can_connect<T2: Type>(self, rhs: TraceAsString<T2>) -> bool {
self.interned_inner_ty()
.canonical()
.can_connect(rhs.interned_inner_ty().canonical())
}
pub fn trace_fmt(
self,
opaque: OpaqueSimValueSlice<'_>,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
self.trace_as_string.interned().trace_fmt(opaque, f)
}
pub fn trace_fmt_append_to_string(self, output: &mut String, opaque: OpaqueSimValueSlice<'_>) {
fn impl_fn(
trace_as_string: Interned<dyn TraceAsStringTrait>,
output: &mut String,
opaque: OpaqueSimValueSlice<'_>,
) {
let initial_len = output.len();
if let Err(fmt::Error {}) = write!(
output,
"{}",
fmt::from_fn(|f| trace_as_string.trace_fmt(opaque, f))
) {
output.truncate(initial_len);
output.push_str("<!!!failed to format!!!>");
}
}
impl_fn(self.trace_as_string.interned(), output, opaque)
}
}
impl<T: Type> SimValueDebug for TraceAsString<T> {
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
T::sim_value_debug(value, f)
}
}
impl<T: Type> Type for TraceAsString<T> {
type BaseType = TraceAsString<CanonicalType>;
type MaskType = T::MaskType;
type SimValue = TraceAsStringSimValue<T::SimValue>;
type MatchVariant = Expr<T>;
type MatchActiveScope = ();
type MatchVariantAndInactiveScope = MatchVariantWithoutScope<Self::MatchVariant>;
type MatchVariantsIter = std::iter::Once<Self::MatchVariantAndInactiveScope>;
fn match_variants(
this: Expr<Self>,
source_location: SourceLocation,
) -> Self::MatchVariantsIter {
let _ = source_location;
std::iter::once(MatchVariantWithoutScope(
ops::TraceAsStringAsInner::new(this).to_expr(),
))
}
fn mask_type(&self) -> Self::MaskType {
self.inner_ty.mask_type()
}
fn canonical(&self) -> CanonicalType {
CanonicalType::TraceAsString(self.canonical_trace_as_string())
}
fn from_canonical(canonical_type: CanonicalType) -> Self {
let CanonicalType::TraceAsString(canonical) = canonical_type else {
panic!("expected TraceAsString");
};
Self::from_canonical_trace_as_string(canonical)
}
fn source_location() -> SourceLocation {
SourceLocation::builtin()
}
fn sim_value_from_opaque(&self, opaque: OpaqueSimValueSlice<'_>) -> Self::SimValue {
TraceAsStringSimValue {
inner: self.inner_ty.sim_value_from_opaque(opaque),
}
}
fn sim_value_clone_from_opaque(
&self,
value: &mut Self::SimValue,
opaque: OpaqueSimValueSlice<'_>,
) {
self.inner_ty
.sim_value_clone_from_opaque(&mut value.inner, opaque);
}
fn sim_value_to_opaque<'w>(
&self,
value: &Self::SimValue,
writer: OpaqueSimValueWriter<'w>,
) -> OpaqueSimValueWritten<'w> {
self.inner_ty.sim_value_to_opaque(&value.inner, writer)
}
}
impl<T: Type> TypeWithDeref for TraceAsString<T> {
fn expr_deref(this: &Expr<Self>) -> &Self::MatchVariant {
Interned::into_inner(
ops::TraceAsStringAsInner::new(*this)
.to_expr()
.intern_sized(),
)
}
}
struct TraceAsStringStaticTypeHelper<T: StaticType>(PhantomData<T>);
impl<T: StaticType> Default for TraceAsStringStaticTypeHelper<T> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<T: StaticType> From<TraceAsStringStaticTypeHelper<T>> for Interned<dyn TraceAsStringTrait> {
fn from(_value: TraceAsStringStaticTypeHelper<T>) -> Self {
Interned::cast_unchecked(T::TYPE.intern_sized(), |v| -> &dyn TraceAsStringTrait { v })
}
}
impl<T: StaticType> Default for TraceAsString<T> {
fn default() -> Self {
Self::TYPE
}
}
struct MakeType<T: StaticType>(Interned<T>);
impl<T: StaticType> From<MakeType<T>> for Interned<T> {
fn from(value: MakeType<T>) -> Self {
value.0
}
}
impl<T: StaticType> Default for MakeType<T> {
fn default() -> Self {
Self(T::TYPE.intern_sized())
}
}
impl<T: StaticType> StaticType for TraceAsString<T> {
const TYPE: Self = Self {
inner_ty: LazyInterned::new_const::<MakeType<T>>(),
trace_as_string: LazyInterned::new_const::<TraceAsStringStaticTypeHelper<T>>(),
};
const MASK_TYPE: Self::MaskType = T::MASK_TYPE;
const TYPE_PROPERTIES: TypeProperties = T::TYPE_PROPERTIES;
const MASK_TYPE_PROPERTIES: TypeProperties = T::MASK_TYPE_PROPERTIES;
}
#[doc(hidden)]
pub struct TraceAsStringWithoutGenerics;
impl<T: Type> Index<T> for TraceAsStringWithoutGenerics {
type Output = TraceAsString<T>;
fn index(&self, inner_ty: T) -> &Self::Output {
Interned::into_inner(TraceAsString::new(inner_ty).intern_sized())
}
}
#[derive(Copy, Clone, Eq, Ord, Hash, Default, Serialize, Deserialize)]
pub struct TraceAsStringSimValue<T> {
inner: T,
}
impl<T> TraceAsStringSimValue<T> {
pub const fn new(inner: T) -> Self {
Self { inner }
}
pub fn into_inner(this: Self) -> T {
let Self { inner } = this;
inner
}
}
impl<T: ValueType> ValueType for TraceAsStringSimValue<T> {
type Type = TraceAsString<T::Type>;
type ValueCategory = T::ValueCategory;
fn ty(&self) -> Self::Type {
TraceAsString::new(self.inner.ty())
}
}
impl<T: ToExpr> ToExpr for TraceAsStringSimValue<T> {
fn to_expr(&self) -> Expr<Self::Type> {
let inner = self.inner.to_expr();
ops::AsTraceAsString::new(Expr::canonical(inner), TraceAsString::new(inner.ty())).to_expr()
}
}
impl<T: ToSimValueWithType<Ty>, Ty: Type> ToSimValueWithType<TraceAsString<Ty>>
for TraceAsStringSimValue<T>
{
fn to_sim_value_with_type(&self, ty: TraceAsString<Ty>) -> SimValue<TraceAsString<Ty>> {
let inner = self.inner.to_sim_value_with_type(ty.inner_ty());
let inner = SimValue::into_value(inner);
SimValue::from_value(ty, TraceAsStringSimValue { inner })
}
fn into_sim_value_with_type(self, ty: TraceAsString<Ty>) -> SimValue<TraceAsString<Ty>> {
let inner = self.inner.into_sim_value_with_type(ty.inner_ty());
let inner = SimValue::into_value(inner);
SimValue::from_value(ty, TraceAsStringSimValue { inner })
}
}
impl<T: ToSimValue> ToSimValue for TraceAsStringSimValue<T> {
fn to_sim_value(&self) -> SimValue<Self::Type> {
self.to_sim_value_with_type(self.ty())
}
fn into_sim_value(self) -> SimValue<Self::Type> {
let ty = self.ty();
self.into_sim_value_with_type(ty)
}
}
impl<T> std::ops::Deref for TraceAsStringSimValue<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<T> std::ops::DerefMut for TraceAsStringSimValue<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl<T: fmt::Debug> fmt::Debug for TraceAsStringSimValue<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { inner } = self;
fmt::Debug::fmt(inner, f)
}
}
impl<T: fmt::Display> fmt::Display for TraceAsStringSimValue<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { inner } = self;
fmt::Display::fmt(inner, f)
}
}
impl<T: PartialOrd<U>, U> PartialOrd<TraceAsStringSimValue<U>> for TraceAsStringSimValue<T> {
fn partial_cmp(&self, other: &TraceAsStringSimValue<U>) -> Option<std::cmp::Ordering> {
let Self { inner } = self;
inner.partial_cmp(&other.inner)
}
}
impl<T: PartialEq<U>, U> PartialEq<TraceAsStringSimValue<U>> for TraceAsStringSimValue<T> {
fn eq(&self, other: &TraceAsStringSimValue<U>) -> bool {
let Self { inner } = self;
*inner == other.inner
}
}
impl<T: Type + Fold<State>, State: ?Sized + Folder> Fold<State> for TraceAsString<T> {
fn fold(self, state: &mut State) -> Result<Self, State::Error> {
state.fold_trace_as_string(self)
}
fn default_fold(self, state: &mut State) -> Result<Self, State::Error> {
Ok(self.with_new_inner_ty(self.interned_inner_ty().fold(state)?))
}
}
impl<T: Type + Visit<State>, State: ?Sized + Visitor> Visit<State> for TraceAsString<T> {
fn visit(&self, state: &mut State) -> Result<(), <State as Visitor>::Error> {
state.visit_trace_as_string(self)
}
fn default_visit(&self, state: &mut State) -> Result<(), <State as Visitor>::Error> {
self.interned_inner_ty().visit(state)
}
}

View file

@ -12,7 +12,8 @@ use crate::{
prelude::PhantomConst,
reset::{AsyncReset, Reset, SyncReset},
sim::value::DynSimOnly,
ty::{BaseType, CanonicalType},
ty::{BaseType, CanonicalType, TraceAsString, TraceAsStringTrait},
util::serde_by_id::SerdeById,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@ -65,6 +66,10 @@ pub(crate) enum SerdeCanonicalType<
Clock,
PhantomConst(ThePhantomConst),
DynSimOnly(DynSimOnly),
TraceAsString {
inner_ty: Interned<CanonicalType>,
trace_as_string: SerdeById<Interned<dyn TraceAsStringTrait>>,
},
}
impl<ArrayElement, PhantomConstInner> SerdeCanonicalType<ArrayElement, PhantomConstInner> {
@ -82,6 +87,7 @@ impl<ArrayElement, PhantomConstInner> SerdeCanonicalType<ArrayElement, PhantomCo
Self::Clock => "a Clock",
Self::PhantomConst(_) => "a PhantomConst",
Self::DynSimOnly(_) => "a SimOnlyValue",
Self::TraceAsString { .. } => "a TraceAsString",
}
}
}
@ -109,6 +115,15 @@ impl<T: BaseType> From<T> for SerdeCanonicalType {
CanonicalType::Clock(Clock {}) => Self::Clock,
CanonicalType::PhantomConst(ty) => Self::PhantomConst(SerdePhantomConst(ty.get())),
CanonicalType::DynSimOnly(ty) => Self::DynSimOnly(ty),
CanonicalType::TraceAsString(TraceAsString {
inner_ty,
trace_as_string,
}) => Self::TraceAsString {
inner_ty: inner_ty.interned(),
trace_as_string: SerdeById {
inner: trace_as_string.interned(),
},
},
}
}
}
@ -130,6 +145,13 @@ impl From<SerdeCanonicalType> for CanonicalType {
Self::PhantomConst(PhantomConst::new_interned(value.0))
}
SerdeCanonicalType::DynSimOnly(value) => Self::DynSimOnly(value),
SerdeCanonicalType::TraceAsString {
inner_ty,
trace_as_string,
} => Self::TraceAsString(TraceAsString {
inner_ty: crate::intern::LazyInterned::Interned(inner_ty),
trace_as_string: crate::intern::LazyInterned::Interned(trace_as_string.inner),
}),
}
}
}

View file

@ -46,3 +46,4 @@ pub(crate) use misc::{InternedStrCompareAsStr, chain, copy_le_bytes_to_bitslice}
pub mod job_server;
pub mod prefix_sum;
pub mod ready_valid;
pub(crate) mod serde_by_id;

View file

@ -0,0 +1,234 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information
use crate::util::HashMap;
use hashbrown::hash_map::Entry;
use serde::{Deserialize, Serialize, de::Error};
use std::{
any::TypeId,
borrow::Cow,
fmt::Write,
hash::{BuildHasher, Hash, Hasher},
marker::PhantomData,
sync::Mutex,
};
pub(crate) struct SerdeByIdProperties<T: SerdeByIdTrait> {
type_id: TypeId,
type_name: &'static str,
_phantom: PhantomData<fn(T) -> T>,
}
impl<T: SerdeByIdTrait> Clone for SerdeByIdProperties<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T: SerdeByIdTrait> Copy for SerdeByIdProperties<T> {}
impl<T: SerdeByIdTrait> SerdeByIdProperties<T> {
pub fn of<U: ?Sized + 'static>() -> Self {
Self {
type_id: TypeId::of::<U>(),
type_name: std::any::type_name::<U>(),
_phantom: PhantomData,
}
}
}
pub(crate) trait SerdeByIdTrait: Hash + Eq + Clone + 'static + Send {
fn serde_by_id_properties(&self) -> SerdeByIdProperties<Self>;
fn static_table() -> &'static SerdeByIdTable<Self>;
const NAME: &'static str;
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
#[serde(transparent)]
struct SerdeRandomId([u32; 4]);
#[derive(Serialize, Deserialize)]
pub(crate) struct SerdeId<'a, T: SerdeByIdTrait> {
random_id: SerdeRandomId,
#[serde(borrow)]
type_name: Cow<'a, str>,
#[serde(skip)]
_phantom: PhantomData<fn(T) -> T>,
}
impl<'a, T: SerdeByIdTrait> Clone for SerdeId<'a, T> {
fn clone(&self) -> Self {
Self {
random_id: self.random_id,
type_name: self.type_name.clone(),
_phantom: PhantomData,
}
}
}
impl<'a, T: SerdeByIdTrait> Eq for SerdeId<'a, T> {}
impl<'a, 'b, T: SerdeByIdTrait> PartialEq<SerdeId<'b, T>> for SerdeId<'a, T> {
fn eq(&self, other: &SerdeId<'b, T>) -> bool {
let Self {
random_id,
type_name,
_phantom: _,
} = self;
*random_id == other.random_id && *type_name == other.type_name
}
}
impl<'a, T: SerdeByIdTrait> Hash for SerdeId<'a, T> {
fn hash<H: Hasher>(&self, state: &mut H) {
let Self {
random_id,
type_name: _,
_phantom: _,
} = self;
random_id.hash(state);
}
}
struct SerdeByIdTableRest<T: SerdeByIdTrait> {
from_serde: HashMap<SerdeId<'static, T>, T>,
serde_id_random_state: std::hash::RandomState,
buffer: String,
}
impl<T: SerdeByIdTrait> Default for SerdeByIdTableRest<T> {
fn default() -> Self {
Self {
from_serde: Default::default(),
serde_id_random_state: Default::default(),
buffer: Default::default(),
}
}
}
impl<T: SerdeByIdTrait> SerdeByIdTableRest<T> {
fn add_new(&mut self, value: T) -> SerdeId<'static, T> {
let properties = value.serde_by_id_properties();
let mut try_number = 0u64;
let mut hasher = self.serde_id_random_state.build_hasher();
// extract more bits of randomness from TypeId -- its Hash impl only hashes 64-bits
write!(self.buffer, "{:?}", properties.type_id).expect("shouldn't ever fail");
self.buffer.hash(&mut hasher);
loop {
let mut hasher = hasher.clone();
try_number.hash(&mut hasher);
try_number += 1;
let key = SerdeId {
random_id: SerdeRandomId(std::array::from_fn(|i| {
let mut hasher = hasher.clone();
i.hash(&mut hasher);
hasher.finish() as u32
})),
type_name: Cow::Borrowed(properties.type_name),
_phantom: PhantomData,
};
match self.from_serde.entry(key) {
Entry::Occupied(_) => continue,
Entry::Vacant(e) => {
let key = e.key().clone();
e.insert(value);
return key;
}
}
}
}
}
pub(crate) struct SerdeByIdTableMut<T: SerdeByIdTrait> {
to_serde: HashMap<T, SerdeId<'static, T>>,
rest: SerdeByIdTableRest<T>,
}
impl<T: SerdeByIdTrait> Default for SerdeByIdTableMut<T> {
fn default() -> Self {
Self {
to_serde: Default::default(),
rest: Default::default(),
}
}
}
impl<T: SerdeByIdTrait> SerdeByIdTableMut<T> {
pub(crate) fn to_serde(&mut self, value: &T) -> SerdeId<'static, T> {
if let Some(retval) = self.to_serde.get(value) {
return retval.clone();
}
self.to_serde_insert(value)
}
#[cold]
fn to_serde_insert(&mut self, value: &T) -> SerdeId<'static, T> {
let value = value.clone();
let retval = self.rest.add_new(value.clone());
self.to_serde.insert(value, retval.clone());
retval
}
pub(crate) fn from_serde(&self, id: &SerdeId<'_, T>) -> Option<T> {
self.rest.from_serde.get(id).cloned()
}
}
pub(crate) struct SerdeByIdTable<T: SerdeByIdTrait>(Mutex<Option<SerdeByIdTableMut<T>>>);
impl<T: SerdeByIdTrait> SerdeByIdTable<T> {
pub(crate) const fn new() -> Self {
Self(Mutex::new(None))
}
pub(crate) fn to_serde(&self, value: &T) -> SerdeId<'static, T> {
self.0
.lock()
.expect("shouldn't be poison")
.get_or_insert_with(
#[cold]
|| Default::default(),
)
.to_serde(value)
}
pub(crate) fn from_serde(&self, id: &SerdeId<'_, T>) -> Option<T> {
self.0
.lock()
.expect("shouldn't be poison")
.get_or_insert_with(
#[cold]
|| Default::default(),
)
.from_serde(id)
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default, Ord, PartialOrd)]
pub(crate) struct SerdeById<T: SerdeByIdTrait> {
pub(crate) inner: T,
}
impl<'de, T: SerdeByIdTrait> Deserialize<'de> for SerdeById<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let id = SerdeId::deserialize(deserializer)?;
let inner = T::static_table().from_serde(&id).ok_or_else(|| {
D::Error::custom(format_args!(
"doesn't match any {} that was serialized this time this program was run: type_name={:?}",
T::NAME,
id.type_name,
))
})?;
Ok(Self { inner })
}
}
impl<T: SerdeByIdTrait> Serialize for SerdeById<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
T::static_table()
.to_serde(&self.inner)
.serialize(serializer)
}
}

View file

@ -546,7 +546,7 @@ impl<W: fmt::Write> Visitor for XdcFileWriter<W> {
base.source_location(),
)? {},
}
match base.canonical_ty() {
match base.canonical_ty().unwrap_transparent_types() {
CanonicalType::UInt(_)
| CanonicalType::SInt(_)
| CanonicalType::Bool(_)
@ -563,6 +563,9 @@ impl<W: fmt::Write> Visitor for XdcFileWriter<W> {
v,
base.source_location(),
)? {},
CanonicalType::TraceAsString(_) => {
unreachable!("handled by unwrap_transparent_types")
}
}
self.required_dont_touch_targets.insert(target);
match v {

View file

@ -0,0 +1,166 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information
use fayalite::{prelude::*, ty::SimValueDebug};
use std::fmt;
#[hdl(outline_generated)]
struct MyStruct0<T, S: Size> {
v: T,
a: ArrayType<UInt<8>, S>,
}
#[hdl]
#[test]
fn check_my_struct0() {
let ty = MyStruct0[UInt[8]][3];
assert_eq!(
format!("{ty:?}"),
"MyStruct0 { v: UInt<8>, a: Array<UInt<8>, 3> }",
);
assert_eq!(
format!("{:?}", ty.mask_type()),
"MaskType<MyStruct0> { v: Bool, a: Array<Bool, 3> }",
);
let v = #[hdl(sim)]
MyStruct0::<_, _> {
v: 0x23u8,
a: [1u8, 2, 3],
};
assert_eq!(
format!("{v:?}"),
"MyStruct0 { v: 0x23_u8, a: [0x1_u8, 0x2_u8, 0x3_u8] }",
);
}
#[hdl(outline_generated, custom_debug())]
struct MyStruct1<T, S: Size> {
v: T,
a: ArrayType<UInt<8>, S>,
}
impl<T: Type, S: Size> fmt::Debug for MyStruct1<T, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { v, a } = self;
f.debug_struct("Custom<MyStruct1>")
.field("v", v)
.field("a", a)
.finish()
}
}
impl<T: Type, S: Size> SimValueDebug for MyStruct1<T, S> {
#[hdl]
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
#[hdl(sim)]
let Self { v, a } = value;
f.debug_struct("Custom<MyStruct1>")
.field("v", &v)
.field("a", &a)
.finish()
}
}
#[hdl]
#[test]
fn check_my_struct1() {
let ty = MyStruct1[UInt[8]][3];
assert_eq!(
format!("{ty:?}"),
"Custom<MyStruct1> { v: UInt<8>, a: Array<UInt<8>, 3> }",
);
assert_eq!(
format!("{:?}", ty.mask_type()),
"MaskType<MyStruct1> { v: Bool, a: Array<Bool, 3> }",
);
let v = #[hdl(sim)]
MyStruct1::<_, _> {
v: 0x23u8,
a: [1u8, 2, 3],
};
assert_eq!(
format!("{v:?}"),
"Custom<MyStruct1> { v: 0x23_u8, a: [0x1_u8, 0x2_u8, 0x3_u8] }",
);
}
#[hdl(outline_generated)]
enum MyEnum0<T, S: Size> {
Unit,
V(T),
A(ArrayType<UInt<8>, S>),
}
#[hdl]
#[test]
fn check_my_enum0() {
let ty = MyEnum0[UInt[8]][3];
assert_eq!(
format!("{ty:?}"),
"MyEnum0 { Unit: (), V: UInt<8>, A: Array<UInt<8>, 3> }",
);
let v = #[hdl(sim)]
ty.Unit();
assert_eq!(format!("{v:?}"), "Unit");
let v = #[hdl(sim)]
ty.V(0x23u8);
assert_eq!(format!("{v:?}"), "V(0x23_u8)");
let v = #[hdl(sim)]
ty.A([1u8, 2, 3]);
assert_eq!(format!("{v:?}"), "A([0x1_u8, 0x2_u8, 0x3_u8])");
}
#[hdl(outline_generated, custom_debug())]
enum MyEnum1<T, S: Size> {
Unit,
V(T),
A(ArrayType<UInt<8>, S>),
}
impl<T: Type, S: Size> fmt::Debug for MyEnum1<T, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { Unit, V, A } = self;
f.debug_struct("Custom<MyEnum1>")
.field("Unit", Unit)
.field("V", V)
.field("A", A)
.finish()
}
}
impl<T: Type, S: Size> SimValueDebug for MyEnum1<T, S> {
#[hdl]
fn sim_value_debug(
value: &<Self as Type>::SimValue,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
type SimValueT<T> = <T as Type>::SimValue;
match value {
SimValueT::<Self>::Unit(_) => f.write_str("MyEnum1::Unit"),
SimValueT::<Self>::V(v, _) => f.debug_tuple("MyEnum1::V").field(v).finish(),
SimValueT::<Self>::A(a, _) => f.debug_tuple("MyEnum1::A").field(a).finish(),
SimValueT::<Self>::Unknown(_) => f.write_str("MyEnum1::Unknown"),
}
}
}
#[hdl]
#[test]
fn check_my_enum1() {
let ty = MyEnum1[UInt[8]][3];
assert_eq!(
format!("{ty:?}"),
"Custom<MyEnum1> { Unit: (), V: UInt<8>, A: Array<UInt<8>, 3> }",
);
let v = #[hdl(sim)]
ty.Unit();
assert_eq!(format!("{v:?}"), "MyEnum1::Unit");
let v = #[hdl(sim)]
ty.V(0x23u8);
assert_eq!(format!("{v:?}"), "MyEnum1::V(0x23_u8)");
let v = #[hdl(sim)]
ty.A([1u8, 2, 3]);
assert_eq!(format!("{v:?}"), "MyEnum1::A([0x1_u8, 0x2_u8, 0x3_u8])");
}

View file

@ -13,7 +13,7 @@ use fayalite::{
};
use serde_json::json;
#[hdl(outline_generated)]
#[hdl(outline_generated, cmp_eq)]
pub enum TestEnum {
A,
B(UInt<8>),
@ -679,6 +679,366 @@ circuit check_enum_literals:
};
}
#[hdl_module(outline_generated)]
pub fn check_enum_cmp_eq() {
#[hdl]
let lhs: TestEnum = m.input();
#[hdl]
let rhs: TestEnum = m.input();
#[hdl]
let eq: Bool = m.output();
connect(eq, lhs.cmp_eq(rhs));
}
#[test]
fn test_enum_cmp_eq() {
let _n = SourceLocation::normalize_files_for_tests();
let m = check_enum_cmp_eq();
dbg!(m);
#[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
assert_export_firrtl! {
m =>
options: ExportOptions {
simplify_enums: None,
..ExportOptions::default()
},
"/test/check_enum_cmp_eq.fir": r"FIRRTL version 3.2.0
circuit check_enum_cmp_eq:
type Ty0 = {|A, B: UInt<8>, C: UInt<1>[3]|}
module check_enum_cmp_eq: @[module-XXXXXXXXXX.rs 1:1]
input lhs: Ty0 @[module-XXXXXXXXXX.rs 2:1]
input rhs: Ty0 @[module-XXXXXXXXXX.rs 3:1]
output eq: UInt<1> @[module-XXXXXXXXXX.rs 4:1]
wire TestEnum_cmp_eq: UInt<1> @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h0) @[module-XXXXXXXXXX.rs 5:1]
match lhs: @[module-XXXXXXXXXX.rs 5:1]
A:
match rhs: @[module-XXXXXXXXXX.rs 5:1]
A:
connect TestEnum_cmp_eq, UInt<1>(0h1) @[module-XXXXXXXXXX.rs 5:1]
B(_match_arm_value):
skip
C(_match_arm_value_1):
skip
B(_match_arm_value_2):
match rhs: @[module-XXXXXXXXXX.rs 5:1]
A:
skip
B(_match_arm_value_3):
connect TestEnum_cmp_eq, eq(_match_arm_value_2, _match_arm_value_3) @[module-XXXXXXXXXX.rs 5:1]
C(_match_arm_value_4):
skip
C(_match_arm_value_5):
match rhs: @[module-XXXXXXXXXX.rs 5:1]
A:
skip
B(_match_arm_value_6):
skip
C(_match_arm_value_7):
wire _array_literal_expr: UInt<1>[3]
connect _array_literal_expr[0], eq(_match_arm_value_5[0], _match_arm_value_7[0])
connect _array_literal_expr[1], eq(_match_arm_value_5[1], _match_arm_value_7[1])
connect _array_literal_expr[2], eq(_match_arm_value_5[2], _match_arm_value_7[2])
wire _cast_array_to_bits_expr: UInt<1>[3]
connect _cast_array_to_bits_expr[0], _array_literal_expr[0]
connect _cast_array_to_bits_expr[1], _array_literal_expr[1]
connect _cast_array_to_bits_expr[2], _array_literal_expr[2]
wire _cast_to_bits_expr: UInt<3>
connect _cast_to_bits_expr, cat(_cast_array_to_bits_expr[2], cat(_cast_array_to_bits_expr[1], _cast_array_to_bits_expr[0]))
connect TestEnum_cmp_eq, andr(_cast_to_bits_expr) @[module-XXXXXXXXXX.rs 5:1]
connect eq, TestEnum_cmp_eq @[module-XXXXXXXXXX.rs 6:1]
",
};
#[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
assert_export_firrtl! {
m =>
options: ExportOptions {
simplify_enums: Some(SimplifyEnumsKind::SimplifyToEnumsWithNoBody),
..ExportOptions::default()
},
"/test/check_enum_cmp_eq.fir": r"FIRRTL version 3.2.0
circuit check_enum_cmp_eq:
type Ty0 = {|A, B, C|}
type Ty1 = {tag: Ty0, body: UInt<8>}
module check_enum_cmp_eq: @[module-XXXXXXXXXX.rs 1:1]
input lhs: Ty1 @[module-XXXXXXXXXX.rs 2:1]
input rhs: Ty1 @[module-XXXXXXXXXX.rs 3:1]
output eq: UInt<1> @[module-XXXXXXXXXX.rs 4:1]
wire TestEnum_cmp_eq: UInt<1> @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h0) @[module-XXXXXXXXXX.rs 5:1]
match lhs.tag: @[module-XXXXXXXXXX.rs 5:1]
A:
match rhs.tag: @[module-XXXXXXXXXX.rs 5:1]
A:
connect TestEnum_cmp_eq, UInt<1>(0h1) @[module-XXXXXXXXXX.rs 5:1]
B:
skip
C:
skip
B:
match rhs.tag: @[module-XXXXXXXXXX.rs 5:1]
A:
skip
B:
connect TestEnum_cmp_eq, eq(bits(lhs.body, 7, 0), bits(rhs.body, 7, 0)) @[module-XXXXXXXXXX.rs 5:1]
C:
skip
C:
match rhs.tag: @[module-XXXXXXXXXX.rs 5:1]
A:
skip
B:
skip
C:
wire _array_literal_expr: UInt<1>[3]
wire _cast_bits_to_array_expr: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr[0], _cast_bits_to_array_expr_flattened[0]
connect _cast_bits_to_array_expr_flattened[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr[1], _cast_bits_to_array_expr_flattened[1]
connect _cast_bits_to_array_expr_flattened[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr[2], _cast_bits_to_array_expr_flattened[2]
wire _cast_bits_to_array_expr_1: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_1: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_1[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_1[0], _cast_bits_to_array_expr_flattened_1[0]
connect _cast_bits_to_array_expr_flattened_1[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_1[1], _cast_bits_to_array_expr_flattened_1[1]
connect _cast_bits_to_array_expr_flattened_1[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_1[2], _cast_bits_to_array_expr_flattened_1[2]
connect _array_literal_expr[0], eq(_cast_bits_to_array_expr[0], _cast_bits_to_array_expr_1[0])
wire _cast_bits_to_array_expr_2: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_2: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_2[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_2[0], _cast_bits_to_array_expr_flattened_2[0]
connect _cast_bits_to_array_expr_flattened_2[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_flattened_2[1]
connect _cast_bits_to_array_expr_flattened_2[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_2[2], _cast_bits_to_array_expr_flattened_2[2]
wire _cast_bits_to_array_expr_3: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_3: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_3[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_3[0], _cast_bits_to_array_expr_flattened_3[0]
connect _cast_bits_to_array_expr_flattened_3[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_3[1], _cast_bits_to_array_expr_flattened_3[1]
connect _cast_bits_to_array_expr_flattened_3[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_3[2], _cast_bits_to_array_expr_flattened_3[2]
connect _array_literal_expr[1], eq(_cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_3[1])
wire _cast_bits_to_array_expr_4: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_4: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_4[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_4[0], _cast_bits_to_array_expr_flattened_4[0]
connect _cast_bits_to_array_expr_flattened_4[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_4[1], _cast_bits_to_array_expr_flattened_4[1]
connect _cast_bits_to_array_expr_flattened_4[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_flattened_4[2]
wire _cast_bits_to_array_expr_5: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_5: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_5[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_5[0], _cast_bits_to_array_expr_flattened_5[0]
connect _cast_bits_to_array_expr_flattened_5[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_5[1], _cast_bits_to_array_expr_flattened_5[1]
connect _cast_bits_to_array_expr_flattened_5[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_5[2], _cast_bits_to_array_expr_flattened_5[2]
connect _array_literal_expr[2], eq(_cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_5[2])
wire _cast_array_to_bits_expr: UInt<1>[3]
connect _cast_array_to_bits_expr[0], _array_literal_expr[0]
connect _cast_array_to_bits_expr[1], _array_literal_expr[1]
connect _cast_array_to_bits_expr[2], _array_literal_expr[2]
wire _cast_to_bits_expr: UInt<3>
connect _cast_to_bits_expr, cat(_cast_array_to_bits_expr[2], cat(_cast_array_to_bits_expr[1], _cast_array_to_bits_expr[0]))
connect TestEnum_cmp_eq, andr(_cast_to_bits_expr) @[module-XXXXXXXXXX.rs 5:1]
connect eq, TestEnum_cmp_eq @[module-XXXXXXXXXX.rs 6:1]
",
};
#[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
assert_export_firrtl! {
m =>
options: ExportOptions {
simplify_enums: Some(SimplifyEnumsKind::ReplaceWithBundleOfUInts),
..ExportOptions::default()
},
"/test/check_enum_cmp_eq.fir": r"FIRRTL version 3.2.0
circuit check_enum_cmp_eq:
type Ty0 = {tag: UInt<2>, body: UInt<8>}
module check_enum_cmp_eq: @[module-XXXXXXXXXX.rs 1:1]
input lhs: Ty0 @[module-XXXXXXXXXX.rs 2:1]
input rhs: Ty0 @[module-XXXXXXXXXX.rs 3:1]
output eq: UInt<1> @[module-XXXXXXXXXX.rs 4:1]
wire TestEnum_cmp_eq: UInt<1> @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h0) @[module-XXXXXXXXXX.rs 5:1]
when eq(lhs.tag, UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
when eq(rhs.tag, UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h1) @[module-XXXXXXXXXX.rs 5:1]
else when eq(rhs.tag, UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(lhs.tag, UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
when eq(rhs.tag, UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(rhs.tag, UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, eq(bits(lhs.body, 7, 0), bits(rhs.body, 7, 0)) @[module-XXXXXXXXXX.rs 5:1]
else when eq(rhs.tag, UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(rhs.tag, UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
skip
else:
wire _array_literal_expr: UInt<1>[3]
wire _cast_bits_to_array_expr: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr[0], _cast_bits_to_array_expr_flattened[0]
connect _cast_bits_to_array_expr_flattened[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr[1], _cast_bits_to_array_expr_flattened[1]
connect _cast_bits_to_array_expr_flattened[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr[2], _cast_bits_to_array_expr_flattened[2]
wire _cast_bits_to_array_expr_1: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_1: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_1[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_1[0], _cast_bits_to_array_expr_flattened_1[0]
connect _cast_bits_to_array_expr_flattened_1[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_1[1], _cast_bits_to_array_expr_flattened_1[1]
connect _cast_bits_to_array_expr_flattened_1[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_1[2], _cast_bits_to_array_expr_flattened_1[2]
connect _array_literal_expr[0], eq(_cast_bits_to_array_expr[0], _cast_bits_to_array_expr_1[0])
wire _cast_bits_to_array_expr_2: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_2: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_2[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_2[0], _cast_bits_to_array_expr_flattened_2[0]
connect _cast_bits_to_array_expr_flattened_2[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_flattened_2[1]
connect _cast_bits_to_array_expr_flattened_2[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_2[2], _cast_bits_to_array_expr_flattened_2[2]
wire _cast_bits_to_array_expr_3: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_3: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_3[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_3[0], _cast_bits_to_array_expr_flattened_3[0]
connect _cast_bits_to_array_expr_flattened_3[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_3[1], _cast_bits_to_array_expr_flattened_3[1]
connect _cast_bits_to_array_expr_flattened_3[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_3[2], _cast_bits_to_array_expr_flattened_3[2]
connect _array_literal_expr[1], eq(_cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_3[1])
wire _cast_bits_to_array_expr_4: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_4: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_4[0], bits(bits(lhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_4[0], _cast_bits_to_array_expr_flattened_4[0]
connect _cast_bits_to_array_expr_flattened_4[1], bits(bits(lhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_4[1], _cast_bits_to_array_expr_flattened_4[1]
connect _cast_bits_to_array_expr_flattened_4[2], bits(bits(lhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_flattened_4[2]
wire _cast_bits_to_array_expr_5: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_5: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_5[0], bits(bits(rhs.body, 2, 0), 0, 0)
connect _cast_bits_to_array_expr_5[0], _cast_bits_to_array_expr_flattened_5[0]
connect _cast_bits_to_array_expr_flattened_5[1], bits(bits(rhs.body, 2, 0), 1, 1)
connect _cast_bits_to_array_expr_5[1], _cast_bits_to_array_expr_flattened_5[1]
connect _cast_bits_to_array_expr_flattened_5[2], bits(bits(rhs.body, 2, 0), 2, 2)
connect _cast_bits_to_array_expr_5[2], _cast_bits_to_array_expr_flattened_5[2]
connect _array_literal_expr[2], eq(_cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_5[2])
wire _cast_array_to_bits_expr: UInt<1>[3]
connect _cast_array_to_bits_expr[0], _array_literal_expr[0]
connect _cast_array_to_bits_expr[1], _array_literal_expr[1]
connect _cast_array_to_bits_expr[2], _array_literal_expr[2]
wire _cast_to_bits_expr: UInt<3>
connect _cast_to_bits_expr, cat(_cast_array_to_bits_expr[2], cat(_cast_array_to_bits_expr[1], _cast_array_to_bits_expr[0]))
connect TestEnum_cmp_eq, andr(_cast_to_bits_expr) @[module-XXXXXXXXXX.rs 5:1]
connect eq, TestEnum_cmp_eq @[module-XXXXXXXXXX.rs 6:1]
",
};
#[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
assert_export_firrtl! {
m =>
options: ExportOptions {
simplify_enums: Some(SimplifyEnumsKind::ReplaceWithUInt),
..ExportOptions::default()
},
"/test/check_enum_cmp_eq.fir": r"FIRRTL version 3.2.0
circuit check_enum_cmp_eq:
module check_enum_cmp_eq: @[module-XXXXXXXXXX.rs 1:1]
input lhs: UInt<10> @[module-XXXXXXXXXX.rs 2:1]
input rhs: UInt<10> @[module-XXXXXXXXXX.rs 3:1]
output eq: UInt<1> @[module-XXXXXXXXXX.rs 4:1]
wire TestEnum_cmp_eq: UInt<1> @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h0) @[module-XXXXXXXXXX.rs 5:1]
when eq(bits(lhs, 1, 0), UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
when eq(bits(rhs, 1, 0), UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, UInt<1>(0h1) @[module-XXXXXXXXXX.rs 5:1]
else when eq(bits(rhs, 1, 0), UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(bits(lhs, 1, 0), UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
when eq(bits(rhs, 1, 0), UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(bits(rhs, 1, 0), UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
connect TestEnum_cmp_eq, eq(bits(bits(lhs, 9, 2), 7, 0), bits(bits(rhs, 9, 2), 7, 0)) @[module-XXXXXXXXXX.rs 5:1]
else when eq(bits(rhs, 1, 0), UInt<2>(0h0)): @[module-XXXXXXXXXX.rs 5:1]
skip
else when eq(bits(rhs, 1, 0), UInt<2>(0h1)): @[module-XXXXXXXXXX.rs 5:1]
skip
else:
wire _array_literal_expr: UInt<1>[3]
wire _cast_bits_to_array_expr: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened[0], bits(bits(bits(lhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr[0], _cast_bits_to_array_expr_flattened[0]
connect _cast_bits_to_array_expr_flattened[1], bits(bits(bits(lhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr[1], _cast_bits_to_array_expr_flattened[1]
connect _cast_bits_to_array_expr_flattened[2], bits(bits(bits(lhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr[2], _cast_bits_to_array_expr_flattened[2]
wire _cast_bits_to_array_expr_1: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_1: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_1[0], bits(bits(bits(rhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr_1[0], _cast_bits_to_array_expr_flattened_1[0]
connect _cast_bits_to_array_expr_flattened_1[1], bits(bits(bits(rhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr_1[1], _cast_bits_to_array_expr_flattened_1[1]
connect _cast_bits_to_array_expr_flattened_1[2], bits(bits(bits(rhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr_1[2], _cast_bits_to_array_expr_flattened_1[2]
connect _array_literal_expr[0], eq(_cast_bits_to_array_expr[0], _cast_bits_to_array_expr_1[0])
wire _cast_bits_to_array_expr_2: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_2: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_2[0], bits(bits(bits(lhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr_2[0], _cast_bits_to_array_expr_flattened_2[0]
connect _cast_bits_to_array_expr_flattened_2[1], bits(bits(bits(lhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_flattened_2[1]
connect _cast_bits_to_array_expr_flattened_2[2], bits(bits(bits(lhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr_2[2], _cast_bits_to_array_expr_flattened_2[2]
wire _cast_bits_to_array_expr_3: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_3: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_3[0], bits(bits(bits(rhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr_3[0], _cast_bits_to_array_expr_flattened_3[0]
connect _cast_bits_to_array_expr_flattened_3[1], bits(bits(bits(rhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr_3[1], _cast_bits_to_array_expr_flattened_3[1]
connect _cast_bits_to_array_expr_flattened_3[2], bits(bits(bits(rhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr_3[2], _cast_bits_to_array_expr_flattened_3[2]
connect _array_literal_expr[1], eq(_cast_bits_to_array_expr_2[1], _cast_bits_to_array_expr_3[1])
wire _cast_bits_to_array_expr_4: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_4: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_4[0], bits(bits(bits(lhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr_4[0], _cast_bits_to_array_expr_flattened_4[0]
connect _cast_bits_to_array_expr_flattened_4[1], bits(bits(bits(lhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr_4[1], _cast_bits_to_array_expr_flattened_4[1]
connect _cast_bits_to_array_expr_flattened_4[2], bits(bits(bits(lhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_flattened_4[2]
wire _cast_bits_to_array_expr_5: UInt<1>[3]
wire _cast_bits_to_array_expr_flattened_5: UInt<1>[3]
connect _cast_bits_to_array_expr_flattened_5[0], bits(bits(bits(rhs, 9, 2), 2, 0), 0, 0)
connect _cast_bits_to_array_expr_5[0], _cast_bits_to_array_expr_flattened_5[0]
connect _cast_bits_to_array_expr_flattened_5[1], bits(bits(bits(rhs, 9, 2), 2, 0), 1, 1)
connect _cast_bits_to_array_expr_5[1], _cast_bits_to_array_expr_flattened_5[1]
connect _cast_bits_to_array_expr_flattened_5[2], bits(bits(bits(rhs, 9, 2), 2, 0), 2, 2)
connect _cast_bits_to_array_expr_5[2], _cast_bits_to_array_expr_flattened_5[2]
connect _array_literal_expr[2], eq(_cast_bits_to_array_expr_4[2], _cast_bits_to_array_expr_5[2])
wire _cast_array_to_bits_expr: UInt<1>[3]
connect _cast_array_to_bits_expr[0], _array_literal_expr[0]
connect _cast_array_to_bits_expr[1], _array_literal_expr[1]
connect _cast_array_to_bits_expr[2], _array_literal_expr[2]
wire _cast_to_bits_expr: UInt<3>
connect _cast_to_bits_expr, cat(_cast_array_to_bits_expr[2], cat(_cast_array_to_bits_expr[1], _cast_array_to_bits_expr[0]))
connect TestEnum_cmp_eq, andr(_cast_to_bits_expr) @[module-XXXXXXXXXX.rs 5:1]
connect eq, TestEnum_cmp_eq @[module-XXXXXXXXXX.rs 6:1]
",
};
}
#[hdl_module(outline_generated)]
pub fn check_struct_enum_match() {
#[hdl]

File diff suppressed because it is too large Load diff

View file

@ -1218,6 +1218,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xff,
last_state: 0xff,
},
@ -1227,6 +1228,7 @@ Simulation {
index: StatePartIndex<BigSlots>(1),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x7f,
last_state: 0x7f,
},
@ -1236,6 +1238,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x3f,
last_state: 0x3f,
},
@ -1245,6 +1248,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x1f,
last_state: 0x1f,
},
@ -1254,6 +1258,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x0f,
last_state: 0x0f,
},
@ -1263,6 +1268,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x07,
last_state: 0x07,
},
@ -1272,6 +1278,7 @@ Simulation {
index: StatePartIndex<BigSlots>(6),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x03,
last_state: 0x03,
},
@ -1281,6 +1288,7 @@ Simulation {
index: StatePartIndex<BigSlots>(7),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x01,
last_state: 0x01,
},
@ -1290,6 +1298,7 @@ Simulation {
index: StatePartIndex<BigSlots>(8),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -1299,6 +1308,7 @@ Simulation {
index: StatePartIndex<BigSlots>(9),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x80,
last_state: 0x80,
},
@ -1308,6 +1318,7 @@ Simulation {
index: StatePartIndex<BigSlots>(10),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xc0,
last_state: 0xc0,
},
@ -1317,6 +1328,7 @@ Simulation {
index: StatePartIndex<BigSlots>(11),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe0,
last_state: 0xe0,
},
@ -1326,6 +1338,7 @@ Simulation {
index: StatePartIndex<BigSlots>(12),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf0,
last_state: 0xf0,
},
@ -1335,6 +1348,7 @@ Simulation {
index: StatePartIndex<BigSlots>(13),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf8,
last_state: 0xf8,
},
@ -1344,6 +1358,7 @@ Simulation {
index: StatePartIndex<BigSlots>(14),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfc,
last_state: 0xfc,
},
@ -1353,6 +1368,7 @@ Simulation {
index: StatePartIndex<BigSlots>(15),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfe,
last_state: 0xfe,
},
@ -1362,6 +1378,7 @@ Simulation {
index: StatePartIndex<BigSlots>(16),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xff,
last_state: 0xff,
},
@ -1371,6 +1388,7 @@ Simulation {
index: StatePartIndex<BigSlots>(17),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x7f,
last_state: 0x7f,
},
@ -1380,6 +1398,7 @@ Simulation {
index: StatePartIndex<BigSlots>(18),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x3f,
last_state: 0x3f,
},
@ -1389,6 +1408,7 @@ Simulation {
index: StatePartIndex<BigSlots>(19),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x1f,
last_state: 0x1f,
},
@ -1398,6 +1418,7 @@ Simulation {
index: StatePartIndex<BigSlots>(20),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x0f,
last_state: 0x0f,
},
@ -1407,6 +1428,7 @@ Simulation {
index: StatePartIndex<BigSlots>(21),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x07,
last_state: 0x07,
},
@ -1416,6 +1438,7 @@ Simulation {
index: StatePartIndex<BigSlots>(22),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x03,
last_state: 0x03,
},
@ -1425,6 +1448,7 @@ Simulation {
index: StatePartIndex<BigSlots>(23),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x01,
last_state: 0x01,
},
@ -1434,6 +1458,7 @@ Simulation {
index: StatePartIndex<BigSlots>(24),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -1443,6 +1468,7 @@ Simulation {
index: StatePartIndex<BigSlots>(25),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x80,
last_state: 0x80,
},
@ -1452,6 +1478,7 @@ Simulation {
index: StatePartIndex<BigSlots>(26),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xc0,
last_state: 0xc0,
},
@ -1461,6 +1488,7 @@ Simulation {
index: StatePartIndex<BigSlots>(27),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe0,
last_state: 0xe0,
},
@ -1470,6 +1498,7 @@ Simulation {
index: StatePartIndex<BigSlots>(28),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf0,
last_state: 0xf0,
},
@ -1479,6 +1508,7 @@ Simulation {
index: StatePartIndex<BigSlots>(29),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf8,
last_state: 0xf8,
},
@ -1488,6 +1518,7 @@ Simulation {
index: StatePartIndex<BigSlots>(30),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfc,
last_state: 0xfc,
},
@ -1497,6 +1528,7 @@ Simulation {
index: StatePartIndex<BigSlots>(31),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfe,
last_state: 0xe1,
},
@ -1506,6 +1538,7 @@ Simulation {
index: StatePartIndex<BigSlots>(32),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -1515,6 +1548,7 @@ Simulation {
index: StatePartIndex<BigSlots>(33),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xff,
last_state: 0xff,
},
@ -1524,6 +1558,7 @@ Simulation {
index: StatePartIndex<BigSlots>(34),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x10,
last_state: 0x0f,
},
@ -1533,6 +1568,7 @@ Simulation {
index: StatePartIndex<BigSlots>(35),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0xe1,
},
@ -1541,6 +1577,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(36),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1550,6 +1587,7 @@ Simulation {
index: StatePartIndex<BigSlots>(37),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xff,
last_state: 0xff,
},
@ -1559,6 +1597,7 @@ Simulation {
index: StatePartIndex<BigSlots>(38),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x7f,
last_state: 0x7f,
},
@ -1568,6 +1607,7 @@ Simulation {
index: StatePartIndex<BigSlots>(39),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x3f,
last_state: 0x3f,
},
@ -1577,6 +1617,7 @@ Simulation {
index: StatePartIndex<BigSlots>(40),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x1f,
last_state: 0x1f,
},
@ -1586,6 +1627,7 @@ Simulation {
index: StatePartIndex<BigSlots>(41),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x0f,
last_state: 0x0f,
},
@ -1595,6 +1637,7 @@ Simulation {
index: StatePartIndex<BigSlots>(42),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x07,
last_state: 0x07,
},
@ -1604,6 +1647,7 @@ Simulation {
index: StatePartIndex<BigSlots>(43),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x03,
last_state: 0x03,
},
@ -1613,6 +1657,7 @@ Simulation {
index: StatePartIndex<BigSlots>(44),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x01,
last_state: 0x01,
},
@ -1622,6 +1667,7 @@ Simulation {
index: StatePartIndex<BigSlots>(45),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -1631,6 +1677,7 @@ Simulation {
index: StatePartIndex<BigSlots>(46),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x80,
last_state: 0x80,
},
@ -1640,6 +1687,7 @@ Simulation {
index: StatePartIndex<BigSlots>(47),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xc0,
last_state: 0xc0,
},
@ -1649,6 +1697,7 @@ Simulation {
index: StatePartIndex<BigSlots>(48),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe0,
last_state: 0xe0,
},
@ -1658,6 +1707,7 @@ Simulation {
index: StatePartIndex<BigSlots>(49),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf0,
last_state: 0xf0,
},
@ -1667,6 +1717,7 @@ Simulation {
index: StatePartIndex<BigSlots>(50),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xf8,
last_state: 0xf8,
},
@ -1676,6 +1727,7 @@ Simulation {
index: StatePartIndex<BigSlots>(51),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfc,
last_state: 0xfc,
},
@ -1685,6 +1737,7 @@ Simulation {
index: StatePartIndex<BigSlots>(52),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xfe,
last_state: 0xe1,
},

View file

@ -155,6 +155,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -163,6 +164,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},

View file

@ -124,6 +124,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x05,
last_state: 0x05,
},

View file

@ -175,6 +175,7 @@ Simulation {
kind: BigAsyncReset {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -183,6 +184,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},

View file

@ -332,6 +332,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -340,6 +341,7 @@ Simulation {
kind: BigAsyncReset {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -349,6 +351,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x3,
last_state: 0x2,
},
@ -358,6 +361,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x3,
last_state: 0x2,
},

View file

@ -313,6 +313,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -321,6 +322,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -330,6 +332,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x3,
last_state: 0x2,
},
@ -339,6 +342,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x3,
last_state: 0x2,
},

View file

@ -137,6 +137,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x05,
last_state: 0x05,
},
@ -146,6 +147,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x06,
last_state: 0x06,
},

View file

@ -0,0 +1,749 @@
Simulation {
state: State {
insns: Insns {
state_layout: StateLayout {
ty: TypeLayout {
small_slots: StatePartLayout<SmallSlots> {
len: 1,
debug_data: [
SlotDebugData {
name: "",
ty: Enum {
A,
B,
C,
},
},
],
..
},
big_slots: StatePartLayout<BigSlots> {
len: 33,
debug_data: [
SlotDebugData {
name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_in",
ty: UInt<8>,
},
SlotDebugData {
name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_in",
ty: UInt<8>,
},
SlotDebugData {
name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_out",
ty: UInt<8>,
},
SlotDebugData {
name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_out",
ty: UInt<8>,
},
SlotDebugData {
name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out",
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: Bool,
},
SlotDebugData {
name: ".0",
ty: UInt<2>,
},
SlotDebugData {
name: ".1",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: UInt<2>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
},
SlotDebugData {
name: "",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: Bool,
},
SlotDebugData {
name: ".0",
ty: UInt<2>,
},
SlotDebugData {
name: ".1",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: UInt<2>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
},
SlotDebugData {
name: ".0",
ty: UInt<2>,
},
SlotDebugData {
name: ".1",
ty: UInt<8>,
},
SlotDebugData {
name: "",
ty: UInt<2>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: UInt<10>,
},
SlotDebugData {
name: "",
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
},
SlotDebugData {
name: "",
ty: UInt<8>,
},
],
..
},
sim_only_slots: StatePartLayout<SimOnlySlots> {
len: 0,
debug_data: [],
layout_data: [],
..
},
},
memories: StatePartLayout<Memories> {
len: 0,
debug_data: [],
layout_data: [],
..
},
},
insns: [
// at: module-XXXXXXXXXX.rs:1:1
0: Const {
dest: StatePartIndex<BigSlots>(32), // (0x2) SlotDebugData { name: "", ty: UInt<8> },
value: 0x2,
},
1: Const {
dest: StatePartIndex<BigSlots>(27), // (0x2) SlotDebugData { name: "", ty: UInt<2> },
value: 0x2,
},
2: Copy {
dest: StatePartIndex<BigSlots>(25), // (0x2) SlotDebugData { name: ".0", ty: UInt<2> },
src: StatePartIndex<BigSlots>(27), // (0x2) SlotDebugData { name: "", ty: UInt<2> },
},
3: Copy {
dest: StatePartIndex<BigSlots>(26), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
src: StatePartIndex<BigSlots>(1), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_in", ty: UInt<8> },
},
4: Shl {
dest: StatePartIndex<BigSlots>(28), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(26), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
rhs: 2,
},
5: Or {
dest: StatePartIndex<BigSlots>(29), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(25), // (0x2) SlotDebugData { name: ".0", ty: UInt<2> },
rhs: StatePartIndex<BigSlots>(28), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
},
6: CastToUInt {
dest: StatePartIndex<BigSlots>(30), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
src: StatePartIndex<BigSlots>(29), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
dest_width: 10,
},
7: Copy {
dest: StatePartIndex<BigSlots>(31), // (0x386) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(30), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
},
8: Const {
dest: StatePartIndex<BigSlots>(20), // (0x1) SlotDebugData { name: "", ty: UInt<2> },
value: 0x1,
},
9: Copy {
dest: StatePartIndex<BigSlots>(18), // (0x1) SlotDebugData { name: ".0", ty: UInt<2> },
src: StatePartIndex<BigSlots>(20), // (0x1) SlotDebugData { name: "", ty: UInt<2> },
},
10: Copy {
dest: StatePartIndex<BigSlots>(19), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
src: StatePartIndex<BigSlots>(1), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_in", ty: UInt<8> },
},
11: Shl {
dest: StatePartIndex<BigSlots>(21), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(19), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
rhs: 2,
},
12: Or {
dest: StatePartIndex<BigSlots>(22), // (0x385) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(18), // (0x1) SlotDebugData { name: ".0", ty: UInt<2> },
rhs: StatePartIndex<BigSlots>(21), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
},
13: CastToUInt {
dest: StatePartIndex<BigSlots>(23), // (0x385) SlotDebugData { name: "", ty: UInt<10> },
src: StatePartIndex<BigSlots>(22), // (0x385) SlotDebugData { name: "", ty: UInt<10> },
dest_width: 10,
},
14: Copy {
dest: StatePartIndex<BigSlots>(24), // (0x385) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(23), // (0x385) SlotDebugData { name: "", ty: UInt<10> },
},
15: Const {
dest: StatePartIndex<BigSlots>(16), // (0x1) SlotDebugData { name: "", ty: UInt<8> },
value: 0x1,
},
16: CmpEq {
dest: StatePartIndex<BigSlots>(17), // (0x0) SlotDebugData { name: "", ty: Bool },
lhs: StatePartIndex<BigSlots>(0), // (0x2) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_in", ty: UInt<8> },
rhs: StatePartIndex<BigSlots>(16), // (0x1) SlotDebugData { name: "", ty: UInt<8> },
},
17: Const {
dest: StatePartIndex<BigSlots>(11), // (0x0) SlotDebugData { name: "", ty: UInt<2> },
value: 0x0,
},
18: Copy {
dest: StatePartIndex<BigSlots>(9), // (0x0) SlotDebugData { name: ".0", ty: UInt<2> },
src: StatePartIndex<BigSlots>(11), // (0x0) SlotDebugData { name: "", ty: UInt<2> },
},
19: Copy {
dest: StatePartIndex<BigSlots>(10), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
src: StatePartIndex<BigSlots>(1), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_in", ty: UInt<8> },
},
20: Shl {
dest: StatePartIndex<BigSlots>(12), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(10), // (0xe1) SlotDebugData { name: ".1", ty: UInt<8> },
rhs: 2,
},
21: Or {
dest: StatePartIndex<BigSlots>(13), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
lhs: StatePartIndex<BigSlots>(9), // (0x0) SlotDebugData { name: ".0", ty: UInt<2> },
rhs: StatePartIndex<BigSlots>(12), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
},
22: CastToUInt {
dest: StatePartIndex<BigSlots>(14), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
src: StatePartIndex<BigSlots>(13), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
dest_width: 10,
},
23: Copy {
dest: StatePartIndex<BigSlots>(15), // (0x384) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(14), // (0x384) SlotDebugData { name: "", ty: UInt<10> },
},
24: Const {
dest: StatePartIndex<BigSlots>(7), // (0x0) SlotDebugData { name: "", ty: UInt<8> },
value: 0x0,
},
25: CmpEq {
dest: StatePartIndex<BigSlots>(8), // (0x0) SlotDebugData { name: "", ty: Bool },
lhs: StatePartIndex<BigSlots>(0), // (0x2) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_in", ty: UInt<8> },
rhs: StatePartIndex<BigSlots>(7), // (0x0) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:7:1
26: BranchIfZero {
target: 28,
value: StatePartIndex<BigSlots>(8), // (0x0) SlotDebugData { name: "", ty: Bool },
},
// at: module-XXXXXXXXXX.rs:8:1
27: Copy {
dest: StatePartIndex<BigSlots>(4), // (0x386) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(15), // (0x384) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
},
// at: module-XXXXXXXXXX.rs:7:1
28: BranchIfNonZero {
target: 33,
value: StatePartIndex<BigSlots>(8), // (0x0) SlotDebugData { name: "", ty: Bool },
},
// at: module-XXXXXXXXXX.rs:9:1
29: BranchIfZero {
target: 31,
value: StatePartIndex<BigSlots>(17), // (0x0) SlotDebugData { name: "", ty: Bool },
},
// at: module-XXXXXXXXXX.rs:10:1
30: Copy {
dest: StatePartIndex<BigSlots>(4), // (0x386) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(24), // (0x385) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
},
// at: module-XXXXXXXXXX.rs:9:1
31: BranchIfNonZero {
target: 33,
value: StatePartIndex<BigSlots>(17), // (0x0) SlotDebugData { name: "", ty: Bool },
},
// at: module-XXXXXXXXXX.rs:11:1
32: Copy {
dest: StatePartIndex<BigSlots>(4), // (0x386) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
src: StatePartIndex<BigSlots>(31), // (0x386) SlotDebugData { name: "", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
},
// at: module-XXXXXXXXXX.rs:1:1
33: Copy {
dest: StatePartIndex<BigSlots>(5), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
src: StatePartIndex<BigSlots>(4), // (0x386) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
},
34: SliceInt {
dest: StatePartIndex<BigSlots>(6), // (0xe1) SlotDebugData { name: "", ty: UInt<8> },
src: StatePartIndex<BigSlots>(5), // (0x386) SlotDebugData { name: "", ty: UInt<10> },
start: 2,
len: 8,
},
// at: module-XXXXXXXXXX.rs:6:1
35: AndBigWithSmallImmediate {
dest: StatePartIndex<SmallSlots>(0), // (0x2 2) SlotDebugData { name: "", ty: Enum {A, B, C} },
lhs: StatePartIndex<BigSlots>(4), // (0x386) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::enum_out", ty: Enum {A(UInt<8>), B(UInt<8>), C(UInt<8>)} },
rhs: 0x3,
},
// at: module-XXXXXXXXXX.rs:12:1
36: BranchIfSmallNeImmediate {
target: 39,
lhs: StatePartIndex<SmallSlots>(0), // (0x2 2) SlotDebugData { name: "", ty: Enum {A, B, C} },
rhs: 0x0,
},
// at: module-XXXXXXXXXX.rs:13:1
37: Copy {
dest: StatePartIndex<BigSlots>(2), // (0x2) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(7), // (0x0) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:14:1
38: Copy {
dest: StatePartIndex<BigSlots>(3), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(6), // (0xe1) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:12:1
39: BranchIfSmallNeImmediate {
target: 42,
lhs: StatePartIndex<SmallSlots>(0), // (0x2 2) SlotDebugData { name: "", ty: Enum {A, B, C} },
rhs: 0x1,
},
// at: module-XXXXXXXXXX.rs:15:1
40: Copy {
dest: StatePartIndex<BigSlots>(2), // (0x2) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(16), // (0x1) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:16:1
41: Copy {
dest: StatePartIndex<BigSlots>(3), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(6), // (0xe1) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:12:1
42: BranchIfSmallNeImmediate {
target: 45,
lhs: StatePartIndex<SmallSlots>(0), // (0x2 2) SlotDebugData { name: "", ty: Enum {A, B, C} },
rhs: 0x2,
},
// at: module-XXXXXXXXXX.rs:17:1
43: Copy {
dest: StatePartIndex<BigSlots>(2), // (0x2) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::which_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(32), // (0x2) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:18:1
44: Copy {
dest: StatePartIndex<BigSlots>(3), // (0xe1) SlotDebugData { name: "InstantiatedModule(enum_with_simple_body: enum_with_simple_body).enum_with_simple_body::data_out", ty: UInt<8> },
src: StatePartIndex<BigSlots>(6), // (0xe1) SlotDebugData { name: "", ty: UInt<8> },
},
// at: module-XXXXXXXXXX.rs:1:1
45: Return,
],
..
},
pc: 45,
memory_write_log: [],
memories: StatePart {
value: [],
},
small_slots: StatePart {
value: [
2,
],
},
big_slots: StatePart {
value: [
2,
225,
2 (modified),
225 (modified),
902,
902,
225,
0,
0,
0,
225,
0,
900,
900,
900,
900,
1,
0,
1,
225,
1,
900,
901,
901,
901,
2,
225,
2,
900,
902,
902,
902,
2,
],
},
sim_only_slots: StatePart {
value: [],
},
},
io: Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
},
main_module: SimulationModuleState {
base_targets: [
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.which_in,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.data_in,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.which_out,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.data_out,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.enum_out,
],
uninitialized_ios: {},
io_targets: {
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.data_in,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.data_out,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.enum_out,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.which_in,
Instance {
name: <simulator>::enum_with_simple_body,
instantiated: Module {
name: enum_with_simple_body,
..
},
}.which_out,
},
did_initial_settle: true,
clocks_for_past: {},
},
extern_modules: [],
trace_decls: TraceModule {
name: "enum_with_simple_body",
children: [
TraceModuleIO {
name: "which_in",
child: TraceUInt {
location: TraceScalarId(0),
name: "which_in",
ty: UInt<8>,
flow: Source,
},
ty: UInt<8>,
flow: Source,
},
TraceModuleIO {
name: "data_in",
child: TraceUInt {
location: TraceScalarId(1),
name: "data_in",
ty: UInt<8>,
flow: Source,
},
ty: UInt<8>,
flow: Source,
},
TraceModuleIO {
name: "which_out",
child: TraceUInt {
location: TraceScalarId(2),
name: "which_out",
ty: UInt<8>,
flow: Sink,
},
ty: UInt<8>,
flow: Sink,
},
TraceModuleIO {
name: "data_out",
child: TraceUInt {
location: TraceScalarId(3),
name: "data_out",
ty: UInt<8>,
flow: Sink,
},
ty: UInt<8>,
flow: Sink,
},
TraceModuleIO {
name: "enum_out",
child: TraceEnumWithFields {
name: "enum_out",
discriminant: TraceEnumDiscriminant {
location: TraceScalarId(4),
name: "$tag",
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
flow: Sink,
},
non_empty_fields: [
TraceUInt {
location: TraceScalarId(5),
name: "A",
ty: UInt<8>,
flow: Source,
},
TraceUInt {
location: TraceScalarId(6),
name: "B",
ty: UInt<8>,
flow: Source,
},
TraceUInt {
location: TraceScalarId(7),
name: "C",
ty: UInt<8>,
flow: Source,
},
],
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
flow: Sink,
},
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
flow: Sink,
},
],
},
traces: [
SimTrace {
id: TraceScalarId(0),
kind: BigUInt {
index: StatePartIndex<BigSlots>(0),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x02,
last_state: 0x02,
},
SimTrace {
id: TraceScalarId(1),
kind: BigUInt {
index: StatePartIndex<BigSlots>(1),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe1,
last_state: 0xb4,
},
SimTrace {
id: TraceScalarId(2),
kind: BigUInt {
index: StatePartIndex<BigSlots>(2),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x02,
last_state: 0x02,
},
SimTrace {
id: TraceScalarId(3),
kind: BigUInt {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe1,
last_state: 0xb4,
},
SimTrace {
id: TraceScalarId(4),
kind: EnumDiscriminant {
index: StatePartIndex<SmallSlots>(0),
ty: Enum {
A(UInt<8>),
B(UInt<8>),
C(UInt<8>),
},
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
SimTrace {
id: TraceScalarId(5),
kind: BigUInt {
index: StatePartIndex<BigSlots>(6),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe1,
last_state: 0xb4,
},
SimTrace {
id: TraceScalarId(6),
kind: BigUInt {
index: StatePartIndex<BigSlots>(6),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe1,
last_state: 0xb4,
},
SimTrace {
id: TraceScalarId(7),
kind: BigUInt {
index: StatePartIndex<BigSlots>(6),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xe1,
last_state: 0xb4,
},
],
trace_memories: {},
trace_writers: [
Running(
VcdWriter {
finished_init: true,
timescale: 1 ps,
..
},
),
],
clocks_triggered: [],
event_queue: EventQueue(EventQueueData {
instant: 18 μs,
events: {},
}),
waiting_sensitivity_sets_by_address: {},
waiting_sensitivity_sets_by_compiled_value: {},
..
}

View file

@ -0,0 +1,133 @@
$timescale 1 ps $end
$scope module enum_with_simple_body $end
$var wire 8 J&-ne which_in $end
$var wire 8 \7mo/ data_in $end
$var wire 8 ,`>ir which_out $end
$var wire 8 0_gMP data_out $end
$scope struct enum_out $end
$var string 1 kFH/w \$tag $end
$var wire 8 |EI_= A $end
$var wire 8 !pRd4 B $end
$var wire 8 &RAbd C $end
$upscope $end
$upscope $end
$enddefinitions $end
$dumpvars
b0 J&-ne
b0 \7mo/
b0 ,`>ir
b0 0_gMP
sA\x20(0) kFH/w
b0 |EI_=
b0 !pRd4
b0 &RAbd
$end
#1000000
b101101 \7mo/
b101101 0_gMP
b101101 |EI_=
b101101 !pRd4
b101101 &RAbd
#2000000
b1011010 \7mo/
b1011010 0_gMP
b1011010 |EI_=
b1011010 !pRd4
b1011010 &RAbd
#3000000
b10000111 \7mo/
b10000111 0_gMP
b10000111 |EI_=
b10000111 !pRd4
b10000111 &RAbd
#4000000
b10110100 \7mo/
b10110100 0_gMP
b10110100 |EI_=
b10110100 !pRd4
b10110100 &RAbd
#5000000
b11100001 \7mo/
b11100001 0_gMP
b11100001 |EI_=
b11100001 !pRd4
b11100001 &RAbd
#6000000
b1 J&-ne
b0 \7mo/
b1 ,`>ir
b0 0_gMP
sB\x20(1) kFH/w
b0 |EI_=
b0 !pRd4
b0 &RAbd
#7000000
b101101 \7mo/
b101101 0_gMP
b101101 |EI_=
b101101 !pRd4
b101101 &RAbd
#8000000
b1011010 \7mo/
b1011010 0_gMP
b1011010 |EI_=
b1011010 !pRd4
b1011010 &RAbd
#9000000
b10000111 \7mo/
b10000111 0_gMP
b10000111 |EI_=
b10000111 !pRd4
b10000111 &RAbd
#10000000
b10110100 \7mo/
b10110100 0_gMP
b10110100 |EI_=
b10110100 !pRd4
b10110100 &RAbd
#11000000
b11100001 \7mo/
b11100001 0_gMP
b11100001 |EI_=
b11100001 !pRd4
b11100001 &RAbd
#12000000
b10 J&-ne
b0 \7mo/
b10 ,`>ir
b0 0_gMP
sC\x20(2) kFH/w
b0 |EI_=
b0 !pRd4
b0 &RAbd
#13000000
b101101 \7mo/
b101101 0_gMP
b101101 |EI_=
b101101 !pRd4
b101101 &RAbd
#14000000
b1011010 \7mo/
b1011010 0_gMP
b1011010 |EI_=
b1011010 !pRd4
b1011010 &RAbd
#15000000
b10000111 \7mo/
b10000111 0_gMP
b10000111 |EI_=
b10000111 !pRd4
b10000111 &RAbd
#16000000
b10110100 \7mo/
b10110100 0_gMP
b10110100 |EI_=
b10110100 !pRd4
b10110100 &RAbd
#17000000
b11100001 \7mo/
b11100001 0_gMP
b11100001 |EI_=
b11100001 !pRd4
b11100001 &RAbd
#18000000

View file

@ -1746,6 +1746,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -1754,6 +1755,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1762,6 +1764,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: false,
state: 0x1,
last_state: 0x1,
},
@ -1771,6 +1774,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<2>,
},
maybe_changed: false,
state: 0x2,
last_state: 0x2,
},
@ -1780,6 +1784,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<4>,
},
maybe_changed: false,
state: 0xf,
last_state: 0xf,
},
@ -1789,6 +1794,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1798,6 +1804,7 @@ Simulation {
index: StatePartIndex<BigSlots>(6),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xf,
last_state: 0xf,
},
@ -1810,6 +1817,7 @@ Simulation {
HdlSome(Bundle {0: UInt<1>, 1: Bool}),
},
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1819,6 +1827,7 @@ Simulation {
index: StatePartIndex<BigSlots>(8),
ty: UInt<1>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1827,6 +1836,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(9),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1839,6 +1849,7 @@ Simulation {
HdlSome(Bundle {0: UInt<1>, 1: Bool}),
},
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1848,6 +1859,7 @@ Simulation {
index: StatePartIndex<BigSlots>(16),
ty: UInt<1>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1856,6 +1868,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(17),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1869,6 +1882,7 @@ Simulation {
C(Bundle {a: Array<UInt<1>, 2>, b: SInt<2>}),
},
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1878,6 +1892,7 @@ Simulation {
index: StatePartIndex<BigSlots>(27),
ty: UInt<1>,
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1886,6 +1901,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(28),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1895,6 +1911,7 @@ Simulation {
index: StatePartIndex<BigSlots>(34),
ty: UInt<1>,
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1904,6 +1921,7 @@ Simulation {
index: StatePartIndex<BigSlots>(35),
ty: UInt<1>,
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1913,6 +1931,7 @@ Simulation {
index: StatePartIndex<BigSlots>(36),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x3,
last_state: 0x3,
},

View file

@ -221,6 +221,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: false,
state: 0x1,
last_state: 0x1,
},
@ -229,6 +230,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},

View file

@ -57,7 +57,7 @@ Simulation {
big_slots: StatePart {
value: [
0,
1,
1 (modified),
101,
],
},
@ -280,6 +280,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -288,6 +289,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -297,6 +299,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x65,
last_state: 0x65,
},

View file

@ -433,7 +433,7 @@ Simulation {
1,
1,
1,
7,
7 (modified),
7,
3,
0,
@ -614,6 +614,7 @@ Simulation {
HdlSome(Array<Bool, 4>),
},
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -622,6 +623,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -630,6 +632,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -638,6 +641,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(3),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -646,6 +650,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(4),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -658,6 +663,7 @@ Simulation {
HdlSome(UInt<8>),
},
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -667,6 +673,7 @@ Simulation {
index: StatePartIndex<BigSlots>(17),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x03,
last_state: 0x02,
},
@ -676,6 +683,7 @@ Simulation {
index: StatePartIndex<BigSlots>(20),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x03,
last_state: 0x02,
},

File diff suppressed because it is too large Load diff

View file

@ -1168,6 +1168,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1176,6 +1177,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1184,6 +1186,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -1193,6 +1196,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xb0,
last_state: 0xb0,
},
@ -1202,6 +1206,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: SInt<8>,
},
maybe_changed: true,
state: 0xc0,
last_state: 0xc0,
},
@ -1211,6 +1216,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1219,6 +1225,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(6),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1227,6 +1234,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(7),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -1236,6 +1244,7 @@ Simulation {
index: StatePartIndex<BigSlots>(8),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xd0,
last_state: 0xd0,
},
@ -1245,6 +1254,7 @@ Simulation {
index: StatePartIndex<BigSlots>(9),
ty: SInt<8>,
},
maybe_changed: true,
state: 0xe0,
last_state: 0xe0,
},
@ -1253,6 +1263,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(10),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1261,6 +1272,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(11),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1270,6 +1282,7 @@ Simulation {
index: StatePartIndex<BigSlots>(12),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1278,6 +1291,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(13),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1286,6 +1300,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(14),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -1295,6 +1310,7 @@ Simulation {
index: StatePartIndex<BigSlots>(15),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xb0,
last_state: 0xb0,
},
@ -1304,6 +1320,7 @@ Simulation {
index: StatePartIndex<BigSlots>(16),
ty: SInt<8>,
},
maybe_changed: true,
state: 0xc0,
last_state: 0xc0,
},
@ -1313,6 +1330,7 @@ Simulation {
index: StatePartIndex<BigSlots>(17),
ty: UInt<4>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -1321,6 +1339,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(18),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1329,6 +1348,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(19),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -1338,6 +1358,7 @@ Simulation {
index: StatePartIndex<BigSlots>(20),
ty: UInt<8>,
},
maybe_changed: true,
state: 0xd0,
last_state: 0xd0,
},
@ -1347,6 +1368,7 @@ Simulation {
index: StatePartIndex<BigSlots>(21),
ty: SInt<8>,
},
maybe_changed: true,
state: 0xe0,
last_state: 0xe0,
},
@ -1355,6 +1377,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(22),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1363,6 +1386,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(23),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},

View file

@ -943,6 +943,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -951,6 +952,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -959,6 +961,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -968,6 +971,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<2>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -976,6 +980,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(4),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -985,6 +990,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<2>,
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -993,6 +999,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(6),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1002,6 +1009,7 @@ Simulation {
index: StatePartIndex<BigSlots>(7),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1010,6 +1018,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(8),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1018,6 +1027,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(9),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -1030,6 +1040,7 @@ Simulation {
HdlSome(Bool),
},
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1038,6 +1049,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(16),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1046,6 +1058,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(11),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1058,6 +1071,7 @@ Simulation {
HdlSome(Bool),
},
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1066,6 +1080,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(19),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1074,6 +1089,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(13),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},

View file

@ -2391,6 +2391,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2399,6 +2400,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2407,6 +2409,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -2416,6 +2419,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2425,6 +2429,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2434,6 +2439,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2443,6 +2449,7 @@ Simulation {
index: StatePartIndex<BigSlots>(6),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2452,6 +2459,7 @@ Simulation {
index: StatePartIndex<BigSlots>(7),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2461,6 +2469,7 @@ Simulation {
index: StatePartIndex<BigSlots>(8),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2470,6 +2479,7 @@ Simulation {
index: StatePartIndex<BigSlots>(9),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2479,6 +2489,7 @@ Simulation {
index: StatePartIndex<BigSlots>(10),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2488,6 +2499,7 @@ Simulation {
index: StatePartIndex<BigSlots>(11),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2496,6 +2508,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(12),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2504,6 +2517,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(13),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -2513,6 +2527,7 @@ Simulation {
index: StatePartIndex<BigSlots>(14),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2522,6 +2537,7 @@ Simulation {
index: StatePartIndex<BigSlots>(15),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2531,6 +2547,7 @@ Simulation {
index: StatePartIndex<BigSlots>(16),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2540,6 +2557,7 @@ Simulation {
index: StatePartIndex<BigSlots>(17),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2549,6 +2567,7 @@ Simulation {
index: StatePartIndex<BigSlots>(18),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2558,6 +2577,7 @@ Simulation {
index: StatePartIndex<BigSlots>(19),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2567,6 +2587,7 @@ Simulation {
index: StatePartIndex<BigSlots>(20),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2576,6 +2597,7 @@ Simulation {
index: StatePartIndex<BigSlots>(21),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2584,6 +2606,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(22),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2592,6 +2615,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(23),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2600,6 +2624,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(24),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2608,6 +2633,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(25),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2616,6 +2642,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(26),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2624,6 +2651,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(27),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2632,6 +2660,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(28),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2640,6 +2669,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(29),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2649,6 +2679,7 @@ Simulation {
index: StatePartIndex<BigSlots>(30),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2657,6 +2688,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(31),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2665,6 +2697,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(32),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -2674,6 +2707,7 @@ Simulation {
index: StatePartIndex<BigSlots>(33),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2683,6 +2717,7 @@ Simulation {
index: StatePartIndex<BigSlots>(34),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2692,6 +2727,7 @@ Simulation {
index: StatePartIndex<BigSlots>(35),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2701,6 +2737,7 @@ Simulation {
index: StatePartIndex<BigSlots>(36),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2710,6 +2747,7 @@ Simulation {
index: StatePartIndex<BigSlots>(37),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2719,6 +2757,7 @@ Simulation {
index: StatePartIndex<BigSlots>(38),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2728,6 +2767,7 @@ Simulation {
index: StatePartIndex<BigSlots>(39),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2737,6 +2777,7 @@ Simulation {
index: StatePartIndex<BigSlots>(40),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2746,6 +2787,7 @@ Simulation {
index: StatePartIndex<BigSlots>(57),
ty: UInt<3>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2754,6 +2796,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(58),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2762,6 +2805,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(59),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -2771,6 +2815,7 @@ Simulation {
index: StatePartIndex<BigSlots>(60),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2780,6 +2825,7 @@ Simulation {
index: StatePartIndex<BigSlots>(61),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2789,6 +2835,7 @@ Simulation {
index: StatePartIndex<BigSlots>(62),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2798,6 +2845,7 @@ Simulation {
index: StatePartIndex<BigSlots>(63),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2807,6 +2855,7 @@ Simulation {
index: StatePartIndex<BigSlots>(64),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2816,6 +2865,7 @@ Simulation {
index: StatePartIndex<BigSlots>(65),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2825,6 +2875,7 @@ Simulation {
index: StatePartIndex<BigSlots>(66),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2834,6 +2885,7 @@ Simulation {
index: StatePartIndex<BigSlots>(67),
ty: UInt<8>,
},
maybe_changed: true,
state: 0x00,
last_state: 0x00,
},
@ -2842,6 +2894,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(68),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2850,6 +2903,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(69),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2858,6 +2912,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(70),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2866,6 +2921,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(71),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2874,6 +2930,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(72),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2882,6 +2939,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(73),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2890,6 +2948,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(74),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -2898,6 +2957,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(75),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},

View file

@ -445,6 +445,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xa,
last_state: 0x3,
},
@ -454,6 +455,7 @@ Simulation {
index: StatePartIndex<BigSlots>(1),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x3,
},
@ -463,6 +465,7 @@ Simulation {
index: StatePartIndex<BigSlots>(2),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -472,6 +475,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xf,
last_state: 0xe,
},
@ -481,6 +485,7 @@ Simulation {
index: StatePartIndex<BigSlots>(8),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xa,
last_state: 0x3,
},
@ -490,6 +495,7 @@ Simulation {
index: StatePartIndex<BigSlots>(9),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x3,
},
@ -499,6 +505,7 @@ Simulation {
index: StatePartIndex<BigSlots>(10),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -508,6 +515,7 @@ Simulation {
index: StatePartIndex<BigSlots>(11),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xf,
last_state: 0xe,
},
@ -517,6 +525,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xa,
last_state: 0x3,
},
@ -526,6 +535,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x3,
},
@ -535,6 +545,7 @@ Simulation {
index: StatePartIndex<BigSlots>(6),
ty: SInt<2>,
},
maybe_changed: true,
state: 0x2,
last_state: 0x2,
},
@ -544,6 +555,7 @@ Simulation {
index: StatePartIndex<BigSlots>(7),
ty: UInt<4>,
},
maybe_changed: true,
state: 0xf,
last_state: 0xe,
},

View file

@ -6,18 +6,12 @@ $var wire 2 Q2~aG o $end
$var wire 2 DXK'| i2 $end
$var wire 4 cPuix o2 $end
$upscope $end
$scope struct child $end
$scope module child $end
$var wire 4 ($5K7 i $end
$var wire 2 %6Wv" o $end
$var wire 2 +|-AU i2 $end
$var wire 4 Hw?%j o2 $end
$upscope $end
$scope module mod1_child $end
$var wire 4 4}s%= i $end
$var wire 2 }IY?g o $end
$var wire 2 of42K i2 $end
$var wire 4 D9]&= o2 $end
$upscope $end
$upscope $end
$enddefinitions $end
$dumpvars
@ -25,10 +19,6 @@ b11 avK(^
b11 Q2~aG
b10 DXK'|
b1110 cPuix
b11 4}s%=
b11 }IY?g
b10 of42K
b1110 D9]&=
b11 ($5K7
b11 %6Wv"
b10 +|-AU
@ -38,9 +28,6 @@ $end
b1010 avK(^
b10 Q2~aG
b1111 cPuix
b1010 4}s%=
b10 }IY?g
b1111 D9]&=
b1010 ($5K7
b10 %6Wv"
b1111 Hw?%j

View file

@ -373,6 +373,7 @@ Simulation {
["a","b"],
),
},
maybe_changed: true,
state: PhantomConst,
last_state: PhantomConst,
},
@ -383,6 +384,7 @@ Simulation {
["a","b"],
),
},
maybe_changed: true,
state: PhantomConst,
last_state: PhantomConst,
},
@ -392,6 +394,7 @@ Simulation {
index: StatePartIndex<BigSlots>(0),
ty: UInt<0>,
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -400,6 +403,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -408,6 +412,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -418,6 +423,7 @@ Simulation {
"mem_element",
),
},
maybe_changed: true,
state: PhantomConst,
last_state: PhantomConst,
},

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -687,18 +687,7 @@ Simulation {
1,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
1,
0,
0,
0,
0 (modified),
0,
0,
0,
@ -709,9 +698,20 @@ Simulation {
1,
0,
0,
0 (modified),
0,
0,
0,
1,
0,
0,
0,
1,
0,
0,
0 (modified),
0,
0,
],
},
sim_only_slots: StatePart {
@ -1284,6 +1284,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: false,
state: 0x1,
last_state: 0x1,
},
@ -1293,6 +1294,7 @@ Simulation {
index: StatePartIndex<BigSlots>(1),
ty: UInt<6>,
},
maybe_changed: false,
state: 0x00,
last_state: 0x00,
},
@ -1301,6 +1303,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1309,6 +1312,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(3),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1317,6 +1321,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(4),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1325,6 +1330,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(5),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1333,6 +1339,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(6),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1341,6 +1348,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(7),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1349,6 +1357,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(24),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1357,6 +1366,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(33),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1365,6 +1375,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(34),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1373,6 +1384,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(31),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1381,6 +1393,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(32),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1389,6 +1402,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(36),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1397,6 +1411,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(44),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1405,6 +1420,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(45),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1413,6 +1429,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(42),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1421,6 +1438,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(43),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1429,6 +1447,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(47),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1437,6 +1456,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(55),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1445,6 +1465,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(56),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1453,6 +1474,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(53),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -1461,6 +1483,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(54),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},

File diff suppressed because it is too large Load diff

View file

@ -458,6 +458,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x0,
},
@ -466,6 +467,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -474,6 +476,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -482,6 +485,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(3),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -490,6 +494,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(4),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -498,6 +503,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(7),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -506,6 +512,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(9),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -514,6 +521,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(11),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},

View file

@ -68,12 +68,12 @@ Simulation {
},
big_slots: StatePart {
value: [
0 (modified),
0,
0,
0,
49,
50,
50,
49 (modified),
50 (modified),
50 (modified),
],
},
sim_only_slots: StatePart {
@ -356,6 +356,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -364,6 +365,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -372,6 +374,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -381,6 +384,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x31,
last_state: 0x31,
},
@ -390,6 +394,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x32,
last_state: 0x32,
},
@ -399,6 +404,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x32,
last_state: 0x32,
},

View file

@ -68,12 +68,12 @@ Simulation {
},
big_slots: StatePart {
value: [
0 (modified),
0,
0,
0,
49,
50,
50,
49 (modified),
50 (modified),
50 (modified),
],
},
sim_only_slots: StatePart {
@ -356,6 +356,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -364,6 +365,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: false,
state: 0x0,
last_state: 0x0,
},
@ -372,6 +374,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x0,
last_state: 0x1,
},
@ -381,6 +384,7 @@ Simulation {
index: StatePartIndex<BigSlots>(3),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x31,
last_state: 0x31,
},
@ -390,6 +394,7 @@ Simulation {
index: StatePartIndex<BigSlots>(4),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x32,
last_state: 0x32,
},
@ -399,6 +404,7 @@ Simulation {
index: StatePartIndex<BigSlots>(5),
ty: UInt<8>,
},
maybe_changed: false,
state: 0x32,
last_state: 0x32,
},

View file

@ -392,7 +392,7 @@ Simulation {
0,
1,
0,
1,
1 (modified),
0,
0,
0,
@ -400,7 +400,7 @@ Simulation {
0,
1,
0,
1,
1 (modified),
0,
],
},
@ -1252,6 +1252,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(0),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1260,6 +1261,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(1),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1269,6 +1271,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(0),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"extra": "value",
},
@ -1282,6 +1285,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(1),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"extra": "value",
},
@ -1295,6 +1299,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(2),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "",
"extra": "value",
@ -1312,6 +1317,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(3),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "baz",
"extra": "value",
@ -1328,6 +1334,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(4),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1336,6 +1343,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(5),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1345,6 +1353,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(6),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"extra": "value",
},
@ -1358,6 +1367,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(7),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "",
"extra": "value",
@ -1374,6 +1384,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(2),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1382,6 +1393,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(3),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1391,6 +1403,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(4),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"extra": "value",
},
@ -1404,6 +1417,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(5),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "",
"extra": "value",
@ -1421,6 +1435,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(8),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"extra": "value",
},
@ -1433,6 +1448,7 @@ Simulation {
kind: BigBool {
index: StatePartIndex<BigSlots>(6),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1441,6 +1457,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(12),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1449,6 +1466,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(13),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1458,6 +1476,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(13),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "",
"extra": "value",
@ -1475,6 +1494,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(14),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "baz",
"extra": "value",
@ -1491,6 +1511,7 @@ Simulation {
kind: BigClock {
index: StatePartIndex<BigSlots>(10),
},
maybe_changed: true,
state: 0x1,
last_state: 0x1,
},
@ -1499,6 +1520,7 @@ Simulation {
kind: BigSyncReset {
index: StatePartIndex<BigSlots>(11),
},
maybe_changed: true,
state: 0x0,
last_state: 0x0,
},
@ -1508,6 +1530,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(11),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "",
"extra": "value",
@ -1525,6 +1548,7 @@ Simulation {
index: StatePartIndex<SimOnlySlots>(12),
ty: SimOnly<alloc::collections::btree::map::BTreeMap<alloc::string::String, alloc::rc::Rc<str>>>,
},
maybe_changed: true,
state: {
"bar": "baz",
"extra": "value",

Some files were not shown because too many files have changed in this diff Show more