diff options
| author | Albert Chen | 2020-07-16 16:59:28 -0700 |
|---|---|---|
| committer | GitHub | 2020-07-16 16:59:28 -0700 |
| commit | c4cc6bc5b614bd7f5383f8a85c7fc81facdc4b20 (patch) | |
| tree | f178900374cf7e1bc44404569210070b4a0dba0a /fuzzer/src/main/scala/firrtl/ExprState.scala | |
| parent | da221ea21f6e5e4022156df9337e3054c333e62f (diff) | |
Add Expression Fuzzer (#1741)
Includes:
* Random generator of FIRRTL Expressions (UInt and SInt types)
* JQF SBT plugin and CLI
* Documentation in README.md
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'fuzzer/src/main/scala/firrtl/ExprState.scala')
| -rw-r--r-- | fuzzer/src/main/scala/firrtl/ExprState.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/fuzzer/src/main/scala/firrtl/ExprState.scala b/fuzzer/src/main/scala/firrtl/ExprState.scala new file mode 100644 index 00000000..f1a2f0d1 --- /dev/null +++ b/fuzzer/src/main/scala/firrtl/ExprState.scala @@ -0,0 +1,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]] +} |
