diff options
author | Yann Herklotz <git@yannherklotz.com> | 2019-11-05 10:17:31 +0000 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2019-11-05 10:17:31 +0000 |
commit | dbdea9bc47513b3643c981043c806647fdcf89b4 (patch) | |
tree | f89b4387e9d78166ccb52b3dab6d970d3ece06c2 /src/Verismith/Reduce.hs | |
parent | a083073ec8ccac04861e06223b117304bd517565 (diff) | |
download | verismith-dbdea9bc47513b3643c981043c806647fdcf89b4.tar.gz verismith-dbdea9bc47513b3643c981043c806647fdcf89b4.zip |
Add reduction pass to remove constants from concat
Diffstat (limited to 'src/Verismith/Reduce.hs')
-rw-r--r-- | src/Verismith/Reduce.hs | 20 |
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 |