Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global per-clock step limit #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/scala/chisel3/tester/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package chisel3

import scala.collection.mutable

import chisel3.core.ActualDirection // TODO needs to be a public API
import chisel3.experimental.{DataMirror, FixedPoint}
import chisel3.internal.firrtl.FPLit
Expand Down Expand Up @@ -91,8 +93,21 @@ package object tester {
// def staleExpect(value: T): Unit = expectWithStale(value, true) // TODO: can this be replaced w/ phases?
}

val clockLimits = new mutable.WeakHashMap[Clock, (Option[Int], Int)]() // Clock -> (MaxCycles, Steps)
implicit class testableClock(x: Clock) {
private def clockLimit = clockLimits.getOrElse(x, (None, 0))

def setMaxSteps(maxSteps: Int) = clockLimits.update(x, clockLimit.copy(_1=Some(maxSteps)))

def step(cycles: Int = 1): Unit = {
clockLimits.update(x, clockLimit match { case (maxSteps, numSteps) =>
val nextNumSteps = numSteps + cycles
maxSteps.foreach { mc =>
if (nextNumSteps >= mc)
Context().env.testerFail(s"Exceeded `maxSteps=$mc` for clock `${x.instanceName}`.")
}
(maxSteps, nextNumSteps)
})
Context().backend.step(x, cycles)
}
}
Expand Down