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

Make Simulator Classes Public for Customization #4240 #4662

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions src/main/scala-2/chisel3/simulator/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ package object simulator {
/**
* An opaque class that can be passed to `Simulation.run` to get access to a `SimulatedModule` in the simulation body.
*/
final class ElaboratedModule[T] private[simulator] (
private[simulator] val wrapped: T,
private[simulator] val ports: Seq[(Data, ModuleInfo.Port)],
final class ElaboratedModule[T] (
val wrapped: T,
val ports: Seq[(Data, ModuleInfo.Port)],
private[simulator] val layers: Seq[chisel3.layer.Layer]
)

/**
* A class that enables using a Chisel module to control an `svsim.Simulation`.
*/
final class SimulatedModule[T] private[simulator] (
private[simulator] val elaboratedModule: ElaboratedModule[T],
final class SimulatedModule[T] (
val elaboratedModule: ElaboratedModule[T],
controller: Simulation.Controller
) extends AnySimulatedModule(elaboratedModule.ports, controller) {
def wrapped: T = elaboratedModule.wrapped
}
sealed class AnySimulatedModule protected (
sealed class AnySimulatedModule (
ports: Seq[(Data, ModuleInfo.Port)],
val controller: Simulation.Controller
) {
Expand Down Expand Up @@ -56,7 +56,7 @@ package object simulator {

// When using the low-level API, the user must explicitly call `controller.completeInFlightCommands()` to ensure that all commands are executed. When using a higher-level API like peek/poke, we handle this automatically.
private var shouldCompleteInFlightCommands: Boolean = false
private[simulator] def completeSimulation() = {
def completeSimulation() = {
if (shouldCompleteInFlightCommands) {
shouldCompleteInFlightCommands = false
controller.completeInFlightCommands()
Expand All @@ -68,19 +68,19 @@ package object simulator {
private[simulator] def willEvaluate() = {
evaluateBeforeNextPeek = false
}
private[simulator] def willPoke() = {
def willPoke() = {
shouldCompleteInFlightCommands = true
evaluateBeforeNextPeek = true
}
private[simulator] def willPeek() = {
def willPeek() = {
shouldCompleteInFlightCommands = true
if (evaluateBeforeNextPeek) {
willEvaluate()
controller.run(0)
}
}
}
private[simulator] object AnySimulatedModule {
object AnySimulatedModule {
private val dynamicVariable = new scala.util.DynamicVariable[Option[AnySimulatedModule]](None)
def withValue[T](module: AnySimulatedModule)(body: => T): T = {
require(dynamicVariable.value.isEmpty, "Nested simulations are not supported.")
Expand Down
Loading