mirror of https://github.com/zachjs/sv2v.git
more aggressive binop simplification
This commit is contained in:
parent
465060ce4f
commit
8e1f2bbafb
|
|
@ -113,9 +113,14 @@ convertExpr info (Mux cc aa bb) =
|
||||||
bb' = convertExpr info bb
|
bb' = convertExpr info bb
|
||||||
cc' = convertExpr info cc
|
cc' = convertExpr info cc
|
||||||
convertExpr info (BinOp op e1 e2) =
|
convertExpr info (BinOp op e1 e2) =
|
||||||
simplifyStep $ BinOp op
|
case simplifyStep $ BinOp op e1'Sub e2'Sub of
|
||||||
(convertExpr info e1)
|
Number n -> Number n
|
||||||
(convertExpr info e2)
|
_ -> simplifyStep $ BinOp op e1' e2'
|
||||||
|
where
|
||||||
|
e1' = convertExpr info e1
|
||||||
|
e2' = convertExpr info e2
|
||||||
|
e1'Sub = substituteIdent info e1'
|
||||||
|
e2'Sub = substituteIdent info e2'
|
||||||
convertExpr info (UniOp op expr) =
|
convertExpr info (UniOp op expr) =
|
||||||
simplifyStep $ UniOp op $ convertExpr info expr
|
simplifyStep $ UniOp op $ convertExpr info expr
|
||||||
convertExpr info (Repeat expr exprs) =
|
convertExpr info (Repeat expr exprs) =
|
||||||
|
|
@ -138,3 +143,10 @@ substitute scopes expr =
|
||||||
Just (_, _, e) -> e
|
Just (_, _, e) -> e
|
||||||
substitute' other =
|
substitute' other =
|
||||||
traverseSinglyNestedExprs substitute' other
|
traverseSinglyNestedExprs substitute' other
|
||||||
|
|
||||||
|
substituteIdent :: Scopes Expr -> Expr -> Expr
|
||||||
|
substituteIdent scopes (Ident x) =
|
||||||
|
case lookupElem scopes x of
|
||||||
|
Just (_, _, n @ Number{}) -> n
|
||||||
|
_ -> Ident x
|
||||||
|
substituteIdent _ other = other
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue