aboutsummaryrefslogtreecommitdiffstats
path: root/src/Verismith/Reduce.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Verismith/Reduce.hs')
-rw-r--r--src/Verismith/Reduce.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/Verismith/Reduce.hs b/src/Verismith/Reduce.hs
index a7ec3f8..cff61ed 100644
--- a/src/Verismith/Reduce.hs
+++ b/src/Verismith/Reduce.hs
@@ -31,6 +31,8 @@ module Verismith.Reduce
, cleanSourceInfo
, cleanSourceInfoAll
, removeDecl
+ , removeConstInConcat
+ , takeReplace
, filterExpr
)
where
@@ -156,6 +158,21 @@ filterAssigns _ _ = True
clean :: (Mutate a) => [Identifier] -> a -> a
clean ids = mutExpr (transform $ filterExpr ids)
+takeReplace :: (Monoid a) => Replacement a -> a
+takeReplace (Single a) = a
+takeReplace (Dual a _) = a
+takeReplace None = mempty
+
+removeConstInConcat :: Replace SourceInfo
+removeConstInConcat = Single . mutExpr replace
+ where
+ replace :: Expr -> Expr
+ replace (Concat expr) = maybe (Number 0) Concat . NonEmpty.nonEmpty
+ $ NonEmpty.filter notConstant expr
+ replace e = e
+ notConstant (Number _) = False
+ notConstant _ = True
+
cleanUndefined :: [Identifier] -> [ModItem] -> [ModItem]
cleanUndefined ids mis = clean usedWires mis
where
@@ -547,9 +564,10 @@ reduce
reduce eval src =
fmap removeDecl
$ red "Modules" moduleBot halveModules src
- >>= redAll "Module Items" modItemBot halveModItems
+ >>= redAll "Module items" modItemBot halveModItems
>>= redAll "Statements" (const defaultBot) halveStatements
-- >>= redAll "Expressions" (const defaultBot) halveExpr
+ >>= red "Remove constants in concat" defaultBot removeConstInConcat
where
red s bot a = reduce_ s a bot eval
red' s bot a t = reduce_ s (a t) (bot t) eval