AsgnOp.hs 1.17 KB
Newer Older
1 2 3
{- sv2v
 - Author: Zachary Snow <zach@zachjs.com>
 -
4 5 6
 - Conversion for binary assignment operators, which can appear in for loops and
 - as a special case of blocking assignment statements. We simply elaborate them
 - in the obvious manner: a += b -> a = a + b.
7 8 9 10 11 12 13
 -}

module Convert.AsgnOp (convert) where

import Convert.Traverse
import Language.SystemVerilog.AST

14
convert :: [AST] -> [AST]
15
convert =
16
    map $ traverseDescriptions $ traverseModuleItems $
17 18 19
    ( traverseStmts    convertStmt
    . traverseGenItems convertGenItem
    )
20 21

convertGenItem :: GenItem -> GenItem
22 23
convertGenItem (GenFor a b (ident, AsgnOp op, expr) c) =
    GenFor a b (ident, AsgnOpEq, BinOp op (Ident ident) expr) c
24
convertGenItem other = other
25 26

convertStmt :: Stmt -> Stmt
27 28 29 30 31 32 33 34
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
35 36
convertStmt (Asgn (AsgnOp op) mt lhs expr) =
    Asgn AsgnOpEq mt lhs (BinOp op (lhsToExpr lhs) expr)
37
convertStmt other = other