Skip to content
Merged
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
4 changes: 2 additions & 2 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
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
11 changes: 11 additions & 0 deletions crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ records the native-runner result; the case stays enabled on all Celox backends.

## SystemVerilog suite

Verilator 5.052 rejects a string variable or string method expression as the
`$sscanf` format, requiring a literal instead. IEEE 1800-2023 21.3.4.3 permits
string expressions here. Only `scan::sscanf_string_format_expression` is
excluded for Verilator; string sources with literal formats remain enabled.
The [direct lint observation](verification/sv/limitations/scan-string-format-verilator.json)
retains the diagnostic against the unchanged shared source. Icarus 13.0
compiles the dynamic-format case but crashes in `vvp`; a reduced source using
only a format variable also crashes. This same case is excluded for Icarus,
with the [runtime observation and reduced source](verification/sv/limitations/scan-string-format-icarus.json)
retained separately. The literal-format case remains enabled for both tools.

Named unpacked array parameter forwarding is checked against IEEE 1800-2023
6.20.2 and 7.6. Verilator 5.052 passes the whole-array forwarding case, but
reverses elements across opposite declaration directions and rejects a constant
Expand Down
49 changes: 49 additions & 0 deletions crates/celox-test-suite/src/sv/cases/scan.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,52 @@
(top Top)
(run_until 0)
(assert_eq ok 1))

; IEEE 1800-2023 13.4.1 and 21.3.4.3: discarding the return value
; does not discard assignments performed by a scan.
(case sscanf_string_inputs_and_discarded_return
(source "sscanf_discard.sv" #"
module Top(output logic ok);
string source = "1234";
int value, keep, count;
initial begin
$sscanf(source, "%d", value);
ok = value == 1234;
source = "42";
count = $sscanf(source.substr(0, 1), "%d", value);
ok &= count == 1 && value == 42;
$sscanf("78", "%d", value);
ok &= value == 78;
source = "";
count = $sscanf(source, "%d", value);
ok &= count == -1 && value == 78;
keep = 77;
$sscanf("bad", "%d", keep);
ok &= keep == 77;
end
endmodule
"#)
(top Top)
(run_until 0)
(assert_eq ok 1))

; 21.3.4.3 also permits a string expression as the format.
(case sscanf_string_format_expression
(source "sscanf_format.sv" #"
module Top(output logic ok);
string source = "42";
string fmt = "%d";
int value, count;
initial begin
count = $sscanf(source, fmt, value);
ok = count == 1 && value == 42;
count = $sscanf(source.substr(0, 1), fmt.substr(0, 1), value);
ok &= count == 1 && value == 42;
count = $sscanf("56", fmt, value);
ok &= count == 1 && value == 56;
end
endmodule
"#)
(top Top)
(run_until 0)
(assert_eq ok 1))
1 change: 1 addition & 0 deletions crates/celox-test-suite/verification/sv/icarus.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"icarus/program.json",
"icarus/random_plusargs.json",
"icarus/review_regressions.json",
"icarus/scan.json",
"icarus/string.json",
"icarus/synthesizable.json",
"icarus/system_functions.json",
Expand Down
27 changes: 27 additions & 0 deletions crates/celox-test-suite/verification/sv/icarus/scan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cases": [
{
"category": "Sequential",
"detail": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Icarus 13.0 compiles this case but vvp terminates with SIGSEGV. A reduced source using only a string format variable, without a method expression, also crashes. The string-source case with a literal format remains enabled.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_runtime_limitation",
"evidence": [
"verification/sv/limitations/scan-string-format-icarus.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_icarus_scan_string_format",
"observed_version": "Icarus Verilog 13.0",
"phase": "execute",
"reason": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Icarus 13.0 compiles this case but vvp terminates with SIGSEGV. A reduced source using only a string format variable, without a method expression, also crashes. The string-source case with a literal format remains enabled.",
"upstream": []
},
"name": "scan::sscanf_string_format_expression",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
}
]
}
34 changes: 34 additions & 0 deletions crates/celox-test-suite/verification/sv/limitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2458,5 +2458,39 @@
"class::randomization_cyclic_enum_alias"
]
}
},
{
"id": "sv_verilator_scan_string_format",
"category": "simulator_compile_limitation",
"phase": "compile",
"observed_version": "Verilator 5.052",
"reason": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Verilator 5.052 requires a format string literal and rejects both a string variable and a string method expression with \"unexpected IDENTIFIER, expecting STRING\". The string-source case with a literal format remains enabled.",
"upstream": [],
"evidence": [
"verification/sv/limitations/scan-string-format-verilator.json",
"LIMITATIONS.md#systemverilog-suite"
],
"cases": {
"verilator": [
"scan::sscanf_string_format_expression"
]
}
},
{
"id": "sv_icarus_scan_string_format",
"category": "simulator_runtime_limitation",
"phase": "execute",
"observed_version": "Icarus Verilog 13.0",
"reason": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Icarus 13.0 compiles this case but vvp terminates with SIGSEGV. A reduced source using only a string format variable, without a method expression, also crashes. The string-source case with a literal format remains enabled.",
"upstream": [],
"evidence": [
"verification/sv/limitations/scan-string-format-icarus.json",
"LIMITATIONS.md#systemverilog-suite"
],
"cases": {
"icarus": [
"scan::sscanf_string_format_expression"
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tool": "icarus",
"version": "Icarus Verilog 13.0",
"case": "scan::sscanf_string_format_expression",
"source": "src/sv/cases/scan.vtest",
"method": "The unchanged shared source compiles with iverilog -g2012 -s tb and crashes when executed by vvp. Removing the string-method-expression call still crashes; the reduced source below isolates a format variable. The added testbench checks the same ok assertion.",
"status": "runtime_error",
"signal": 11,
"stdout": "",
"stderr": "",
"reduced_source": "\n module Top(output logic ok);\n string source = \"42\";\n string fmt = \"%d\";\n int value, count;\n initial begin\n count = $sscanf(source, fmt, value);\n ok = count == 1 && value == 42;\n count = $sscanf(\"56\", fmt, value);\n ok &= count == 1 && value == 56;\n end\n endmodule\n \nmodule tb; wire ok; Top dut(ok); initial begin #1; if (ok !== 1) $fatal(1, \"scan failed\"); $display(\"PASS\"); $finish; end endmodule\n"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tool": "verilator",
"version": "Verilator 5.052 2026-09-05 rev v5.052",
"case": "scan::sscanf_string_format_expression",
"source": "src/sv/cases/scan.vtest",
"method": "The source block from the named case was passed unchanged to verilator --lint-only --top-module Top.",
"status": "compile_error",
"exit_code": 1,
"detail": "%Error: <case>/sscanf_format.sv:7:33: syntax error, unexpected IDENTIFIER, expecting STRING\n 7 | count = $sscanf(source, fmt, value);\n | ^~~\n ... See the manual at https://verilator.org/verilator_doc.html?v=5.052 for more assistance.\n%Error: <case>/sscanf_format.sv:9:46: syntax error, unexpected IDENTIFIER, expecting STRING\n 9 | count = $sscanf(source.substr(0, 1), fmt.substr(0, 1), value);\n | ^~~\n%Error: <case>/sscanf_format.sv:11:31: syntax error, unexpected IDENTIFIER, expecting STRING\n 11 | count = $sscanf(\"56\", fmt, value);\n | ^~~\n%Error: Exiting due to 3 error(s)\n"
}
1 change: 1 addition & 0 deletions crates/celox-test-suite/verification/sv/verilator.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"verilator/program.json",
"verilator/random_plusargs.json",
"verilator/review_regressions.json",
"verilator/scan.json",
"verilator/string.json",
"verilator/synthesizable.json",
"verilator/system_functions.json",
Expand Down
27 changes: 27 additions & 0 deletions crates/celox-test-suite/verification/sv/verilator/scan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cases": [
{
"category": "Sequential",
"detail": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Verilator 5.052 requires a format string literal and rejects both a string variable and a string method expression with \"unexpected IDENTIFIER, expecting STRING\". The string-source case with a literal format remains enabled.",
"expectation": "Simulation",
"known_issue": {
"category": "simulator_compile_limitation",
"evidence": [
"verification/sv/limitations/scan-string-format-verilator.json",
"LIMITATIONS.md#systemverilog-suite"
],
"id": "sv_verilator_scan_string_format",
"observed_version": "Verilator 5.052",
"phase": "compile",
"reason": "IEEE 1800-2023 21.3.4.3 permits a string expression as the scan format. Verilator 5.052 requires a format string literal and rejects both a string variable and a string method expression with \"unexpected IDENTIFIER, expecting STRING\". The string-source case with a literal format remains enabled.",
"upstream": []
},
"name": "scan::sscanf_string_format_expression",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
}
]
}
Loading
Loading