2019-03-05 01:58:54 +01:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
-
|
2019-03-27 06:53:26 +01:00
|
|
|
- Conversion for binary assignment operators, which appear in standard and
|
|
|
|
|
- generate for loops and as a special case of blocking assignment statements.
|
|
|
|
|
- We simply elaborate them in the obvious manner.
|
2019-03-05 01:58:54 +01:00
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Convert.AsgnOp (convert) where
|
|
|
|
|
|
|
|
|
|
import Convert.Traverse
|
|
|
|
|
import Language.SystemVerilog.AST
|
|
|
|
|
|
|
|
|
|
convert :: AST -> AST
|
|
|
|
|
convert =
|
2019-03-07 21:56:03 +01:00
|
|
|
traverseDescriptions $ traverseModuleItems $
|
|
|
|
|
( traverseStmts convertStmt
|
|
|
|
|
. traverseGenItems convertGenItem
|
|
|
|
|
)
|
2019-03-05 01:58:54 +01:00
|
|
|
|
|
|
|
|
convertGenItem :: GenItem -> GenItem
|
|
|
|
|
convertGenItem (GenFor a b (ident, AsgnOp op, expr) c d) =
|
|
|
|
|
GenFor a b (ident, AsgnOpEq, BinOp op (Ident ident) expr) c d
|
|
|
|
|
convertGenItem other = other
|
2019-03-07 21:56:03 +01:00
|
|
|
|
|
|
|
|
convertStmt :: Stmt -> Stmt
|
2019-03-27 06:53:26 +01:00
|
|
|
convertStmt (For inits cc asgns stmt) =
|
|
|
|
|
For inits cc asgns' stmt
|
|
|
|
|
where
|
|
|
|
|
asgns' = map convertAsgn asgns
|
|
|
|
|
convertAsgn :: (LHS, AsgnOp, Expr) -> (LHS, AsgnOp, Expr)
|
|
|
|
|
convertAsgn (lhs, AsgnOp op, expr) =
|
|
|
|
|
(lhs, AsgnOpEq, BinOp op (lhsToExpr lhs) expr)
|
|
|
|
|
convertAsgn other = other
|
2019-03-07 21:56:03 +01:00
|
|
|
convertStmt (AsgnBlk (AsgnOp op) lhs expr) =
|
|
|
|
|
AsgnBlk AsgnOpEq lhs (BinOp op (lhsToExpr lhs) expr)
|
|
|
|
|
convertStmt other = other
|
|
|
|
|
|
|
|
|
|
lhsToExpr :: LHS -> Expr
|
2019-04-05 19:53:52 +02:00
|
|
|
lhsToExpr (LHSIdent x ) = Ident x
|
|
|
|
|
lhsToExpr (LHSBit l e ) = Bit (lhsToExpr l) e
|
|
|
|
|
lhsToExpr (LHSRange l m r) = Range (lhsToExpr l) m r
|
|
|
|
|
lhsToExpr (LHSDot l x ) = Dot (lhsToExpr l) x
|
|
|
|
|
lhsToExpr (LHSConcat ls ) = Concat $ map lhsToExpr ls
|