From 28187823eda1c49470ed50177f1cc97aa944b3f7 Mon Sep 17 00:00:00 2001 From: Paul Rigge Date: Thu, 11 Apr 2024 15:56:20 -0700 Subject: [PATCH] Update handling of single-element arrays. Also, add a test. This fixes #1113. --- ivtest/ivltests/single_element_array.v | 31 ++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/single_element_array.json | 4 +++ tgt-vvp/vvp_scope.c | 8 +++--- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 ivtest/ivltests/single_element_array.v create mode 100644 ivtest/vvp_tests/single_element_array.json diff --git a/ivtest/ivltests/single_element_array.v b/ivtest/ivltests/single_element_array.v new file mode 100644 index 0000000000..18f91175d6 --- /dev/null +++ b/ivtest/ivltests/single_element_array.v @@ -0,0 +1,31 @@ +module SingleElementArray( + input wire [48:0] x1, + output wire [48:0] out +); + wire [48:0] x17[0:0]; + assign x17[0] = x1; + assign out = {x17[0]}; +endmodule + +module testbench; + reg [48:0] in; + wire [48:0] out; + + SingleElementArray dut(.x1(in), .out(out)); + + initial begin + in = 49'h0000000000000; + #1; + if (out != 49'h0000000000000) begin + $display("FAILED"); + $finish; + end + in = 49'h1555555555555; + #1; + if (out != 49'h1555555555555) begin + $display("FAILED"); + $finish; + end + $display("PASSED"); + end +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 1e67e16b98..cb56e7b661 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -173,6 +173,7 @@ sf_countones_fail vvp_tests/sf_countones_fail.json sf_isunknown_fail vvp_tests/sf_isunknown_fail.json sf_onehot_fail vvp_tests/sf_onehot_fail.json sf_onehot0_fail vvp_tests/sf_onehot0_fail.json +single_element_array vvp_tests/single_element_array.json struct_enum_partsel vvp_tests/struct_enum_partsel.json struct_field_left_right vvp_tests/struct_field_left_right.json struct_nested1 vvp_tests/struct_nested1.json diff --git a/ivtest/vvp_tests/single_element_array.json b/ivtest/vvp_tests/single_element_array.json new file mode 100644 index 0000000000..cfc255c36a --- /dev/null +++ b/ivtest/vvp_tests/single_element_array.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "single_element_array.v" +} diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index c4a6599581..978b27d59f 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -689,7 +689,6 @@ static void draw_net_in_scope(ivl_signal_t sig) nex_data->net_word = iword; } else if (dimensions > 0) { - /* In this case, we have an alias to an existing signal array. this typically is an instance of port collapsing that the elaborator combined to @@ -697,13 +696,14 @@ static void draw_net_in_scope(ivl_signal_t sig) so the word count for the signal and the alias *must* match. */ - if (word_count == ivl_signal_array_count(nex_data->net)) { - if (iword == 0) { + if (ivl_signal_dimensions(nex_data->net) > 0 && + word_count == ivl_signal_array_count(nex_data->net)) { + if (iword == 0) { fprintf(vvp_out, "v%p .array \"%s\", v%p; Alias to %s \n", sig, vvp_mangle_name(ivl_signal_basename(sig)), nex_data->net, ivl_signal_basename(nex_data->net)); - } + } /* An alias for an individual word. */ } else { if (iword == 0) {