From cea51d812d734ad209d980638cd782dff19d831b Mon Sep 17 00:00:00 2001 From: tignear Date: Thu, 22 Oct 2026 17:41:36 +0900 Subject: [PATCH] fix(sv): forward named unpacked array parameters Passing a fixed-size unpacked array parameter by name, such as Child #(.Q(TABLE)), failed with a non-integer module parameter override. Bind the caller's array value and type before specializing the child, and check assignment compatibility while preserving element order, signedness, and four-state values. Reuse the bound initializers for simulation. Add shared regressions for parent specialization, opposite array bounds, package arrays, subarrays, multiple hierarchy levels, and X/Z values, plus rejections for incompatible array types. Retain focused external-tool observations and exact-case exclusions: Icarus 13.0 rejects unpacked array parameters; Verilator 5.052 reverses opposite-bound parameter values and rejects a constant subarray argument. Slang 12.0 accepts the four shared cases and independently confirms their bound parameter values. Validation: - Full SV behavioral suite: 3755 passed, 20 existing ignores, across five backends. - Analyzer unit tests: 784 passed, 3 existing ignores. - Test-suite unit tests: 46 passed, 2 existing ignores; retained-report checks: 3 passed. - cargo fmt --all -- --check and affected library/test Clippy with -D warnings. - Verilator passes whole-array forwarding; remaining external limitations are recorded with their original failures and Slang elaboration evidence. Taxi axis switch advances past its M_BASE override rejection, then stops at an existing unknown conditional-generate condition. An equivalent direct- pattern control on the previous master reproduces that next blocker; this change does not claim a complete Taxi cocotb pass. Change-Id: If43dcafa4cc2af8fd81f6bd5912a5bd29e7178f5 --- crates/celox-sv-analyzer/src/ast.rs | 35 ++++++- .../src/ast/array_compatibility.rs | 2 +- .../src/ast/bound_patterns.rs | 36 ++++++- crates/celox-sv-analyzer/src/ast/generate.rs | 5 + crates/celox-sv-analyzer/src/ast/instances.rs | 9 ++ crates/celox-sv-analyzer/src/typecheck.rs | 2 +- crates/celox-test-suite/LIMITATIONS.md | 11 +++ .../src/sv/cases/hierarchy.vtest | 86 +++++++++++++++++ .../repros/named_array_parameters_icarus.json | 66 +++++++++++++ .../repros/named_array_parameters_slang.json | 62 ++++++++++++ .../named_array_parameters_verilator.json | 66 +++++++++++++ .../verification/sv/icarus/hierarchy.json | 96 +++++++++++++++++++ .../verification/sv/limitations.json | 57 +++++++++++ .../verification/sv/verilator/hierarchy.json | 70 ++++++++++++++ .../frontends/systemverilog/hierarchy.rs | 51 ++++++++++ 15 files changed, 646 insertions(+), 8 deletions(-) create mode 100644 crates/celox-test-suite/verification/repros/named_array_parameters_icarus.json create mode 100644 crates/celox-test-suite/verification/repros/named_array_parameters_slang.json create mode 100644 crates/celox-test-suite/verification/repros/named_array_parameters_verilator.json diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index cf131498124..ec279ef5898 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -933,6 +933,32 @@ impl Module { } packed_dimensions.subroutine_param_shapes = Arc::new(subroutine_shapes.clone()); packed_dimensions.subroutine_param_names = Arc::new(subroutine_params.clone()); + // Array parameters retain a constant value as well as their signal layout. + // Bind their values in declaration order before child parameter arguments. + for process in &imported.initial_processes { + for statement in &process.body { + if let Stmt::Assign { + lhs: LValue::Ident(name), + rhs, + .. + } = statement + { + packed_dimensions + .array_parameter_values + .insert(name.clone(), rhs.clone()); + } + } + } + let mut array_initial_processes = Vec::new(); + for parameter in &array_parameters { + let process = parameter.initial_process(syntax_tree, &packed_dimensions)?; + if let Stmt::Assign { rhs, .. } = &process.body[0] { + packed_dimensions + .array_parameter_values + .insert(parameter.signal.name.clone(), rhs.clone()); + } + array_initial_processes.push(process); + } let mut instances = instances_from_scope(syntax_tree, &const_env, &packed_dimensions, interfaces)?; let mut instance_names = HashSet::default(); @@ -1108,11 +1134,7 @@ impl Module { )?; comb_processes.extend(imported.comb_processes.iter().cloned()); ff_processes.extend(imported.ff_processes.iter().cloned()); - let mut initial_processes = Vec::new(); - for parameter in &array_parameters { - initial_processes - .push(parameter.initial_process(syntax_tree, &packed_dimensions)?); - } + let mut initial_processes = array_initial_processes; initial_processes.extend(imported.initial_processes.iter().cloned()); initial_processes.extend(procedural::initial_processes_from_scope( syntax_tree, @@ -2645,6 +2667,8 @@ struct PackedDimensions { function_return_types: HashMap, functions: Arc>, parameter_values: SharedMap, + /// Constant array initializers for binding child parameter values. + array_parameter_values: SharedMap, expression_signedness: ScopedMap, constant_indexed_base: bool, /// The current lexical scope has already collected its visible declarations. @@ -2671,6 +2695,7 @@ impl PackedDimensions { function_return_types: HashMap::default(), functions: Arc::default(), parameter_values: SharedMap::default(), + array_parameter_values: SharedMap::default(), expression_signedness: ScopedMap::default(), constant_indexed_base: false, scope_types_complete: false, diff --git a/crates/celox-sv-analyzer/src/ast/array_compatibility.rs b/crates/celox-sv-analyzer/src/ast/array_compatibility.rs index ad2ce5624af..38200c36ebe 100644 --- a/crates/celox-sv-analyzer/src/ast/array_compatibility.rs +++ b/crates/celox-sv-analyzer/src/ast/array_compatibility.rs @@ -12,7 +12,7 @@ use typecheck::UnpackedArrayType; /// The type of an unpacked array of `shape`, or `None` when `shape` is not an /// unpacked array or its type cannot be resolved. -fn unpacked_array_type( +pub(super) fn unpacked_array_type( state: &AnalysisState, shape: &VariableDimensions, dims: &PackedDimensions, diff --git a/crates/celox-sv-analyzer/src/ast/bound_patterns.rs b/crates/celox-sv-analyzer/src/ast/bound_patterns.rs index 94f167ee27b..3c7fc313c9a 100644 --- a/crates/celox-sv-analyzer/src/ast/bound_patterns.rs +++ b/crates/celox-sv-analyzer/src/ast/bound_patterns.rs @@ -13,6 +13,10 @@ pub struct BoundPattern { #[derive(Debug, Clone, PartialEq, Eq, Hash)] enum Items { Value(Expr), + ArrayValue { + value: Expr, + ty: typecheck::UnpackedArrayType, + }, List(Vec), Repeat(usize, Vec), Keyed(Vec<(Key, Value)>), @@ -44,6 +48,24 @@ pub(super) fn from_param( } } +pub(super) fn from_array_parameter( + root: celox_sv_syntax::ExprId, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, + shape: &VariableDimensions, +) -> Converted { + let ty = array_compatibility::unpacked_array_type(&tree.state, shape, dims) + .ok_or_else(|| unsupported("array parameter argument type"))?; + let value = substitute_expr_idents( + expression_binding::bind(root, tree, dims)?, + &dims.array_parameter_values, + ); + let value = frozen(&tree.state, value, dims)?; + Ok(BoundPattern { + items: Items::ArrayValue { value, ty }, + }) +} + fn frozen(state: &AnalysisState, expr: Expr, dims: &PackedDimensions) -> Converted { let freeze = |expr| frozen(state, expr, dims).map(Box::new); Ok(match expr { @@ -174,6 +196,18 @@ impl BoundPattern { shape: &VariableDimensions, dims: &PackedDimensions, ) -> Converted { + if let Items::ArrayValue { value, ty } = &self.items { + let target = array_compatibility::unpacked_array_type(state, shape, dims) + .ok_or_else(|| unsupported("unpacked array parameter supplied to a scalar"))?; + if !ty.is_assignment_compatible_with(&target) { + return Err(AnalyzerError::IncompatibleUnpackedArray { + context: "module parameter override".into(), + actual: ty.clone(), + target, + }); + } + return Ok(value.clone()); + } if let Items::Value(value) = &self.items { return Ok(value.clone()); } @@ -269,7 +303,7 @@ impl BoundPattern { keys = (0..width).rev().map(|i| Key::Index(i as i128)).collect(); } let selected = match &self.items { - Items::Value(value) => return Ok(value.clone()), + Items::Value(value) | Items::ArrayValue { value, .. } => return Ok(value.clone()), Items::Repeat(count, values) => { if count.checked_mul(values.len()) != Some(shapes.len()) { return Err(unsupported( diff --git a/crates/celox-sv-analyzer/src/ast/generate.rs b/crates/celox-sv-analyzer/src/ast/generate.rs index 4f866e8457a..a8672d7c67a 100644 --- a/crates/celox-sv-analyzer/src/ast/generate.rs +++ b/crates/celox-sv-analyzer/src/ast/generate.rs @@ -291,6 +291,11 @@ impl Item { } else { self.parameter_literals(&dimensions.parameter_values).into() }; + if !self.shadowed.is_empty() || !self.names.is_empty() { + local + .array_parameter_values + .retain(|name, _| !self.shadowed.contains(name) && !self.names.contains_key(name)); + } // Ordinary module items keep the module's function bindings. Rewriting // every function body for every item costs O(items * function size). if !self.shadowed.is_empty() || !self.names.is_empty() { diff --git a/crates/celox-sv-analyzer/src/ast/instances.rs b/crates/celox-sv-analyzer/src/ast/instances.rs index 5b878ebaefe..90db4712621 100644 --- a/crates/celox-sv-analyzer/src/ast/instances.rs +++ b/crates/celox-sv-analyzer/src/ast/instances.rs @@ -382,6 +382,15 @@ fn parameter_override( } pending.extend(parameters::skipped::children(id, declarations)); } + if let Some(shape) = + array_compatibility::native_unpacked_shape(native, declarations, packed_dimensions) + { + let pattern = + bound_patterns::from_array_parameter(native, syntax_tree, packed_dimensions, &shape)?; + let mut bound = ParameterOverride::new(name, None); + bound.bound_pattern = Some(pattern); + return Ok(bound); + } if let Some((type_name, dimensions)) = type_binding::argument_alias(native, declarations) && packed_dimensions.type_aliases.contains_key(&type_name) && !dimensions.is_empty() diff --git a/crates/celox-sv-analyzer/src/typecheck.rs b/crates/celox-sv-analyzer/src/typecheck.rs index cdbd0ae14e7..900a17b71df 100644 --- a/crates/celox-sv-analyzer/src/typecheck.rs +++ b/crates/celox-sv-analyzer/src/typecheck.rs @@ -15,7 +15,7 @@ pub struct IntegralLiteral { } /// The type of a fixed-size unpacked array of an integral element type. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnpackedArrayType { /// The element count of each unpacked dimension, slowest varying first. pub dims: Vec, diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 0324915b5fc..8200380ae33 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -345,6 +345,17 @@ records the native-runner result; the case stays enabled on all Celox backends. ## SystemVerilog suite +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 +subarray argument. Slang 12.0 accepts all four cases and confirms their parameter +values. Icarus 13.0 explicitly reports unpacked array parameters as unsupported. +Only these exact tool/case combinations are excluded; Celox runs every assertion. +The focused [Verilator](verification/repros/named_array_parameters_verilator.json), +[Icarus](verification/repros/named_array_parameters_icarus.json), and +[Slang](verification/repros/named_array_parameters_slang.json) observations retain +the failures and independent elaborated values. + The new `$dist_uniform` seed-width case is excluded for Verilator 5.052 and Icarus 13.0. Verilator generates an invalid C++ reference binding for converted seed arguments; Icarus rejects the `shortint` seed at startup. IEEE 1800-2023 diff --git a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest index ef8a2439d0c..31e2396f386 100644 --- a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest +++ b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest @@ -664,3 +664,89 @@ (top Top) (assert_eq a 0xdc) (assert_eq b 0xedc)) + +; IEEE 1800-2023 6.20.2 and 7.6: array values bind in the caller and +; corresponding elements follow declaration order, independently of bounds. +(case named_array_parameters_follow_caller_specialization + (source "named_array_parameters.sv" #" + module Child #(parameter byte Q[3:2] = '{1, 2}) + (input logic sel, output logic [15:0] y, output byte selected); + localparam byte TABLE[2] = '{99, 98}; + assign y = {Q[3], Q[2]}; + assign selected = Q[3-sel]; + endmodule + module Parent #(parameter byte B = -3) + (input logic sel, output logic [15:0] y, output byte selected); + localparam byte TABLE[0:1] = '{B, B-2}; + Child #(.Q((TABLE))) child(sel, y, selected); + endmodule + module Top(input logic sel, output logic [15:0] a, b, + output byte a_selected, b_selected); + Parent #(.B(-3)) first(sel, a, a_selected); + Parent #(.B(7)) second(sel, b, b_selected); + endmodule + "#) + (top Top) + (assert_eq a 0xfdfb) + (assert_eq b 0x0705) + (assert_eq a_selected 0xfd) + (assert_eq b_selected 7) + (modify (set sel 1)) + (assert_eq a_selected 0xfb) + (assert_eq b_selected 5)) + +(case named_array_parameters_keep_four_state_values + (four_state) + (source "named_array_parameter_states.sv" #" + module Child #(parameter logic [3:0] Q[2] = '{0, 0}) + (output logic [7:0] y); + assign y = {Q[0], Q[1]}; + endmodule + module Top(output logic [7:0] y); + localparam logic [3:0] TABLE[2] = '{4'b10xz, 4'bz01x}; + Child #(.Q(TABLE)) child(y); + endmodule + "#) + (top Top) + (assert_eq y (fourstate 0xa3 0x39))) + +(case named_array_parameters_forward_package_subarrays + (source "named_array_parameter_packages.sv" #" + package Values; + localparam logic [7:0] TABLE[2][2] = '{'{8'h12, 8'h34}, '{8'h56, 8'h78}}; + endpackage + module Child #(parameter logic [7:0] Q[2] = '{0, 0}) + (output logic [15:0] y); + assign y = {Q[0], Q[1]}; + endmodule + module Middle #(parameter logic [7:0] Q[2][2] = '{default: 0}) + (output logic [15:0] y); + Child #(.Q(Q[1])) child(y); + endmodule + module Top(output logic [15:0] y); + import Values::*; + Middle #(.Q(TABLE)) middle(y); + endmodule + "#) + (top Top) + (assert_eq y 0x5678)) + +(case named_array_parameters_forward_whole_values + (source "named_array_parameter_whole_values.sv" #" + module Child #(parameter logic [7:0] Q[2] = '{0, 0}) + (input logic sel, output logic [7:0] y); + assign y = Q[sel]; + endmodule + module Middle #(parameter logic [7:0] Q[2] = '{0, 0}) + (input logic sel, output logic [7:0] y); + Child #(.Q(Q)) child(sel, y); + endmodule + module Top(input logic sel, output logic [7:0] y); + localparam logic [7:0] TABLE[2] = '{8'h12, 8'ha5}; + Middle #(.Q(TABLE)) middle(sel, y); + endmodule + "#) + (top Top) + (assert_eq y 0x12) + (modify (set sel 1)) + (assert_eq y 0xa5)) diff --git a/crates/celox-test-suite/verification/repros/named_array_parameters_icarus.json b/crates/celox-test-suite/verification/repros/named_array_parameters_icarus.json new file mode 100644 index 00000000000..a70a2216b43 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/named_array_parameters_icarus.json @@ -0,0 +1,66 @@ +{ + "cases": [ + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 3; see /build.log\n/source_0.sv:2: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:4: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:10: sorry: unpacked array parameters are not supported yet.\n", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_follow_caller_specialization", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 4; see /build.log\n/source_0.sv:3: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:5: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:9: syntax error\nI give up.\n", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_forward_package_subarrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 3; see /build.log\n/source_0.sv:2: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:6: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:11: sorry: unpacked array parameters are not supported yet.\n", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_forward_whole_values", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 2; see /build.log\n/source_0.sv:2: sorry: unpacked array parameters are not supported yet.\n/source_0.sv:7: sorry: unpacked array parameters are not supported yet.\n", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_keep_four_state_values", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "counts": { + "compile_error": 4, + "emission_error": 0, + "ignored": 0, + "mismatch": 0, + "passed": 0, + "rejected": 0, + "runtime_error": 0, + "unexpected_accept": 0, + "unsupported": 0 + }, + "include_ignored": true, + "schema_version": 3, + "suite": "sv", + "suite_version": "0.11.0", + "tool": "icarus", + "version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "note": "Focused observations before exact-case exclusions for named array parameter forwarding; shared assertions are preserved." +} diff --git a/crates/celox-test-suite/verification/repros/named_array_parameters_slang.json b/crates/celox-test-suite/verification/repros/named_array_parameters_slang.json new file mode 100644 index 00000000000..b3cbfe51d01 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/named_array_parameters_slang.json @@ -0,0 +1,62 @@ +{ + "tool": "pyslang", + "version": "12.0.0", + "checks": [ + { + "case": "hierarchy::named_array_parameters_follow_caller_specialization", + "source_sha256": "c8127334e666ab7dafd74cefc709ac9f1fdfe9cd5795faf618bb2deeabfdb5b9", + "errors": [], + "bindings": { + "first.child.Q": { + "type": "byte$[3:2]", + "value": "[-8'sd3,-8'sd5]" + }, + "second.child.Q": { + "type": "byte$[3:2]", + "value": "[8'sd7,8'sd5]" + } + } + }, + { + "case": "hierarchy::named_array_parameters_forward_package_subarrays", + "source_sha256": "87f67f23270f1e7615c93554ed10c7b2cbc9fc300d1f480e2d7ee041adc3cb14", + "errors": [], + "bindings": { + "middle.Q": { + "type": "logic[7:0]$[0:1][0:1]", + "value": "[[8'd18,8'd52],[8'd86,8'd120]]" + }, + "middle.child.Q": { + "type": "logic[7:0]$[0:1]", + "value": "[8'd86,8'd120]" + } + } + }, + { + "case": "hierarchy::named_array_parameters_forward_whole_values", + "source_sha256": "cf38282d49b23193fe91e1305785f18710377c4571b2b8753cb9483bf0416092", + "errors": [], + "bindings": { + "middle.Q": { + "type": "logic[7:0]$[0:1]", + "value": "[8'd18,8'd165]" + }, + "middle.child.Q": { + "type": "logic[7:0]$[0:1]", + "value": "[8'd18,8'd165]" + } + } + }, + { + "case": "hierarchy::named_array_parameters_keep_four_state_values", + "source_sha256": "c22969827d053f0d8c1382530727806db9e5c0179262e8c0ed8eb14b9c73e4e8", + "errors": [], + "bindings": { + "child.Q": { + "type": "logic[3:0]$[0:1]", + "value": "[4'b10xz,4'bz01x]" + } + } + } + ] +} diff --git a/crates/celox-test-suite/verification/repros/named_array_parameters_verilator.json b/crates/celox-test-suite/verification/repros/named_array_parameters_verilator.json new file mode 100644 index 00000000000..972eeb4fc90 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/named_array_parameters_verilator.json @@ -0,0 +1,66 @@ +{ + "cases": [ + { + "category": "Hierarchy", + "detail": "hierarchy::named_array_parameters_follow_caller_specialization at 690:3: assert_eq a: expected 0xfdfb, got 0xfbfd", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_follow_caller_specialization", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Verilator build exit status: 1; see /build.log\n%Error: /source_0.sv:11:18: Expecting expression to be constant, but variable isn't const: 'Q'\n : ... note: In instance 'celox_suite_tb.dut.middle'\n 11 | Child #(.Q(Q[1])) child(y);\n | ^\n ... See the manual at https://verilator.org/verilator_doc.html?v=5.052 for more assistance.\n%Error: /source_0.sv:11:16: Can't convert defparam value to constant: Param 'Q' of 'child'\n : ... note: In instance 'celox_suite_tb.dut.middle'\n 11 | Child #(.Q(Q[1])) child(y);\n | ^\n%Error: Exiting due to 2 error(s)\n", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_forward_package_subarrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_forward_whole_values", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_keep_four_state_values", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "counts": { + "compile_error": 1, + "emission_error": 0, + "ignored": 0, + "mismatch": 1, + "passed": 1, + "rejected": 0, + "runtime_error": 0, + "unexpected_accept": 0, + "unsupported": 1 + }, + "include_ignored": true, + "schema_version": 3, + "suite": "sv", + "suite_version": "0.11.0", + "tool": "verilator", + "version": "Verilator 5.052 2026-09-05 rev v5.052", + "note": "Focused observations before exact-case exclusions for named array parameter forwarding; shared assertions are preserved." +} diff --git a/crates/celox-test-suite/verification/sv/icarus/hierarchy.json b/crates/celox-test-suite/verification/sv/icarus/hierarchy.json index ee5f58bdfcb..1224737eb93 100644 --- a/crates/celox-test-suite/verification/sv/icarus/hierarchy.json +++ b/crates/celox-test-suite/verification/sv/icarus/hierarchy.json @@ -373,6 +373,102 @@ }, "phase": "skip", "status": "ignored" + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/named_array_parameters_icarus.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_named_array_parameters", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_follow_caller_specialization", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/named_array_parameters_icarus.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_named_array_parameters", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_forward_package_subarrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/named_array_parameters_icarus.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_named_array_parameters", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_forward_whole_values", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/named_array_parameters_icarus.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_named_array_parameters", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_keep_four_state_values", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 9fcd0f1feb8..9db98840e3b 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -1673,5 +1673,62 @@ "string::methods" ] } + }, + { + "id": "sv_verilator_array_parameter_bounds", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052", + "reason": "Verilator 5.052 reverses the elements when an ascending caller array overrides a descending unpacked parameter. IEEE 1800-2023 6.20.2 and 7.6 require assignment by left-to-right element order, independently of the bounds. Slang 12.0 elaborates Q[3:2] as [-3,-5] and [7,5], matching Celox; Verilator returns 0xfbfd instead of 0xfdfb.", + "upstream": [], + "evidence": [ + "verification/repros/named_array_parameters_verilator.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "hierarchy::named_array_parameters_follow_caller_specialization" + ] + } + }, + { + "id": "sv_verilator_array_parameter_subarray", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Verilator 5.052", + "reason": "Verilator 5.052 rejects Q[1] in a child parameter argument as nonconstant when Q is a multidimensional array parameter. IEEE 1800-2023 6.20.2 permits aggregate parameter values and constant member expressions. Slang 12.0 accepts the unchanged source and elaborates the child Q to [86,120], matching Celox.", + "upstream": [], + "evidence": [ + "verification/repros/named_array_parameters_verilator.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "hierarchy::named_array_parameters_forward_package_subarrays" + ] + } + }, + { + "id": "sv_icarus_named_array_parameters", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "reason": "Icarus 13.0 explicitly reports that unpacked array parameters are not supported. IEEE 1800-2023 6.20.2 permits these aggregate value parameters. Slang 12.0 accepts all four cases and confirms their parameter values; Verilator passes the whole-array forwarding case.", + "upstream": [], + "evidence": [ + "verification/repros/named_array_parameters_icarus.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "icarus": [ + "hierarchy::named_array_parameters_follow_caller_specialization", + "hierarchy::named_array_parameters_forward_package_subarrays", + "hierarchy::named_array_parameters_forward_whole_values", + "hierarchy::named_array_parameters_keep_four_state_values" + ] + } } ] diff --git a/crates/celox-test-suite/verification/sv/verilator/hierarchy.json b/crates/celox-test-suite/verification/sv/verilator/hierarchy.json index dc34ea1ce4d..1caa40418c8 100644 --- a/crates/celox-test-suite/verification/sv/verilator/hierarchy.json +++ b/crates/celox-test-suite/verification/sv/verilator/hierarchy.json @@ -132,6 +132,76 @@ "LIMITATIONS.md#systemverilog-suite" ] } + }, + { + "category": "Hierarchy", + "detail": "Verilator 5.052 reverses the elements when an ascending caller array overrides a descending unpacked parameter. IEEE 1800-2023 6.20.2 and 7.6 require assignment by left-to-right element order, independently of the bounds. Slang 12.0 elaborates Q[3:2] as [-3,-5] and [7,5], matching Celox; Verilator returns 0xfbfd instead of 0xfdfb.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/named_array_parameters_verilator.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_array_parameter_bounds", + "observed_version": "Verilator 5.052", + "phase": "execute", + "reason": "Verilator 5.052 reverses the elements when an ascending caller array overrides a descending unpacked parameter. IEEE 1800-2023 6.20.2 and 7.6 require assignment by left-to-right element order, independently of the bounds. Slang 12.0 elaborates Q[3:2] as [-3,-5] and [7,5], matching Celox; Verilator returns 0xfbfd instead of 0xfdfb.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_follow_caller_specialization", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Verilator 5.052 rejects Q[1] in a child parameter argument as nonconstant when Q is a multidimensional array parameter. IEEE 1800-2023 6.20.2 permits aggregate parameter values and constant member expressions. Slang 12.0 accepts the unchanged source and elaborates the child Q to [86,120], matching Celox.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/named_array_parameters_verilator.json", + "verification/repros/named_array_parameters_slang.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_array_parameter_subarray", + "observed_version": "Verilator 5.052", + "phase": "compile", + "reason": "Verilator 5.052 rejects Q[1] in a child parameter argument as nonconstant when Q is a multidimensional array parameter. IEEE 1800-2023 6.20.2 permits aggregate parameter values and constant member expressions. Slang 12.0 accepts the unchanged source and elaborates the child Q to [86,120], matching Celox.", + "upstream": [] + }, + "name": "hierarchy::named_array_parameters_forward_package_subarrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_forward_whole_values", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "hierarchy::named_array_parameters_keep_four_state_values", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox/tests/frontends/systemverilog/hierarchy.rs b/crates/celox/tests/frontends/systemverilog/hierarchy.rs index c1dc0f96413..e400c0a1882 100644 --- a/crates/celox/tests/frontends/systemverilog/hierarchy.rs +++ b/crates/celox/tests/frontends/systemverilog/hierarchy.rs @@ -1,6 +1,21 @@ use super::*; sv_backends! { + fn named_array_parameters_forward_whole_values(sim) { + @case "hierarchy::named_array_parameters_forward_whole_values"; + } + + fn named_array_parameters_forward_package_subarrays(sim) { + @case "hierarchy::named_array_parameters_forward_package_subarrays"; + } + + fn named_array_parameters_follow_caller_specialization(sim) { + @case "hierarchy::named_array_parameters_follow_caller_specialization"; + } + fn named_array_parameters_keep_four_state_values(sim) { + @case "hierarchy::named_array_parameters_keep_four_state_values"; + } + fn sized_parameter_actuals_follow_parent_specialization(sim) { @case "hierarchy::sized_parameter_actuals_follow_parent_specialization"; } @@ -392,3 +407,39 @@ sv_backends! { assert_eq!(sim.get(sim.signal("matched")), BigUint::from(1u8)); } } + +#[test] +fn rejects_incompatible_named_array_parameter_overrides() { + for declaration in [ + "logic [7:0] TABLE[3] = '{1, 2, 3}", + "logic [3:0] TABLE[2] = '{1, 2}", + "logic signed [7:0] TABLE[2] = '{1, 2}", + "bit [7:0] TABLE[2] = '{1, 2}", + "logic [7:0] TABLE[1][2] = '{'{1, 2}}", + ] { + let source = format!( + r#" + module Child #(parameter logic [7:0] Q[2] = '{{0, 0}})(output logic [7:0] y); + assign y = Q[0]; + endmodule + module Top(output logic [7:0] y); + localparam {declaration}; + Child #(.Q(TABLE)) child(y); + endmodule + "# + ); + let error = match Simulator::from_sv_sources( + vec![(&source, Path::new("array_override.sv"))], + "Top", + ) + .build_cranelift() + { + Err(error) => error, + Ok(_) => panic!("incompatible array parameter must be rejected"), + }; + assert!( + error.to_string().contains("is not assignment compatible"), + "{declaration}: {error}" + ); + } +}