From 9f0857d68e668a9e6f93a6511fef58164c0aab81 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Thu, 7 Mar 2019 20:03:35 -0500 Subject: [PATCH] some fixes for 'VTR' targetted conversions --- src/Convert/FuncRet.hs | 4 +++- src/Convert/Logic.hs | 16 +++++++++++++--- src/Convert/Struct.hs | 10 +++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Convert/FuncRet.hs b/src/Convert/FuncRet.hs index 7180ca5..d9b34f4 100644 --- a/src/Convert/FuncRet.hs +++ b/src/Convert/FuncRet.hs @@ -1,7 +1,7 @@ {- sv2v - Author: Zachary Snow - - - Conversion which makes function `logic` return types implicit + - Conversion which makes function `logic` and `reg` return types implicit -} module Convert.FuncRet (convert) where @@ -13,6 +13,8 @@ convert :: AST -> AST convert = traverseDescriptions $ traverseModuleItems convertFunction 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)) = MIPackageItem $ Function ml (Implicit r) f decls stmts convertFunction other = other diff --git a/src/Convert/Logic.hs b/src/Convert/Logic.hs index 035332d..577cbce 100644 --- a/src/Convert/Logic.hs +++ b/src/Convert/Logic.hs @@ -25,8 +25,8 @@ convert :: AST -> AST convert = traverseDescriptions convertDescription convertDescription :: Description -> Description -convertDescription orig = - traverseModuleItems convertModuleItem orig +convertDescription (orig @ (Part Module _ _ _)) = + traverseModuleItems (traverseDecls convertDecl . convertModuleItem) orig where idents = execWriter (collectModuleItemsM regIdents orig) convertModuleItem :: ModuleItem -> ModuleItem @@ -34,11 +34,21 @@ convertDescription orig = MIDecl $ Variable dir (t mr) ident a me where t = if Set.member ident idents then Reg else Wire 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 (AlwaysC _ stmt) = collectStmtLHSsM idents stmt +regIdents (AlwaysC _ stmt) = + collectStmtLHSsM idents $ traverseNestedStmts removeTimings stmt where idents :: LHS -> Writer RegIdents () idents (LHSIdent vx ) = tell $ Set.singleton vx idents _ = return () -- the collector recurses for us + removeTimings :: Stmt -> Stmt + removeTimings (Timing _ s) = s + removeTimings other = other regIdents _ = return () diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index ade3882..f760eb2 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -98,6 +98,7 @@ convertType structs t1 = -- write down the type a declarations collectDecl :: Decl -> Writer Types () +collectDecl (Variable _ (Implicit []) _ _ _) = return () collectDecl (Variable _ t x a _) = -- 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` @@ -186,9 +187,12 @@ convertAsgn structs types (lhs, expr) = Nothing -> (Implicit [], Ident x) Just t -> (t, Ident x) convertSubExpr (Access e x) = - if Map.notMember structTf structs - then (fieldType, Access e' x) - else (fieldType, Range e' r) + case subExprType of + Struct _ _ _ -> + if Map.notMember structTf structs + then (fieldType, Access e' x) + else (fieldType, Range e' r) + _ -> (Implicit [], Access e' x) where (subExprType, e') = convertSubExpr e Struct p fields [] = subExprType