aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Circuit.hs
blob: af534a2729c0ceeacade359d5c32f7ddb55e72c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-|
Module      : VeriFuzz.Circuit
Description : Definition of the circuit graph.
Copyright   : (c) 2018-2019, Yann Herklotz
License     : BSD-3
Maintainer  : ymherklotz [at] gmail [dot] com
Stability   : experimental
Portability : POSIX

Definition of the circuit graph.
-}

module VeriFuzz.Circuit
    ( -- * Circuit
      Gate(..)
    , Circuit(..)
    , CNode(..)
    , CEdge(..)
    )
where

import           Data.Graph.Inductive (Gr, LEdge, LNode)
import           System.Random

-- | The types for all the gates.
data Gate = And
          | Or
          | Xor
          deriving (Show, Eq, Enum, Bounded, Ord)

-- | Newtype for the Circuit which implements a Graph from fgl.
newtype Circuit = Circuit { getCircuit :: Gr Gate () }

newtype CNode = CNode { getCNode :: LNode Gate }

newtype CEdge = CEdge { getCEdge :: LEdge () }

instance Random Gate where
  randomR (a, b) g =
    case randomR (fromEnum a, fromEnum b) g of
      (x, g') -> (toEnum x, g')

  random = randomR (minBound, maxBound)