Skip to content

Commit

Permalink
Add regression tests for checking constant function call scopes.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinwhitaker committed Jun 30, 2024
1 parent f3092bb commit 5cbdff2
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ivtest/gold/constfunccall3-iverilog-stderr.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ivltests/constfunccall3.v:21: error: A function invoked by a constant function must be a constant function local to the current module or provided by a package.
ivltests/constfunccall3.v:26: error: `f2' is not a constant function.
2 error(s) during elaboration.
32 changes: 32 additions & 0 deletions ivtest/ivltests/constfunccall1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Check that a constant function call is permitted when the call is inside
// a named block (issue #1141)

module test;

function integer f1(input integer i);

begin
f1 = i + 1;
end

endfunction

function integer f2(input integer i);

begin : b2
f2 = f1(i);
end

endfunction

localparam p = f2(1);

initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end

endmodule
36 changes: 36 additions & 0 deletions ivtest/ivltests/constfunccall2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Check that a constant function call is permitted when the function is
// provided by a package.

package p1;

function integer f1(input integer i);

begin
f1 = i + 1;
end

endfunction

endpackage

module test;

function integer f2(input integer i);

begin
f2 = p1::f1(i);
end

endfunction

localparam p = f2(1);

initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end

endmodule
36 changes: 36 additions & 0 deletions ivtest/ivltests/constfunccall3.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Check that a constant function call is permitted when the function is
// provided by a package.

module m1;

function integer f1(input integer i);

begin
f1 = i + 1;
end

endfunction

endmodule

module test;

function integer f2(input integer i);

begin
f2 = m1.f1(i);
end

endfunction

localparam p = f2(1);

initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end

endmodule
3 changes: 3 additions & 0 deletions ivtest/regress-vvp.list
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ constfunc17 vvp_tests/constfunc17.json
constfunc18 vvp_tests/constfunc18.json
constfunc19 vvp_tests/constfunc19.json
constfunc20 vvp_tests/constfunc20.json
constfunccall1 vvp_tests/constfunccall1.json
constfunccall2 vvp_tests/constfunccall2.json
constfunccall3 vvp_tests/constfunccall3.json
decl_before_use1 vvp_tests/decl_before_use1.json
decl_before_use2 vvp_tests/decl_before_use2.json
decl_before_use3 vvp_tests/decl_before_use3.json
Expand Down
4 changes: 4 additions & 0 deletions ivtest/vvp_tests/constfunccall1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "normal",
"source" : "constfunccall1.v"
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/constfunccall2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "constfunccall2.v",
"iverilog-args" : [ "-g2009" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/constfunccall3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "constfunccall3.v",
"gold" : "constfunccall3"
}

0 comments on commit 5cbdff2

Please sign in to comment.