diff --git a/test_regress/t/t_foreach.pl b/test_regress/t/t_foreach.pl index 60e20ab59..6b3172aee 100755 --- a/test_regress/t/t_foreach.pl +++ b/test_regress/t/t_foreach.pl @@ -15,5 +15,14 @@ execute ( check_finished=>1, ); +# We expect all loops should be unrolled by verilator, +# none of the loop variables should exist in the output: +file_grep_not ("$Self->{obj_dir}/$Self->{VM_PREFIX}.cpp", qr/index_/); + +# Further, we expect that all logic within the loop should +# have been evaluated inside the compiler. So there should be +# no references to 'sum' in the .cpp. +file_grep_not ("$Self->{obj_dir}/$Self->{VM_PREFIX}.cpp", qr/sum/); + ok(1); 1; diff --git a/test_regress/t/t_foreach.v b/test_regress/t/t_foreach.v index 4c9f4c649..e6dcc5cfd 100644 --- a/test_regress/t/t_foreach.v +++ b/test_regress/t/t_foreach.v @@ -21,64 +21,68 @@ module t (/*AUTOARG*/); initial begin sum = 0; - foreach (depth1_array[index]) begin - sum = crc(sum, index, 0, 0, 0); + // We use 'index_' as the prefix for all loop vars, + // this allows t_foreach.pl to confirm that all loops + // have been unrolled and flattened away and no loop vars + // remain in the generated .cpp + foreach (depth1_array[index_a]) begin + sum = crc(sum, index_a, 0, 0, 0); // Ensure the index never goes out of bounds. // We used to get this wrong for an array of depth 1. - assert (index != -1); - assert (index != 1); + assert (index_a != -1); + assert (index_a != 1); end `checkh(sum, 64'h0); sum = 0; - foreach (array[a]) begin - sum = crc(sum, a, 0, 0, 0); + foreach (array[index_a]) begin + sum = crc(sum, index_a, 0, 0, 0); end `checkh(sum, 64'h000000c000000000); sum = 0; - foreach (array[a,b]) begin - sum = crc(sum, a, b, 0, 0); + foreach (array[index_a,index_b]) begin + sum = crc(sum, index_a, index_b, 0, 0); end `checkh(sum, 64'h000003601e000000); sum = 0; - foreach (array[a,b,c]) begin - sum = crc(sum, a, b, c, 0); + foreach (array[index_a,index_b,index_c]) begin + sum = crc(sum, index_a, index_b, index_c, 0); end `checkh(sum, 64'h00003123fc101000); sum = 0; - foreach (array[a,b,c,d]) begin - sum = crc(sum, a, b, c, d); + foreach (array[index_a,index_b,index_c,index_d]) begin + sum = crc(sum, index_a, index_b, index_c, index_d); end `checkh(sum, 64'h0030128ab2a8e557); // sum = 0; - foreach (larray[a]) begin - sum = crc(sum, a, 0, 0, 0); + foreach (larray[index_a]) begin + sum = crc(sum, index_a, 0, 0, 0); end `checkh(sum, 64'h0000009000000000); sum = 0; - foreach (larray[a,b]) begin - sum = crc(sum, a, b, 0, 0); - sum = sum + {4'b0,a[7:0], 4'h0,b[7:0]}; + foreach (larray[index_a,index_b]) begin + sum = crc(sum, index_a, index_b, 0, 0); + sum = sum + {4'b0,index_a[7:0], 4'h0,index_b[7:0]}; end `checkh(sum, 64'h000002704b057073); sum = 0; - foreach (larray[a,b,c]) begin - sum = crc(sum, a, b, c, 0); + foreach (larray[index_a,index_b,index_c]) begin + sum = crc(sum, index_a, index_b, index_c, 0); end `checkh(sum, 64'h00002136f9000000); sum = 0; - foreach (larray[a,b,c,d]) begin - sum = crc(sum, a, b, c, d); + foreach (larray[index_a,index_b,index_c,index_d]) begin + sum = crc(sum, index_a, index_b, index_c, index_d); end `checkh(sum, 64'h0020179aa7aa0aaa);