-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert severity and elaboration system tasks (#276)
- Loading branch information
Showing
14 changed files
with
167 additions
and
7 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
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,64 @@ | ||
{- sv2v | ||
- Author: Ethan Sifferman <ethan@sifferman.dev> | ||
- | ||
- Conversion of severity system tasks (IEEE 1800-2017 Section 20.10) and | ||
- elaboration system tasks (Section 20.11) `$info`, `$warning`, `$error`, and | ||
- `$fatal`, which sv2v collectively refers to as "severity tasks". | ||
- | ||
- 1. Severity task messages are converted into `$display` tasks. | ||
- 2. `$fatal` tasks also run `$finish` directly after running `$display`. | ||
-} | ||
|
||
module Convert.SeverityTask (convert) where | ||
|
||
import Data.Char (toUpper) | ||
import Data.Functor ((<&>)) | ||
|
||
import Convert.Scoper | ||
import Convert.Traverse | ||
import Language.SystemVerilog.AST | ||
|
||
type SC = Scoper () | ||
|
||
convert :: [AST] -> [AST] | ||
convert = map $ traverseDescriptions traverseDescription | ||
|
||
traverseDescription :: Description -> Description | ||
traverseDescription = partScoper return traverseModuleItem return traverseStmt | ||
|
||
-- convert elaboration severity tasks | ||
traverseModuleItem :: ModuleItem -> SC ModuleItem | ||
traverseModuleItem (ElabTask severity taskArgs) = | ||
elab severity taskArgs "elaboration" [] <&> Initial | ||
traverseModuleItem other = return other | ||
|
||
-- convert standard severity tasks | ||
traverseStmt :: Stmt -> SC Stmt | ||
traverseStmt (SeverityStmt severity taskArgs) = | ||
elab severity taskArgs "%0t" [Ident "$time"] | ||
traverseStmt other = return other | ||
|
||
elab :: Severity -> [Expr] -> String -> [Expr] -> SC Stmt | ||
elab severity args prefixStr prefixArgs = do | ||
scopeName <- hierarchyPathM | ||
fileLocation <- sourceLocationM | ||
let contextArg = String $ msg scopeName fileLocation | ||
let stmtDisplay = call "$display" $ contextArg : prefixArgs ++ displayArgs | ||
return $ Block Seq "" [] [stmtDisplay, stmtFinish] | ||
where | ||
msg scope file = severityToString severity ++ " [" ++ prefixStr ++ "] " | ||
++ file ++ " - " ++ scope | ||
++ if null displayArgs then "" else "\\n msg: " | ||
displayArgs = if severity /= SeverityFatal || null args | ||
then args | ||
else tail args | ||
stmtFinish = if severity /= SeverityFatal | ||
then Null | ||
else call "$finish" $ if null args then [] else [head args] | ||
|
||
call :: Identifier -> [Expr] -> Stmt | ||
call func args = Subroutine (Ident func) (Args args []) | ||
|
||
severityToString :: Severity -> String | ||
severityToString severity = toUpper ch : str | ||
where '$' : ch : str = show severity |
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ module top; | |
$error; | ||
$error("%b", 3); | ||
$fatal; | ||
$fatal("%b", 4); | ||
$fatal(0); | ||
$fatal(1, "%b", 4); | ||
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,5 @@ | ||
affirm $finish; | ||
affirm $display("Fatal [elaboration] elab_task.sv:9:5 - top"); | ||
affirm $finish(0); | ||
affirm $display("Fatal [elaboration] elab_task.sv:10:5 - top\\n msg: ", "%b", 4); | ||
affirm $finish(1); |
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 @@ | ||
module top; | ||
initial $display("Info [elaboration] elab_task.sv:2:5 - top"); | ||
initial $display("Info [elaboration] elab_task.sv:3:5 - top\n msg: %b", 1); | ||
initial $display("Warning [elaboration] elab_task.sv:4:5 - top"); | ||
initial $display("Warning [elaboration] elab_task.sv:5:5 - top\n msg: %b", 2); | ||
initial $display("Error [elaboration] elab_task.sv:6:5 - top"); | ||
initial $display("Error [elaboration] elab_task.sv:7:5 - top\n msg: %b", 3); | ||
initial begin | ||
$display("Fatal [elaboration] elab_task.sv:8:5 - top"); | ||
$finish; | ||
end | ||
initial begin | ||
$display("Fatal [elaboration] elab_task.sv:9:5 - top"); | ||
$finish(0); | ||
end | ||
initial begin | ||
$display("Fatal [elaboration] elab_task.sv:10:5 - top\n msg: %b", 4); | ||
$finish(1); | ||
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 @@ | ||
module top; | ||
initial begin | ||
$info; | ||
$info("%b", 1); | ||
$warning; | ||
$warning("%b", 2); | ||
$error; | ||
$error("%b", 3); | ||
$fatal; | ||
$fatal(0); | ||
$fatal(1, "%b", 4); | ||
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,5 @@ | ||
affirm $finish; | ||
affirm $display("Fatal [%0t] severity_task.sv:10:9 - top.<unnamed_block>", $time); | ||
affirm $finish(0); | ||
affirm $display("Fatal [%0t] severity_task.sv:11:9 - top.<unnamed_block>\\n msg: ", $time, "%b", 4); | ||
affirm $finish(1); |
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 @@ | ||
module top; | ||
initial begin | ||
$display("Info [%0t] severity_task.sv:3:9 - top.<unnamed_block>", $time); | ||
$display("Info [%0t] severity_task.sv:4:9 - top.<unnamed_block>\n msg: ", $time, "%b", 1); | ||
$display("Warning [%0t] severity_task.sv:5:9 - top.<unnamed_block>", $time); | ||
$display("Warning [%0t] severity_task.sv:6:9 - top.<unnamed_block>\n msg: ", $time, "%b", 2); | ||
$display("Error [%0t] severity_task.sv:7:9 - top.<unnamed_block>", $time); | ||
$display("Error [%0t] severity_task.sv:8:9 - top.<unnamed_block>\n msg: ", $time, "%b", 3); | ||
$display("Fatal [%0t] severity_task.sv:9:9 - top.<unnamed_block>", $time); | ||
$finish; | ||
$display("Fatal [%0t] severity_task.sv:10:9 - top.<unnamed_block>", $time); | ||
$finish(0); | ||
$display("Fatal [%0t] severity_task.sv:11:9 - top.<unnamed_block>\n msg: ", $time, "%b", 4); | ||
$finish(1); | ||
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