From 9f8a8959a75259e899f6b9b94cba78839534043f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 3 Jan 2025 12:28:42 -0800 Subject: [PATCH] Add regression tests for assignment operators on queue and darray elements Check that assignment operators work as expected on queue and dynamic array elements. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_darray_assign_op.v | 86 +++++++++++++++++++++++ ivtest/ivltests/sv_queue_assign_op.v | 84 ++++++++++++++++++++++ ivtest/regress-vvp.list | 2 + ivtest/vvp_tests/sv_darray_assign_op.json | 5 ++ ivtest/vvp_tests/sv_queue_assign_op.json | 5 ++ tgt-vvp/stmt_assign.c | 1 + 6 files changed, 183 insertions(+) create mode 100644 ivtest/ivltests/sv_darray_assign_op.v create mode 100644 ivtest/ivltests/sv_queue_assign_op.v create mode 100644 ivtest/vvp_tests/sv_darray_assign_op.json create mode 100644 ivtest/vvp_tests/sv_queue_assign_op.json diff --git a/ivtest/ivltests/sv_darray_assign_op.v b/ivtest/ivltests/sv_darray_assign_op.v new file mode 100644 index 000000000..c57818932 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_op.v @@ -0,0 +1,86 @@ +// Check that assignment operators are supported on dynamic array elements. + +module test; + + bit failed = 1'b0; + + `define check(val, exp) do \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \ + failed = 1'b1; \ + end \ + while(0) + + integer x[]; + integer i; + + initial begin + x = new[2]; + + // Static index + x[1] = 1; + x[1] += 5; + `check(x[1], 6); + x[1] -= 2; + `check(x[1], 4); + x[1] *= 25; + `check(x[1], 100); + x[1] /= 5; + `check(x[1], 20); + x[1] %= 3; + `check(x[1], 2); + + x[1] = 'haa; + x[1] &= 'h33; + `check(x[1], 'h22); + x[1] |= 'h11; + `check(x[1], 'h33); + x[1] ^= 'h22; + `check(x[1], 'h11); + + x[1] <<= 3; + `check(x[1], 'h88); + x[1] <<<= 1; + `check(x[1], 'h110); + x[1] >>= 2; + `check(x[1], 'h44); + x[1] >>>= 1; + `check(x[1], 'h22); + + // Dynamic index + x[1] = 1; + i = 1; + x[i] += 5; + `check(x[i], 6); + x[i] -= 2; + `check(x[i], 4); + x[i] *= 25; + `check(x[i], 100); + x[i] /= 5; + `check(x[i], 20); + x[i] %= 3; + `check(x[i], 2); + + x[i] = 'haa; + x[i] &= 'h33; + `check(x[i], 'h22); + x[i] |= 'h11; + `check(x[i], 'h33); + x[i] ^= 'h22; + `check(x[i], 'h11); + + x[i] <<= 3; + `check(x[i], 'h88); + x[i] <<<= 1; + `check(x[i], 'h110); + x[i] >>= 2; + `check(x[i], 'h44); + x[i] >>>= 1; + `check(x[i], 'h22); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_op.v b/ivtest/ivltests/sv_queue_assign_op.v new file mode 100644 index 000000000..c97e9c980 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_op.v @@ -0,0 +1,84 @@ +// Check that assignment operators are supported on queue elements. + +module test; + + bit failed = 1'b0; + + `define check(val, exp) do \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \ + failed = 1'b1; \ + end \ + while(0) + + integer x[$]; + integer i; + + initial begin + x = '{0, 1}; + // Static index + x[1] += 5; + `check(x[1], 6); + x[1] -= 2; + `check(x[1], 4); + x[1] *= 25; + `check(x[1], 100); + x[1] /= 5; + `check(x[1], 20); + x[1] %= 3; + `check(x[1], 2); + + x[1] = 'haa; + x[1] &= 'h33; + `check(x[1], 'h22); + x[1] |= 'h11; + `check(x[1], 'h33); + x[1] ^= 'h22; + `check(x[1], 'h11); + + x[1] <<= 3; + `check(x[1], 'h88); + x[1] <<<= 1; + `check(x[1], 'h110); + x[1] >>= 2; + `check(x[1], 'h44); + x[1] >>>= 1; + `check(x[1], 'h22); + + // Dynamic index + x[1] = 1; + i = 1; + x[i] += 5; + `check(x[i], 6); + x[i] -= 2; + `check(x[i], 4); + x[i] *= 25; + `check(x[i], 100); + x[i] /= 5; + `check(x[i], 20); + x[i] %= 3; + `check(x[i], 2); + + x[i] = 'haa; + x[i] &= 'h33; + `check(x[i], 'h22); + x[i] |= 'h11; + `check(x[i], 'h33); + x[i] ^= 'h22; + `check(x[i], 'h11); + + x[i] <<= 3; + `check(x[i], 'h88); + x[i] <<<= 1; + `check(x[i], 'h110); + x[i] >>= 2; + `check(x[i], 'h44); + x[i] >>>= 1; + `check(x[i], 'h22); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 07e2b64a8..dcba81515 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -239,6 +239,7 @@ sv_const_fail6 vvp_tests/sv_const_fail6.json sv_const_fail7 vvp_tests/sv_const_fail7.json sv_const_fail8 vvp_tests/sv_const_fail8.json sv_const_fail9 vvp_tests/sv_const_fail9.json +sv_darray_assign_op vvp_tests/sv_darray_assign_op.json sv_default_port_value1 vvp_tests/sv_default_port_value1.json sv_default_port_value2 vvp_tests/sv_default_port_value2.json sv_default_port_value3 vvp_tests/sv_default_port_value3.json @@ -257,6 +258,7 @@ sv_module_port2 vvp_tests/sv_module_port2.json sv_module_port3 vvp_tests/sv_module_port3.json sv_module_port4 vvp_tests/sv_module_port4.json sv_parameter_type vvp_tests/sv_parameter_type.json +sv_queue_assign_op vvp_tests/sv_queue_assign_op.json sv_wildcard_import8 vvp_tests/sv_wildcard_import8.json sdf_header vvp_tests/sdf_header.json task_return1 vvp_tests/task_return1.json diff --git a/ivtest/vvp_tests/sv_darray_assign_op.json b/ivtest/vvp_tests/sv_darray_assign_op.json new file mode 100644 index 000000000..065ed73fa --- /dev/null +++ b/ivtest/vvp_tests/sv_darray_assign_op.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_darray_assign_op.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_queue_assign_op.json b/ivtest/vvp_tests/sv_queue_assign_op.json new file mode 100644 index 000000000..b4c2136ec --- /dev/null +++ b/ivtest/vvp_tests/sv_queue_assign_op.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_queue_assign_op.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/tgt-vvp/stmt_assign.c b/tgt-vvp/stmt_assign.c index c76954cd0..94aed6242 100644 --- a/tgt-vvp/stmt_assign.c +++ b/tgt-vvp/stmt_assign.c @@ -1066,6 +1066,7 @@ static void show_stmt_assign_sig_darray_queue_mux(ivl_statement_t net) case IVL_VT_STRING: assert(ivl_stmt_opcode(net) == 0); draw_eval_string(rval); + draw_eval_expr_into_integer(mux, 3); break; case IVL_VT_BOOL: case IVL_VT_LOGIC: