improved portability of logic conversion

- indirect converted reg continuous assignments through wires
- fix typeof for implicitly typed ports
- fix typeof for sized implicitly typed params
This commit is contained in:
Zachary Snow
2021-01-25 19:23:54 -05:00
parent 5f0dc6be0c
commit b22cd210a4
9 changed files with 51 additions and 19 deletions
+10 -14
View File
@@ -106,21 +106,17 @@ traverseModuleItem ports scopes =
fixModuleItem :: ModuleItem -> ModuleItem
-- rewrite bad continuous assignments to use procedural assignments
fixModuleItem (Assign AssignOptionNone lhs expr) =
if not (isReg lhs) then
Assign AssignOptionNone lhs expr
else if isConstant expr then
Initial $ Asgn AsgnOpEq Nothing lhs expr
else
AlwaysC AlwaysComb $ Asgn AsgnOpEq Nothing lhs expr
if not (isReg lhs)
then Assign AssignOptionNone lhs expr
else
Generate $ map GenModuleItem
[ MIPackageItem (Decl (Variable Local t x [] Nil))
, Assign AssignOptionNone (LHSIdent x) expr
, AlwaysC AlwaysComb $ Asgn AsgnOpEq Nothing lhs (Ident x)
]
where
-- only handles expressions which are trivially constant for now
isConstant :: Expr -> Bool
isConstant Number{} = True
isConstant (Repeat _ es) = all isConstant es
isConstant (Concat es) = all isConstant es
isConstant (BinOp _ e1 e2) = isConstant e1 && isConstant e2
isConstant (UniOp _ e) = isConstant e
isConstant _ = False
t = TypeOf expr
x = "sv2v_tmp_" ++ shortHash (lhs, expr)
-- rewrite port bindings to use temporary nets where necessary
fixModuleItem (Instance moduleName params instanceName rs bindings) =
if null newItems
+6 -3
View File
@@ -37,11 +37,11 @@ traverseDeclM decl = do
item <- traverseModuleItemM (MIPackageItem $ Decl decl)
let MIPackageItem (Decl decl') = item
case decl' of
Variable Local (Implicit sg rs) ident [] Nil -> do
Variable _ (Implicit sg rs) ident a _ ->
-- implicit types, which are commonly found in function return
-- types, are recast as logics to avoid outputting bare ranges
insertElem ident $ IntegerVector TLogic sg rs
return decl'
insertElem ident t' >> return decl'
where t' = injectRanges (IntegerVector TLogic sg rs) a
Variable d t ident a e -> do
let t' = injectRanges t a
insertElem ident t'
@@ -52,6 +52,9 @@ traverseDeclM decl = do
insertElem ident UnknownType >> return decl'
Param _ UnknownType ident e ->
typeof e >>= insertElem ident >> return decl'
Param _ (Implicit sg rs) ident _ ->
insertElem ident t' >> return decl'
where t' = IntegerVector TLogic sg rs
Param _ t ident _ ->
insertElem ident t >> return decl'
ParamType{} -> return decl'