-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression tests for const variables
Check that const variables are supported and they can not be overridden by type of assignment. Signed-off-by: Lars-Peter Clausen <[email protected]>
- Loading branch information
1 parent
3daa298
commit f092820
Showing
27 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Check that const variables in module scope are supported. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
// The initializer expression is allowed to reference other const variables. | ||
const integer y = 20 + x; | ||
|
||
initial begin | ||
if (x === 10 && y === 30) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Check that const variables are supported in function and task scope. | ||
|
||
module test; | ||
|
||
function automatic integer f(integer x); | ||
// Automatic const variables can have a non-const initializer epxression | ||
const integer y = 2 * x; | ||
return y; | ||
endfunction | ||
|
||
task automatic t(input integer x, output integer y); | ||
// Automatic const variables can have a non-const initializer epxression | ||
const integer z = 2 * x; | ||
y = z; | ||
endtask | ||
|
||
initial begin | ||
integer y; | ||
|
||
t(15, y); | ||
|
||
if (f(10) === 20 && y === 30) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Check that const variables in block scope are supported. | ||
|
||
module test; | ||
|
||
initial begin | ||
const static integer x = 10; | ||
// The initializer expression is allowed to reference other const variables. | ||
const static integer y = 20 + x; | ||
|
||
if (x === 10 && y === 30) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Check that const variables are supported in the unit scope. | ||
|
||
const integer x = 10; | ||
|
||
// The initializer expression is allowed to reference other const variables. | ||
const integer y = 20 + x; | ||
|
||
module test; | ||
|
||
initial begin | ||
if (x === 10 && y === 30) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Check that const variables are supported in a package scope. | ||
|
||
package P; | ||
const integer x = 10; | ||
|
||
// The initializer expression is allowed to reference other const variables. | ||
const integer y = 20 + x; | ||
endpackage | ||
|
||
module test; | ||
|
||
initial begin | ||
if (P::x === 10 && P::y === 30) begin | ||
$display("PASSED"); | ||
end else begin | ||
$display("FAILED"); | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Check that continuous assignment to a const variable fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
assign x = 20; // Error: Assignment to const variable | ||
|
||
initial begin | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Check that blocking assignment to a const variable fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
initial begin | ||
x = 20; // Error: Assignment to const variable | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Check that non-blocking assignment to a const variable fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
initial begin | ||
x <= 20; // Error: Assignment to const variable | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Check that force assignment to a const variable fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
initial begin | ||
force x = 20; // Error: Assignment to const variable | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Check that procedural continuous assignment to a const variable fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
initial begin | ||
assign x = 20; // Error: Assignment to const variable | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Check that binding a const variable to a task output port fails. | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
task t(output integer x); | ||
x = 20; | ||
endtask | ||
|
||
initial begin | ||
t(x); | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Check that binding a const variable to a module output port fails. | ||
|
||
module M( | ||
output integer x | ||
); | ||
assign x = 20; | ||
endmodule | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
M i_m ( | ||
.x (x) | ||
); | ||
|
||
initial begin | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Check that binding a const variable to a module inout port fails. | ||
|
||
module M( | ||
inout integer x | ||
); | ||
assign x = 20; | ||
endmodule | ||
|
||
module test; | ||
|
||
const integer x = 10; | ||
|
||
M i_m ( | ||
.x (x) | ||
); | ||
|
||
initial begin | ||
$display("FAILED"); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_const1.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_const2.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_const3.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_const4.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "normal", | ||
"source" : "sv_const5.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail1.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail2.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail3.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail4.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail5.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail6.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail7.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type" : "CE", | ||
"source" : "sv_const_fail8.v", | ||
"iverilog-args" : [ "-g2005-sv" ] | ||
} |