diff --git a/ivtest/ivltests/recursive_func.v b/ivtest/ivltests/recursive_func1.v similarity index 100% rename from ivtest/ivltests/recursive_func.v rename to ivtest/ivltests/recursive_func1.v diff --git a/ivtest/ivltests/recursive_func2.v b/ivtest/ivltests/recursive_func2.v new file mode 100644 index 000000000..2fd45cbae --- /dev/null +++ b/ivtest/ivltests/recursive_func2.v @@ -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 diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 8a69255de..ef58758eb 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -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 diff --git a/ivtest/regress-vlg.list b/ivtest/regress-vlg.list index 850341b19..cfa4b3b1a 100644 --- a/ivtest/regress-vlg.list +++ b/ivtest/regress-vlg.list @@ -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 diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 6569c8c60..8e5fcf2be 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -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