diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-29 22:29:45 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-29 22:29:45 +0100 |
commit | 2c84e82a0263c9bf87cc660a9aabeb5f69828253 (patch) | |
tree | 21a92bf7e9852e9f1639b16f913c27d2745307e2 | |
parent | 08f10a6f6cbc4fc8235beacedd587c56a9534f34 (diff) | |
download | verismith-2c84e82a0263c9bf87cc660a9aabeb5f69828253.tar.gz verismith-2c84e82a0263c9bf87cc660a9aabeb5f69828253.zip |
Add new generation method
-rw-r--r-- | app/Main.hs | 17 | ||||
-rw-r--r-- | src/Test/VeriFuzz/Graph/Random.hs | 28 |
2 files changed, 25 insertions, 20 deletions
diff --git a/app/Main.hs b/app/Main.hs index de3f870..5cdc245 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,12 +1,15 @@ module Main where import qualified Data.Graph.Inductive as G +import qualified Data.Graph.Inductive.Arbitrary as G +import qualified Data.Graph.Inductive.PatriciaTree as G import qualified Data.GraphViz as Gviz import qualified Data.GraphViz.Attributes.Complete as Gviz import qualified Data.Text.IO as T import qualified Data.Text.Lazy as T import qualified Test.QuickCheck as QC import Test.VeriFuzz +import qualified Test.VeriFuzz.Graph.RandomAlt as V instance Gviz.Labellable Gate where toLabelValue gate = Gviz.StrLabel . T.pack $ show gate @@ -14,10 +17,12 @@ instance Gviz.Labellable Gate where main :: IO () --main = sample (arbitrary :: Gen (Circuit Input)) main = do - --gr <- genRandomDAG 100 :: IO (G.Gr Gate ()) - -- _ <- runGraphviz (graphToDot quickParams $ emap (const "") gr) Png "output.png", - -- T.putStrLn $ generate gr - g <- QC.generate (QC.resize 5 (QC.arbitrary :: QC.Gen VerilogSrc)) - --render . genVerilogSrc . addTestBench . nestUpTo 20 . generateAST $ Circuit gr + gr <- QC.generate $ QC.resize 100 (V.randomDAG :: QC.Gen (G.Gr Gate ())) + let dot = Gviz.graphToDot Gviz.nonClusteredParams . G.emap (const "") $ gr + _ <- Gviz.runGraphviz dot Gviz.Png "output.png" + return () + -- T.putStrLn $ generate gr + -- g <- QC.generate (QC.resize 5 (QC.arbitrary :: QC.Gen VerilogSrc)) + -- render . genVerilogSrc . addTestBench . nestUpTo 20 . generateAST $ Circuit gr - render . genVerilogSrc . addTestBench $ g + -- render . genVerilogSrc . addTestBench $ g diff --git a/src/Test/VeriFuzz/Graph/Random.hs b/src/Test/VeriFuzz/Graph/Random.hs index 8d3eb50..7f9e3e6 100644 --- a/src/Test/VeriFuzz/Graph/Random.hs +++ b/src/Test/VeriFuzz/Graph/Random.hs @@ -12,9 +12,10 @@ Define the random generation for the directed acyclic graph. module Test.VeriFuzz.Graph.Random where -import Data.Graph.Inductive (Graph, LEdge, mkGraph) -import Test.QuickCheck (Arbitrary, Gen) -import qualified Test.QuickCheck as QC +import Data.Graph.Inductive (Graph, LEdge, mkGraph) +import Data.Graph.Inductive.PatriciaTree (Gr) +import Test.QuickCheck (Arbitrary, Gen) +import qualified Test.QuickCheck as QC -- | Gen instance to create an arbitrary edge, where the edges are limited by -- `n` that is passed to it. @@ -28,19 +29,18 @@ arbitraryEdge n = do with = QC.suchThat $ QC.resize n QC.arbitrary -- | Gen instance for a random acyclic DAG. -randomDAG :: (Arbitrary l, Arbitrary e, Graph gr) - => Int -- ^ The number of nodes - -> Gen (gr l e) -- ^ The generated graph. It uses Arbitrary to +randomDAG :: (Arbitrary l, Arbitrary e) + => Gen (Gr l e) -- ^ The generated graph. It uses Arbitrary to -- generate random instances of each node -randomDAG n = do +randomDAG = do list <- QC.infiniteListOf QC.arbitrary - l <- QC.infiniteListOf $ arbitraryEdge n - return . mkGraph (nodes list) $ take (10*n) l + l <- QC.infiniteListOf $ aE + QC.sized (\n -> return . mkGraph (nodes list n) $ take (10*n) l) where - nodes l = zip [0..n] $ take n l + nodes l n = zip [0..n] $ take n l + aE = QC.sized arbitraryEdge -- | Generate a random acyclic DAG with an IO instance. -genRandomDAG :: (Arbitrary l, Arbitrary e, Graph gr) - => Int - -> IO (gr l e) -genRandomDAG = QC.generate . randomDAG +genRandomDAG :: (Arbitrary l, Arbitrary e) + => IO (Gr l e) +genRandomDAG = QC.generate randomDAG |