diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs index 0d49a3c..529c5b0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,7 +1,12 @@ module Main where import Data.Bits -import Test.QuickCheck hiding ((.&.), (.|.)) +import Test.QuickCheck hiding ((.&.)) +import Data.GraphViz +import Data.Graph.Inductive.Example (clr479, dag4) +import Data.Text.Lazy +import Data.GraphViz.Printing +import Data.Graph.Inductive.Graph type Input = Bool @@ -34,5 +39,14 @@ eval (Node Xor c1 c2) = eval c1 `xor` eval c2 eval (Node Nand c1 c2) = complement $ eval c1 .&. eval c2 eval (Node Nor c1 c2) = complement $ eval c1 .|. eval c2 +visualize :: (Graph g, Show a) => Circuit a -> g String () +visualize circ = + uncurry mkGraph $ graph Nothing 0 ([], []) circ + where + graph (Just (par, _)) nl (n, e) (In val) = (n ++ [(nl, "In: " ++ show val)], e ++ [(par, nl, ())]) + graph Nothing nl (n, e) (In val) = (n ++ [(nl, "In: " ++ show val)], e) + graph _ _ _ _ = ([], []) + main :: IO () -main = sample (arbitrary :: Gen (Circuit Input)) +--main = sample (arbitrary :: Gen (Circuit Input)) +main = putStrLn . unpack . renderDot . toDot . graphToDot nonClusteredParams $ visualize (In True) |