Commit ff812671 by Zachary Snow

added conversion for genvar iteration AsgnOps

parent 460c0ee4
...@@ -10,6 +10,7 @@ import Language.SystemVerilog.AST ...@@ -10,6 +10,7 @@ import Language.SystemVerilog.AST
import Job (Target(..)) import Job (Target(..))
import qualified Convert.AlwaysKW import qualified Convert.AlwaysKW
import qualified Convert.AsgnOp
import qualified Convert.CaseKW import qualified Convert.CaseKW
import qualified Convert.Enum import qualified Convert.Enum
import qualified Convert.Logic import qualified Convert.Logic
...@@ -23,7 +24,8 @@ type Phase = AST -> AST ...@@ -23,7 +24,8 @@ type Phase = AST -> AST
phases :: Target -> [Phase] phases :: Target -> [Phase]
phases YOSYS = phases YOSYS =
[ Convert.Enum.convert [ Convert.AsgnOp.convert
, Convert.Enum.convert
, Convert.PackedArray.convert , Convert.PackedArray.convert
, Convert.StarPort.convert , Convert.StarPort.convert
, Convert.Typedef.convert , Convert.Typedef.convert
......
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for binary assignment operators, which only appear in generate for
- loops. We simply elaborate them in the obvious manner.
-}
module Convert.AsgnOp (convert) where
import Convert.Traverse
import Language.SystemVerilog.AST
convert :: AST -> AST
convert =
traverseDescriptions $
traverseModuleItems $
traverseGenItems convertGenItem
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
...@@ -33,6 +33,9 @@ module Convert.Traverse ...@@ -33,6 +33,9 @@ module Convert.Traverse
, traverseTypesM , traverseTypesM
, traverseTypes , traverseTypes
, collectTypesM , collectTypesM
, traverseGenItemsM
, traverseGenItems
, collectGenItemsM
) where ) where
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
...@@ -70,28 +73,15 @@ traverseModuleItemsM mapper (Part kw name ports items) = ...@@ -70,28 +73,15 @@ traverseModuleItemsM mapper (Part kw name ports items) =
mapM fullMapper items >>= return . Part kw name ports mapM fullMapper items >>= return . Part kw name ports
where where
fullMapper (Generate genItems) = fullMapper (Generate genItems) =
mapM genItemMapper genItems >>= mapper . Generate mapM fullGenItemMapper genItems >>= mapper . Generate
fullMapper other = mapper other fullMapper other = mapper other
-- maps all ModuleItems within the given GenItem fullGenItemMapper = traverseNestedGenItemsM genItemMapper
genItemMapper (GenBlock x subItems) =
mapM genItemMapper subItems >>= return . GenBlock x
genItemMapper (GenFor a b c d subItems) =
mapM genItemMapper subItems >>= return . GenFor a b c d
genItemMapper (GenIf e i1 i2) = do
i1' <- genItemMapper i1
i2' <- genItemMapper i2
return $ GenIf e i1' i2'
genItemMapper (GenNull) = return GenNull
genItemMapper (GenModuleItem moduleItem) = do genItemMapper (GenModuleItem moduleItem) = do
moduleItem' <- fullMapper moduleItem moduleItem' <- fullMapper moduleItem
return $ case moduleItem' of return $ case moduleItem' of
Generate subItems -> GenBlock Nothing subItems Generate subItems -> GenBlock Nothing subItems
_ -> GenModuleItem moduleItem' _ -> GenModuleItem moduleItem'
genItemMapper (GenCase e cases def) = do genItemMapper other = return other
caseItems <- mapM (genItemMapper . snd) cases
let cases' = zip (map fst cases) caseItems
def' <- maybeDo genItemMapper def
return $ GenCase e cases' def'
traverseModuleItemsM _ orig = return orig traverseModuleItemsM _ orig = return orig
traverseModuleItems :: Mapper ModuleItem -> Mapper Description traverseModuleItems :: Mapper ModuleItem -> Mapper Description
...@@ -354,3 +344,39 @@ traverseTypes :: Mapper Type -> Mapper ModuleItem ...@@ -354,3 +344,39 @@ traverseTypes :: Mapper Type -> Mapper ModuleItem
traverseTypes = unmonad traverseTypesM traverseTypes = unmonad traverseTypesM
collectTypesM :: Monad m => CollectorM m Type -> CollectorM m ModuleItem collectTypesM :: Monad m => CollectorM m Type -> CollectorM m ModuleItem
collectTypesM = collectify traverseTypesM collectTypesM = collectify traverseTypesM
traverseGenItemsM :: Monad m => MapperM m GenItem -> MapperM m ModuleItem
traverseGenItemsM mapper = moduleItemMapper
where
fullMapper = traverseNestedGenItemsM mapper
moduleItemMapper (Generate genItems) =
mapM fullMapper genItems >>= return . Generate
moduleItemMapper other = return other
traverseGenItems :: Mapper GenItem -> Mapper ModuleItem
traverseGenItems = unmonad traverseGenItemsM
collectGenItemsM :: Monad m => CollectorM m GenItem -> CollectorM m ModuleItem
collectGenItemsM = collectify traverseGenItemsM
-- traverses all GenItems within a given GenItem, but doesn't inspect within
-- GenModuleItems
traverseNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem
traverseNestedGenItemsM mapper = fullMapper
where
fullMapper genItem = gim genItem >>= mapper
gim (GenBlock x subItems) =
mapM fullMapper subItems >>= return . GenBlock x
gim (GenFor a b c d subItems) =
mapM fullMapper subItems >>= return . GenFor a b c d
gim (GenIf e i1 i2) = do
i1' <- fullMapper i1
i2' <- fullMapper i2
return $ GenIf e i1' i2'
gim (GenCase e cases def) = do
caseItems <- mapM (fullMapper . snd) cases
let cases' = zip (map fst cases) caseItems
def' <- maybeDo fullMapper def
return $ GenCase e cases' def'
gim (GenModuleItem moduleItem) =
return $ GenModuleItem moduleItem
gim (GenNull) = return GenNull
...@@ -41,6 +41,7 @@ executable sv2v ...@@ -41,6 +41,7 @@ executable sv2v
-- Conversion modules -- Conversion modules
Convert Convert
Convert.AlwaysKW Convert.AlwaysKW
Convert.AsgnOp
Convert.CaseKW Convert.CaseKW
Convert.Enum Convert.Enum
Convert.Logic Convert.Logic
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment