Commit 9f0857d6 by Zachary Snow

some fixes for 'VTR' targetted conversions

parent b2b1c9e5
{- sv2v {- sv2v
- Author: Zachary Snow <zach@zachjs.com> - Author: Zachary Snow <zach@zachjs.com>
- -
- Conversion which makes function `logic` return types implicit - Conversion which makes function `logic` and `reg` return types implicit
-} -}
module Convert.FuncRet (convert) where module Convert.FuncRet (convert) where
...@@ -13,6 +13,8 @@ convert :: AST -> AST ...@@ -13,6 +13,8 @@ convert :: AST -> AST
convert = traverseDescriptions $ traverseModuleItems convertFunction convert = traverseDescriptions $ traverseModuleItems convertFunction
convertFunction :: ModuleItem -> ModuleItem convertFunction :: ModuleItem -> ModuleItem
convertFunction (MIPackageItem (Function ml (Reg r) f decls stmts)) =
MIPackageItem $ Function ml (Implicit r) f decls stmts
convertFunction (MIPackageItem (Function ml (Logic r) f decls stmts)) = convertFunction (MIPackageItem (Function ml (Logic r) f decls stmts)) =
MIPackageItem $ Function ml (Implicit r) f decls stmts MIPackageItem $ Function ml (Implicit r) f decls stmts
convertFunction other = other convertFunction other = other
...@@ -25,8 +25,8 @@ convert :: AST -> AST ...@@ -25,8 +25,8 @@ convert :: AST -> AST
convert = traverseDescriptions convertDescription convert = traverseDescriptions convertDescription
convertDescription :: Description -> Description convertDescription :: Description -> Description
convertDescription orig = convertDescription (orig @ (Part Module _ _ _)) =
traverseModuleItems convertModuleItem orig traverseModuleItems (traverseDecls convertDecl . convertModuleItem) orig
where where
idents = execWriter (collectModuleItemsM regIdents orig) idents = execWriter (collectModuleItemsM regIdents orig)
convertModuleItem :: ModuleItem -> ModuleItem convertModuleItem :: ModuleItem -> ModuleItem
...@@ -34,11 +34,21 @@ convertDescription orig = ...@@ -34,11 +34,21 @@ convertDescription orig =
MIDecl $ Variable dir (t mr) ident a me MIDecl $ Variable dir (t mr) ident a me
where t = if Set.member ident idents then Reg else Wire where t = if Set.member ident idents then Reg else Wire
convertModuleItem other = other convertModuleItem other = other
-- all other logics (i.e. inside of functions) become regs
convertDecl :: Decl -> Decl
convertDecl (Variable d (Logic rs) x a me) =
Variable d (Reg rs) x a me
convertDecl other = other
convertDescription other = other
regIdents :: ModuleItem -> Writer RegIdents () regIdents :: ModuleItem -> Writer RegIdents ()
regIdents (AlwaysC _ stmt) = collectStmtLHSsM idents stmt regIdents (AlwaysC _ stmt) =
collectStmtLHSsM idents $ traverseNestedStmts removeTimings stmt
where where
idents :: LHS -> Writer RegIdents () idents :: LHS -> Writer RegIdents ()
idents (LHSIdent vx ) = tell $ Set.singleton vx idents (LHSIdent vx ) = tell $ Set.singleton vx
idents _ = return () -- the collector recurses for us idents _ = return () -- the collector recurses for us
removeTimings :: Stmt -> Stmt
removeTimings (Timing _ s) = s
removeTimings other = other
regIdents _ = return () regIdents _ = return ()
...@@ -98,6 +98,7 @@ convertType structs t1 = ...@@ -98,6 +98,7 @@ convertType structs t1 =
-- write down the type a declarations -- write down the type a declarations
collectDecl :: Decl -> Writer Types () collectDecl :: Decl -> Writer Types ()
collectDecl (Variable _ (Implicit []) _ _ _) = return ()
collectDecl (Variable _ t x a _) = collectDecl (Variable _ t x a _) =
-- We add the unpacked dimensions to the type so that our type traversal can -- We add the unpacked dimensions to the type so that our type traversal can
-- correctly match-off the dimensions whenever we see a `Bit` or `Range` -- correctly match-off the dimensions whenever we see a `Bit` or `Range`
...@@ -186,9 +187,12 @@ convertAsgn structs types (lhs, expr) = ...@@ -186,9 +187,12 @@ convertAsgn structs types (lhs, expr) =
Nothing -> (Implicit [], Ident x) Nothing -> (Implicit [], Ident x)
Just t -> (t, Ident x) Just t -> (t, Ident x)
convertSubExpr (Access e x) = convertSubExpr (Access e x) =
case subExprType of
Struct _ _ _ ->
if Map.notMember structTf structs if Map.notMember structTf structs
then (fieldType, Access e' x) then (fieldType, Access e' x)
else (fieldType, Range e' r) else (fieldType, Range e' r)
_ -> (Implicit [], Access e' x)
where where
(subExprType, e') = convertSubExpr e (subExprType, e') = convertSubExpr e
Struct p fields [] = subExprType Struct p fields [] = subExprType
......
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