Skip to content

Conversation

seldridge
Copy link
Member

Add a new type class, HasSimulator, which provides a method to get a
simulator. Provide two implementations: one for Verilator and one for
VCS. Additionally, provide a low-priority default that maps to Verilator.

This is working towards refactoring Chiselsim to improve the
customizability of its APIs while not dramatically changing how a user
interacts with it. Additionally, this is trying to work towards providing
Scalatest-specific implementations of HasSimulator which allow the
simulator to be chosen on the command line. Much of the code for this is
currently sequestered in either ChiselSpec (part of the tests which are
not published) or in internal code.

Refactor the Chiselsim's DefaultSimulator to no longer create an
instance of a private Verilator simulator class. Instead, use what is
provided by a HasSimulator type class implementation.

This is done to slim down DefaultSimulator (and transitively
EphemeralSimulator) to essentially nothing other than objects that
define convenience APIs for running simulation like the existing
simulate method.

Release Notes

  • Add HasSimulator type class to Chiselsim. This allows for customization of the simulator used by DefaultSimulator.

@seldridge seldridge added the Feature New feature, will be included in release notes label Feb 11, 2025
@seldridge seldridge requested a review from jackkoenig February 11, 2025 20:59
Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a test that shows explicitly "overriding" the simulator to verilator. This obviously is no different than using the default but it shows the API. As written that would look something like:

class MyTestSpec ... {
  implicit val simulator: HasSimulator = chisel3.simulator.HasSimulator.verilator
  ...
}

Or in Scala 3

class MyTestSpec ... {
  given HasSimulator = chisel3.simulator.HasSimulator.verilator
  ...
}

I think this is reasonable, but an alternative could be to move verilator and vcs to some other object, and make them implicits. Then the override would be:

import chisel3.simulator.HasSimulator.simulators.verilator

I am not sure if this is better, but it is something to consider.

@seldridge seldridge force-pushed the dev/seldridge/add-and-use-HasSimulator branch from a312ee8 to 386d24d Compare February 12, 2025 00:55
@seldridge
Copy link
Member Author

I think this is reasonable, but an alternative could be to move verilator and vcs to some other object, and make them implicits. Then the override would be:

I like this approach. I added that exact structure in 51e838e

There is now a minimal test in: 386d24d

Add a new type class, `HasSimulator`, which provides a method to get a
simulator.  Provide two implementations: one for Verilator and one for
VCS.  Additionally, provide a low-priority default that maps to Verilator.

This is working towards refactoring Chiselsim to improve the
customizability of its APIs while not dramatically changing how a user
interacts with it.  Additionally, this is trying to work towards providing
Scalatest-specific implementations of `HasSimulator` which allow the
simulator to be chosen on the command line.  Much of the code for this is
currently sequestered in either ChiselSpec (part of the tests which are
not published) or in internal code.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Refactor the Chiselsim's `DefaultSimulator` to no longer create an
instance of a private Verilator simulator class.  Instead, use what is
provided by a `HasSimulator` type class implementation.

This is done to slim down `DefaultSimulator` (and transitively
`EphemeralSimulator`) to essentially nothing other than objects that
define convenience APIs for running simulation like the existing
`simulate` method.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/add-and-use-HasSimulator branch from 386d24d to ba49fcc Compare February 12, 2025 02:33
@seldridge seldridge merged commit ba49fcc into main Feb 12, 2025
15 checks passed
@seldridge seldridge deleted the dev/seldridge/add-and-use-HasSimulator branch February 12, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants