aboutsummaryrefslogtreecommitdiff
path: root/fuzzer/src/main/scala/firrtl/ExprState.scala
blob: b2fd40abe38a60363694289d84855210d4b4c167 (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
// SPDX-License-Identifier: Apache-2.0

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]]
}