Files
iverilog/ivtest/ivltests/recursive_func_const1.v
T
Lars-Peter Clausen 338516bc55 Add regression tests for constant recursive functions
Check that constant recursive functions are supported. Check both Verilog
style using assignments to the implicit function return signal and
SystemVerilog style using `return`.

Signed-off-by: Lars-Peter Clausen <[email protected]>
2022-04-11 22:03:02 +02:00

26 lines
445 B
Verilog

// Check that constant recursive functions are supported.
module recursive_func();
function automatic [15:0] factorial;
input [15:0] n;
begin
factorial = (n > 1) ? factorial(n - 1) * n : n;
end
endfunction
localparam F3 = factorial(3);
localparam F4 = factorial(4);
localparam F5 = factorial(5);
initial begin
$display("factorial 3 = %0d", F3);
$display("factorial 4 = %0d", F4);
$display("factorial 5 = %0d", F5);
end
endmodule