-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sv: support assignments within expressions #3920
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,73 @@ | ||
module top; | ||
integer x, y, z; | ||
task check; | ||
input integer a, b, c; | ||
assert (x == a); | ||
assert (y == b); | ||
assert (z == c); | ||
endtask | ||
always_comb begin | ||
x = 0; y = 0; z = 0; | ||
check(0, 0, 0); | ||
|
||
// post-increment/decrement statements | ||
x++; | ||
check(1, 0, 0); | ||
(* bar *) y (* foo *) ++; | ||
check(1, 1, 0); | ||
z--; | ||
check(1, 1, -1); | ||
(* bar *) z (* foo *) --; | ||
check(1, 1, -2); | ||
|
||
// pre-increment/decrement statements are equivalent | ||
++z; | ||
check(1, 1, -1); | ||
(* bar *) ++ (* foo *) z; | ||
check(1, 1, 0); | ||
--x; | ||
check(0, 1, 0); | ||
(* bar *) -- (* foo *) y; | ||
check(0, 0, 0); | ||
|
||
// procedural pre-increment/decrement expressions | ||
z = ++x; | ||
check(1, 0, 1); | ||
z = ++ (* foo *) x; | ||
check(2, 0, 2); | ||
y = --x; | ||
check(1, 1, 2); | ||
y = -- (* foo *) x; | ||
|
||
// procedural post-increment/decrement expressions | ||
// TODO: support attributes on post-increment/decrement | ||
check(0, 0, 2); | ||
y = x++; | ||
check(1, 0, 2); | ||
y = x--; | ||
check(0, 1, 2); | ||
|
||
// procedural assignment expressions | ||
x = (y = (z = 99) + 1) + 1; | ||
check(101, 100, 99); | ||
x = (y *= 2); | ||
check(200, 200, 99); | ||
x = (z >>= 2) * 4; | ||
check(96, 200, 24); | ||
y = (z >>= 1'sb1) * 2; // shift is implicitly cast to unsigned | ||
check(96, 24, 12); | ||
|
||
// check width of post-increment expressions | ||
z = (y = 0); | ||
begin | ||
byte w; | ||
w = 0; | ||
x = {1'b1, ++w}; | ||
check(257, 0, 0); | ||
assert (w == 1); | ||
x = {2'b10, w++}; | ||
check(513, 0, 0); | ||
assert (w == 2); | ||
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,3 @@ | ||
read_verilog -sv asgn_expr.sv | ||
proc | ||
sat -verify -prove-asserts -show-all |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only permitted within procedures." 1 | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x, y; | ||
assign x = y++; | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only permitted within procedures." 1 | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x; | ||
wire [++x:0] y; | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only permitted within procedures." 1 | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x; | ||
integer y = --x; | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only permitted within procedures." 1 | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x, y; | ||
assign x = (y = 1); | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only permitted within procedures." 1 | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x, y; | ||
assign x = (y += 2); | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only supported in SystemVerilog mode." 1 | ||
read_verilog <<EOF | ||
module top; | ||
integer x, y; | ||
initial y = ++x; | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only supported in SystemVerilog mode." 1 | ||
read_verilog <<EOF | ||
module top; | ||
integer x, y; | ||
initial y = x++; | ||
endmodule | ||
EOF |
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,7 @@ | ||
logger -expect error "Assignments within expressions are only supported in SystemVerilog mode." 1 | ||
read_verilog <<EOF | ||
module top; | ||
integer x, y; | ||
initial y = (x = 1); | ||
endmodule | ||
EOF |
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,15 @@ | ||
read_verilog -sv <<EOF | ||
module top; | ||
integer x, y; | ||
initial y = (x += 1); | ||
endmodule | ||
EOF | ||
design -reset | ||
|
||
logger -expect error "syntax error, unexpected TOK_ID" 1 | ||
read_verilog <<EOF | ||
module top; | ||
integer x, y; | ||
initial y = (x += 1); | ||
endmodule | ||
EOF |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to recover the sizing information here, or do something other than the plus one minus one dance (maybe an assignment to a dummy wire?). Consider the following:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great catch! I should have set the width of
minus_one
explicitly to prevent it from affecting the width of the expression. This logic seems simpler than the alternatives I considered: A) adding a temporary wire; or B) actually doing the increment afterwards. That said, my preference here likely comes from having done it the same way in sv2v.