Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ chapter-21/21.3--fwrite-boh.sv 2state fail
chapter-21/21.3--fwrite-boh.sv 4state fail
chapter-21/21.3--fwrite.sv 2state fail
chapter-21/21.3--fwrite.sv 4state fail
chapter-21/21.3--sscanf.sv 2state fail
chapter-21/21.3--sscanf.sv 4state fail
chapter-21/21.3--sscanf.sv 2state pass
chapter-21/21.3--sscanf.sv 4state pass
chapter-21/21.3--ungetc.sv 2state fail
chapter-21/21.3--ungetc.sv 4state fail
chapter-21/21.4--readmemb.sv 2state pass
Expand Down Expand Up @@ -1153,14 +1153,14 @@ chapter-6/6.18--typedef.sv 2state pass
chapter-6/6.18--typedef.sv 4state pass
chapter-6/6.19--enum_anon.sv 2state pass
chapter-6/6.19--enum_anon.sv 4state pass
chapter-6/6.19--enum_value_inv.sv 2state fail
chapter-6/6.19--enum_value_inv.sv 4state fail
chapter-6/6.19--enum_value_inv.sv 2state pass
chapter-6/6.19--enum_value_inv.sv 4state pass
chapter-6/6.19--enum_xx.sv 2state pass
chapter-6/6.19--enum_xx.sv 4state pass
chapter-6/6.19--enum_xx_inv.sv 2state fail
chapter-6/6.19--enum_xx_inv.sv 4state fail
chapter-6/6.19--enum_xx_inv_order.sv 2state fail
chapter-6/6.19--enum_xx_inv_order.sv 4state fail
chapter-6/6.19--enum_xx_inv.sv 2state pass
chapter-6/6.19--enum_xx_inv.sv 4state pass
chapter-6/6.19--enum_xx_inv_order.sv 2state pass
chapter-6/6.19--enum_xx_inv_order.sv 4state pass
chapter-6/6.19.1--enum_typedef.sv 2state pass
chapter-6/6.19.1--enum_typedef.sv 4state pass
chapter-6/6.19.2--enum_sequence.sv 2state pass
Expand Down
6 changes: 6 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,17 @@ pub struct HostRequestValue<A> {
pub width: usize,
pub signed: bool,
pub is_string: bool,
/// The payload representation, independent of display formatting.
#[serde(default)]
pub value_kind: ValueKind,
#[serde(default)]
pub float_precision: Option<FloatPrecision>,
}

impl<A: Copy> HostRequestValue<A> {
pub fn map<B>(&self, map: &mut impl FnMut(A) -> B) -> HostRequestValue<B> {
HostRequestValue {
value_kind: self.value_kind,
id: map(self.id),
width: self.width,
signed: self.signed,
Expand Down Expand Up @@ -2032,6 +2036,7 @@ mod tests {
#[test]
fn host_request_mapping_relocates_operands_and_results() {
let value = |id| HostRequestValue {
value_kind: ValueKind::StrRef,
id,
width: 17,
signed: true,
Expand All @@ -2051,6 +2056,7 @@ mod tests {
assert_eq!(relocated.process, 2);
assert_eq!(relocated.args[0].width, 17);
assert!(relocated.results[0].signed);
assert_eq!(relocated.args[0].value_kind, ValueKind::StrRef);
assert_eq!(relocated.strings, site.strings);
}

Expand Down
5 changes: 5 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ impl<'p, 'a> Ff<'p, 'a> {
let (id, _) = self.m.temp("vcd_argument", width, signed, is_4state);
self.store(id, SIROffset::Static(0), width, reg);
values.push(HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id,
width,
Expand Down Expand Up @@ -2221,6 +2222,7 @@ impl<'p, 'a> Ff<'p, 'a> {
let (seed_id, seed_result) =
self.host_hidden("distribution_seed", &formal, 32, true, true)?;
let value = |id| HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id,
width: 32,
Expand Down Expand Up @@ -2288,6 +2290,7 @@ impl<'p, 'a> Ff<'p, 'a> {
let mut results = Vec::new();
let (ret_id, ret_name) = self.m.temp("plusargs_result", 32, true, false);
results.push(HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id: ret_id,
width: 32,
Expand All @@ -2306,6 +2309,7 @@ impl<'p, 'a> Ff<'p, 'a> {
.ok_or_else(|| unsupported("integral plusargs destination"))?;
let (id, result) = self.host_hidden("plusargs_value", &captured, width, false, true)?;
results.push(HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id,
width,
Expand All @@ -2326,6 +2330,7 @@ impl<'p, 'a> Ff<'p, 'a> {
kind: HostRequestKind::Plusargs,
operation: u32::from(value_query),
args: vec![HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id: query_id,
width,
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl Ff<'_, '_> {
let (id, _) = self.m.temp("file_arg", width, signed, four_state);
self.store(id, SIROffset::Static(0), width, reg);
Ok(HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
id,
width,
signed,
Expand Down Expand Up @@ -101,6 +102,7 @@ impl Ff<'_, '_> {
0,
values,
vec![HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
id,
width: 32,
signed: false,
Expand Down Expand Up @@ -151,6 +153,7 @@ impl Ff<'_, '_> {
operation,
values,
vec![HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id,
width: 32,
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff/fread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ impl Ff<'_, '_> {
values,
vec![
HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id: result_id,
width: 32,
signed: true,
is_string: false,
},
HostRequestValue {
value_kind: celox_design::ValueKind::Bits,
float_precision: None,
id: data_id,
width,
Expand Down
26 changes: 23 additions & 3 deletions crates/celox-frontend-sv/src/lowering/ff/scan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use celox_design::{HostRequestKind, HostRequestSite, HostRequestValue};
use celox_design::{HostRequestKind, HostRequestSite, HostRequestValue, ValueKind};

impl Ff<'_, '_> {
pub(super) fn scan_function(
Expand All @@ -24,7 +24,7 @@ impl Ff<'_, '_> {
.m
.comparison_width(&argument, &argument)
.ok_or_else(|| {
unsupported("scan source/format must be a packed integral or literal string")
unsupported("scan source/format must be a packed integral or string")
})?;
// File descriptors are 32-bit packed values (21.3.1), even when
// the actual expression has a wider integral type.
Expand All @@ -33,8 +33,26 @@ impl Ff<'_, '_> {
} else {
width
};
let (id, _) = self.host_hidden("scan_input", &argument, width, false, true)?;
let value_kind = if self.m.expr_is_string(&argument) {
ValueKind::StrRef
} else {
ValueKind::Bits
};
let (id, _) = self.host_hidden(
"scan_input",
&argument,
width,
false,
value_kind == ValueKind::Bits,
)?;
// Keep captured strings rooted across the host-request suspension.
self.m
.variables
.get_mut(&id)
.expect("scan input")
.value_kind = value_kind;
inputs.push(HostRequestValue {
value_kind,
float_precision: None,
id,
width,
Expand All @@ -44,6 +62,7 @@ impl Ff<'_, '_> {
}
let (result_id, result_name) = self.m.temp("scan_count", 32, true, false);
let mut results = vec![HostRequestValue {
value_kind: ValueKind::Bits,
float_precision: None,
id: result_id,
width: 32,
Expand All @@ -70,6 +89,7 @@ impl Ff<'_, '_> {
let (id, name) = self.m.temp("scan_value", width, false, precision.is_none());
self.m.variables.get_mut(&id).expect("scan temporary").float = precision;
results.push(HostRequestValue {
value_kind: ValueKind::Bits,
float_precision: precision,
id,
width,
Expand Down
19 changes: 12 additions & 7 deletions crates/celox-sv-analyzer/src/ast/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,20 +1046,25 @@ pub(super) fn enum_member_constants_from_items(
let DataTypeKind::Enum { base, items } = &native.data_type(id).kind else {
unreachable!();
};
let member_type = match base {
let member_base = match base {
Some(id) => type_binding::enum_constant_base(
*id,
syntax_tree,
&eval_env,
&resolved_type_aliases,
)?
.and_then(|ty| expr_type_from_type(&syntax_tree.state, &ty, &eval_env)),
None => Some(ExprType {
width: 32,
signed: true,
}),
)?,
None => type_binding::builtin_type("int", None),
}
.ok_or_else(|| unsupported("enum base type"))?;
type_binding::binding::validate_enum_initializers(
id,
native,
syntax_tree,
&PackedDimensions::new(HashMap::default(), &eval_env, &resolved_type_aliases),
&member_base,
)?;
let member_type = expr_type_from_type(&syntax_tree.state, &member_base, &eval_env)
.ok_or_else(|| unsupported("enum base type"))?;
let mut next_enum_value = 0i128;
for new in items {
let name = instances::normalize_identifier(&new.name.spelling);
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-sv-analyzer/src/ast/type_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub(super) fn alias_base_type(
return Ok(None);
}
let context = PackedDimensions::new(HashMap::default(), env, aliases);
binding::bind_in(id, native, tree, &context)
binding::bind_alias_in(id, native, tree, &context)
}

/// Builtin integral identity/width without syntax or aggregate layout.
Expand Down
Loading
Loading