initial stylistic changes in SeverityTask.hs

This commit is contained in:
Zachary Snow 2024-04-20 21:04:24 -04:00
parent f922b5ce6b
commit 8c41d049e5
1 changed files with 41 additions and 47 deletions

View File

@ -4,11 +4,11 @@
- Conversion of standard and elaboration severity tasks `$info`, `$warning`,
- `$error`, and `$fatal` (20.10 and 20.11).
-
- * Severity task messages are converted into `$display` tasks.
- * Standard `$fatal` tasks run `$finish` directly after running `$display`.
- * Elaboration `$fatal` tasks set `_sv2v_elaboration_fatal` to a
- non-negative value, causing the simulation to exit once all elaboration
- severity task messages have been printed.
- 1. Severity task messages are converted into `$display` tasks.
- 2. Standard `$fatal` tasks run `$finish` directly after running `$display`.
- 3. Elaboration `$fatal` tasks set `_sv2v_elaboration_fatal` to a non-negative
- value, causing the simulation to exit once all elaboration severity task
- messages have been printed.
-}
module Convert.SeverityTask (convert) where
@ -29,16 +29,20 @@ elaborationFatalCancelCode = UniOp UniSub $ RawNum 1
-- Checker for fatal elaboration
elaborationFatalDecl :: ModuleItem
elaborationFatalDecl = MIPackageItem $ Decl $ Variable Local t elaborationFatalIdent [] elaborationFatalCancelCode
elaborationFatalDecl =
MIPackageItem $ Decl $
Variable Local t elaborationFatalIdent [] elaborationFatalCancelCode
where t = IntegerAtom TInteger Unspecified
elaborationFatalCheck :: ModuleItem
elaborationFatalCheck = Initial (Block Seq "" [] [
zeroDelay,
If NoCheck checkCancelCode finishCall Null
]) where
zeroDelay = Timing (Delay (RawNum 0)) Null
elaborationFatalCheck =
Initial $ Block Seq "" []
[ zeroDelay
, If NoCheck checkCancelCode finishCall Null
]
where
zeroDelay = Timing (Delay $ RawNum 0) Null
checkCancelCode = BinOpA Ne [] (Ident elaborationFatalIdent) elaborationFatalCancelCode
finishCall = Subroutine (Ident "$finish") (Args [(Ident elaborationFatalIdent)] [])
finishCall = call "$finish" [Ident elaborationFatalIdent]
-- If SV code uses elab fatal, add checker for fatal elaboration
traverseDescription :: Description -> Description
@ -54,61 +58,51 @@ traverseDescription (Part att ext kw lif name pts items) =
isElabTaskFatal _ = False
traverseDescription description = traverseModuleItems convertModuleItem description
-- Convert Elaboration Severity Tasks
severityToString :: Severity -> String
severityToString severity = toUpper ch : str
where '$' : ch : str = show severity
severityElabTaskToDisplay :: ModuleItem -> [Stmt]
severityElabTaskToDisplay (ElabTask severity taskArgs) =
[Subroutine (Ident "$display") (Args (
[(String ("Elaboration "++(severityToString severity)++":"++(trailingSpace)))] ++ args
) [])]
-- Convert Elaboration Severity Tasks
convertModuleItem :: ModuleItem -> ModuleItem
convertModuleItem (ElabTask severity taskArgs) =
Initial $ Block Seq "" [] [stmtDisplay, stmtFinish]
where
stmtDisplay = call "$display" $ msg : args
args = if severity /= SeverityFatal || null taskArgs
then taskArgs
else tail taskArgs
trailingSpace = if (length args) > 0 then " " else ""
severityElabTaskToDisplay _ = []
msg = String $ "Elaboration " ++ severityToString severity ++ ':' : trailingSpace
trailingSpace = if length args > 0 then " " else ""
severityElabTaskToFinish :: ModuleItem -> [Stmt]
severityElabTaskToFinish (ElabTask SeverityFatal []) =
[Asgn AsgnOpEq Nothing (LHSIdent elaborationFatalIdent) (RawNum 0)]
severityElabTaskToFinish (ElabTask SeverityFatal (finishArgs : _)) =
[Asgn AsgnOpEq Nothing (LHSIdent elaborationFatalIdent) finishArgs]
severityElabTaskToFinish _ = []
stmtFinish = if severity /= SeverityFatal
then Null
else Asgn AsgnOpEq Nothing (LHSIdent elaborationFatalIdent) finishArg
finishArg = if null taskArgs then RawNum 0 else head taskArgs
convertModuleItem :: ModuleItem -> ModuleItem
convertModuleItem task@(ElabTask _ _) =
Initial (Block Seq "" [] ((severityElabTaskToDisplay task) ++ (severityElabTaskToFinish task)))
convertModuleItem other =
traverseStmts (traverseNestedStmts convertStmt) other
-- Convert Standard Severity Tasks
timeExpr :: Expr
timeExpr = Ident "$time"
severityTaskToDisplay :: Stmt -> [Stmt]
severityTaskToDisplay (SeverityStmt severity taskArgs) =
[Subroutine (Ident "$display") (Args (
[(String ("[%0t] "++(severityToString severity)++":"++(trailingSpace))), timeExpr] ++ args
) [])]
-- Convert Standard Severity Tasks
convertStmt :: Stmt -> Stmt
convertStmt (SeverityStmt severity taskArgs) =
Block Seq "" [] [stmtDisplay, stmtFinish]
where
stmtDisplay = call "$display" $ [msg, timeExpr] ++ args
msg = String $ "[%0t] " ++ severityToString severity ++ ':' : trailingSpace
trailingSpace = if length args > 0 then " " else ""
args = if severity /= SeverityFatal || null taskArgs
then taskArgs
else tail taskArgs
trailingSpace = if (length args) > 0 then " " else ""
severityTaskToDisplay _ = []
severityTaskToFinish :: Stmt -> [Stmt]
severityTaskToFinish (SeverityStmt SeverityFatal []) =
[Subroutine (Ident "$finish") (Args [] [])]
severityTaskToFinish (SeverityStmt SeverityFatal (finishArgs : _)) =
[Subroutine (Ident "$finish") (Args [finishArgs] [])]
severityTaskToFinish _ = []
stmtFinish = if severity /= SeverityFatal
then Null
else call "$finish" argsFinish
argsFinish = if null taskArgs then [] else [head taskArgs]
convertStmt :: Stmt -> Stmt
convertStmt task@SeverityStmt{} =
Block Seq "" [] $ severityTaskToDisplay task ++ severityTaskToFinish task
convertStmt other = other
call :: Identifier -> [Expr] -> Stmt
call func args = Subroutine (Ident func) (Args args [])