Add regression test for recursive function using `return

Add a regression test that checks that recursive functions using a `return`
statement work correctly.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-04-11 17:51:14 +02:00
parent 84c3c72563
commit 5b6d8e968d
5 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,46 @@
// Check that recursive functions are supported when the `return` statement is
// used.
module recursive_func();
function automatic [15:0] factorial(input [15:0] n);
if (n > 1) begin : recursion
reg [15:0] result;
result = factorial(n - 1) * n;
return result;
end
return n;
endfunction
reg [15:0] r1;
reg [15:0] r2;
reg [15:0] r3;
initial begin
fork
r1 = factorial(3);
r2 = factorial(4);
r3 = factorial(5);
join
$display("factorial 3 = %0d", r1);
$display("factorial 4 = %0d", r2);
$display("factorial 5 = %0d", r3);
end
wire [15:0] r4;
wire [15:0] r5;
wire [15:0] r6;
assign r4 = factorial(6);
assign r5 = factorial(7);
assign r6 = factorial(8);
initial begin
#1;
$display("factorial 6 = %0d", r4);
$display("factorial 7 = %0d", r5);
$display("factorial 8 = %0d", r6);
end
endmodule

View File

@ -402,6 +402,7 @@ program5a CE,-g2009 ivltests
program5b CE,-g2009 ivltests
program_hello normal,-g2009 ivltests
program_hello2 CE,-g2009 ivltests
recursive_func2 normal,-g2005-sv ivltests gold=recursive_func.gold
sbyte_test normal,-g2005-sv ivltests
scalar_vector normal,-g2005-sv ivltests
sf_countbits normal,-g2012 ivltests

View File

@ -1469,7 +1469,7 @@ real_force_rel normal ivltests
real_invalid_ops CE ivltests gold=real_invalid_ops.gold
real_logical normal ivltests
real_reg_force_rel normal ivltests
recursive_func normal ivltests gold=recursive_func.gold
recursive_func1 normal ivltests gold=recursive_func.gold
recursive_task normal ivltests gold=recursive_task.gold
redef_net_error CE ivltests
redef_reg_error CE ivltests

View File

@ -90,7 +90,8 @@ pr2172606b CE ivltests
pr2276163 CE ivltests
pr2929913 CE ivltests
real_events CE ivltests
recursive_func CE ivltests
recursive_func1 CE ivltests
recursive_func2 CE ivltests
recursive_task CE ivltests
task_init_var1 CE,-pallowsigned=1 ivltests
task_init_var2 CE,-pallowsigned=1 ivltests