diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-22 11:35:45 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-22 11:35:45 +0000 |
commit | 7f73caee6374f0da1bc335a6a618ddd7f2249a14 (patch) | |
tree | 612a6c9835c8640307c56d0e788bb89f786595d1 /src/Test/VeriFuzz/Internal | |
parent | b5202e97fe669dfa10ec15cc39f9c7f250bcefc5 (diff) | |
download | verismith-7f73caee6374f0da1bc335a6a618ddd7f2249a14.tar.gz verismith-7f73caee6374f0da1bc335a6a618ddd7f2249a14.zip |
Add shared code to code generation
Diffstat (limited to 'src/Test/VeriFuzz/Internal')
-rw-r--r-- | src/Test/VeriFuzz/Internal/Gen.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Test/VeriFuzz/Internal/Gen.hs b/src/Test/VeriFuzz/Internal/Gen.hs new file mode 100644 index 0000000..a8bd57a --- /dev/null +++ b/src/Test/VeriFuzz/Internal/Gen.hs @@ -0,0 +1,34 @@ +{-| +Module : Test.VeriFuzz.Internal.Gen +Description : Internal helpers for generation. +Copyright : (c) Yann Herklotz Grave 2018 +License : GPL-3 +Maintainer : ymherklotz@gmail.com +Stability : experimental +Portability : POSIX + +Internal helpers for generation. +-} + +module Test.VeriFuzz.Internal.Gen where + +import Data.Graph.Inductive (Graph, Node) +import qualified Data.Graph.Inductive as G +import qualified Data.Text as T +import Test.VeriFuzz.VerilogAST + +fromNode :: Node -> T.Text +fromNode node = Identifier . T.pack $ "w" <> show node + +filterGr :: (Graph gr) => gr n e -> (Node -> Bool) -> [Node] +filterGr graph f = + filter f $ G.nodes graph + +only :: (Graph gr) => (gr n e -> Node -> Int) -> (gr n e -> Node -> Int) -> gr n e -> Node -> [Node] +only fun1 fun2 n = fun1 graph n == 0 && fun2 graph n /= 0 + +inputs :: (Graph gr) => gr n e -> [Node] +inputs graph = filterGr graph $ only G.indeg G.outdeg + +outputs :: (Graph gr) => gr n e -> [Node] +outputs graph = filterGr graph $ only G.outdeg G.indeg |