aboutsummaryrefslogtreecommitdiff
path: root/fuzzer/src/main/scala/firrtl/ExprState.scala
blob: f1a2f0d13bebddeb3c9a3aaee5fb1d6bcb94513b (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
package firrtl.fuzzer

import firrtl.ir.{Expression, Reference, Type}

import scala.language.higherKinds

/** A typeclass for types that represent the state of a random expression generator
  */
trait ExprState[State] {

  /** Creates a [[StateGen]] that adds a reference to the input state and returns that reference
    */
  def withRef[Gen[_]: GenMonad](ref: Reference): StateGen[State, Gen, Reference]

  /** Creates a [[StateGen]] that returns an [[firrtl.ir.Expression Expression]] with the specified type
    */
  def exprGen[Gen[_]: GenMonad](tpe: Type): StateGen[State, Gen, Expression]

  /** Gets the set of unbound references
    */
  def unboundRefs(s: State): Set[Reference]

  /** Gets the maximum allowed width of any Expression
    */
  def maxWidth(s: State): Int
}

object ExprState {
  def apply[S: ExprState] = implicitly[ExprState[S]]
}