2019-02-20 21:22:26 +01:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
-
|
|
|
|
|
- Conversion for `.*` in module instantiation
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Convert.StarPort (convert) where
|
|
|
|
|
|
2019-02-25 08:36:37 +01:00
|
|
|
import Data.Maybe (mapMaybe)
|
2019-02-20 21:22:26 +01:00
|
|
|
import qualified Data.Map.Strict as Map
|
|
|
|
|
|
2019-02-25 08:36:37 +01:00
|
|
|
import Convert.Traverse
|
2019-02-20 21:22:26 +01:00
|
|
|
import Language.SystemVerilog.AST
|
|
|
|
|
|
|
|
|
|
convert :: AST -> AST
|
2019-02-25 08:36:37 +01:00
|
|
|
convert descriptions =
|
|
|
|
|
traverseDescriptions (traverseModuleItems mapInstance) descriptions
|
2019-02-20 21:22:26 +01:00
|
|
|
where
|
2019-02-25 08:36:37 +01:00
|
|
|
modulePorts = Map.fromList $ mapMaybe getPorts descriptions
|
2019-02-20 21:22:26 +01:00
|
|
|
getPorts :: Description -> Maybe (Identifier, [Identifier])
|
|
|
|
|
getPorts (Module name ports _) = Just (name, ports)
|
|
|
|
|
getPorts _ = Nothing
|
|
|
|
|
|
2019-02-25 08:36:37 +01:00
|
|
|
mapInstance :: ModuleItem -> ModuleItem
|
|
|
|
|
mapInstance (Instance m p x Nothing) =
|
|
|
|
|
Instance m p x (Just portBindings)
|
|
|
|
|
where
|
|
|
|
|
ports = case Map.lookup m modulePorts of
|
|
|
|
|
Nothing -> error $ "could not convert `.*` in instantiation of " ++ m
|
|
|
|
|
Just l -> l
|
|
|
|
|
portBindings = map (\port -> (port, Just $ Ident port)) ports
|
|
|
|
|
mapInstance other = other
|