Commit 5ea2ec9d by Zachary Snow

added conversion for name task and function arguments

parent f1ac4fc0
......@@ -14,6 +14,7 @@ import qualified Convert.AsgnOp
import qualified Convert.Enum
import qualified Convert.FuncRet
import qualified Convert.Interface
import qualified Convert.KWArgs
import qualified Convert.Logic
import qualified Convert.PackedArray
import qualified Convert.Return
......@@ -32,6 +33,7 @@ phases excludes =
, selectExclude (Job.Logic , Convert.Logic.convert)
, Convert.FuncRet.convert
, Convert.Enum.convert
, Convert.KWArgs.convert
, Convert.PackedArray.convert
, Convert.StarPort.convert
, Convert.StmtBlock.convert
......
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for named function and task arguments
-}
module Convert.KWArgs (convert) where
import Data.List (elemIndex, sortOn)
import Data.Maybe (mapMaybe)
import Control.Monad.Writer
import qualified Data.Map.Strict as Map
import Convert.Traverse
import Language.SystemVerilog.AST
type TFs = Map.Map Identifier [Identifier]
convert :: AST -> AST
convert = traverseDescriptions convertDescription
convertDescription :: Description -> Description
convertDescription description =
traverseModuleItems
(traverseExprs $ traverseNestedExprs $ convertExpr tfs)
description
where
tfs = execWriter $ collectModuleItemsM collectTF description
collectTF :: ModuleItem -> Writer TFs ()
collectTF (MIPackageItem (Function _ _ f decls _)) = collectTFDecls f decls
collectTF (MIPackageItem (Task _ f decls _)) = collectTFDecls f decls
collectTF _ = return ()
collectTFDecls :: Identifier -> [Decl] -> Writer TFs ()
collectTFDecls name decls =
tell $ Map.singleton name $ mapMaybe getInput decls
where
getInput :: Decl -> Maybe Identifier
getInput (Variable Input _ ident _ _) = Just ident
getInput _ = Nothing
convertExpr :: TFs -> Expr -> Expr
convertExpr _ (orig @ (Call _ (Args _ []))) = orig
convertExpr tfs (Call func (Args pnArgs kwArgs)) =
case tfs Map.!? func of
Nothing -> Call func (Args pnArgs kwArgs)
Just ordered -> Call func (Args args [])
where
args = pnArgs ++ (map snd $ sortOn position kwArgs)
position (x, _) = elemIndex x ordered
convertExpr _ other = other
......@@ -54,6 +54,7 @@ executable sv2v
Convert.Enum
Convert.FuncRet
Convert.Interface
Convert.KWArgs
Convert.Logic
Convert.PackedArray
Convert.Return
......
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