Skip to content

Commit 52a3d68

Browse files
authored
Merge pull request #5 from rameloni/tywaves-parametric-simulator
Tywaves parametric simulator
2 parents 25a016e + 617d25f commit 52a3d68

12 files changed

+753
-201
lines changed

README.md

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ discovered [here](https://github.com/rameloni/Tydi-Chisel-testing-frameworks-ana
3737

3838
# Installation
3939

40-
You can run `make all` to install all the pre-requisites.
40+
You can run `make all` to install all the pre-requisites and **this library**.
4141

42-
## Install [surfer-tywaves-demo](https://gitlab.com/rameloni/surfer-tywaves-demo/-/tree/tywaves)
42+
## Prerequisite: Install [surfer-tywaves-demo](https://gitlab.com/rameloni/surfer-tywaves-demo/-/tree/tywaves)
4343

4444
The makefile contains a rule to clone the frontend repository, build and install it.
4545

@@ -50,62 +50,102 @@ make clean # To remove the cloned repository
5050

5151
The frontend will be installed as `surfer-tywaves` executable.
5252

53-
## Publish locally this scala project
53+
## Install and publish locally this library
5454

5555
```bash
56-
make install-chisel-fork
56+
make install-chisel-fork # TEMPORARY NEEDED: Install the chisel fork with the needed changes in the development branch
5757
make install-tywaves-backend
5858
```
5959

6060
Once published locally, the `tywaves-demo-backend` can be used by adding the following line to the `build.sbt` file:
6161

6262
```scala
63-
libraryDependencies += "com.github.rameloni" %% "tywaves-backend" % "0.1.0-SNAPSHOT"
63+
libraryDependencies += "com.github.rameloni" %% "tywaves-demo-backend" % "0.1.0-SNAPSHOT"
6464
```
6565

6666
# Use it on your project
6767

68-
The `TywavesBackend` provides a [simulator](./src/main/tywaves/simulator/BetterEphemeralSimulator.scala) with
69-
functionalities to simulate a circuit through [svsim](https://github.com/chipsalliance/chisel/tree/main/svsim), emit VCD
70-
traces and of course generate the symbol table for the waveform viewer itself automatically.
68+
The `TywavesBackend` provides 2 simulators with functionalities to simulate a circuit
69+
through [svsim](https://github.com/chipsalliance/chisel/tree/main/svsim), emit VCD
70+
traces and of course generate the symbol table for the waveform viewer itself automatically:
71+
72+
- [ParametricSimulator](./src/main/scala/tywaves/simulator/ParametricSimulator.scala): provides some generic features
73+
such as VCD trace emission, name the trace file, pass additional arguments to firtool before simulation, save the
74+
workspace of svsim
75+
- [TywavesSimulator](./src/main/scala/tywaves/simulator/TywavesSimulator.scala): it extends the parametric simulator in
76+
order to generate the symbol table for Tywaves waveform viewer and provides an option to launch the waveform viewer
77+
after the simulation
78+
79+
> While `TywavesSimulator` is central part of the Tywaves project and its functionalities are not fully supported
80+
> yet, `ParametricSimulator` is
81+
> should be able to simulate any Chisel circuit. In case you need to simulate a circuit that is not supported
82+
> by `TywavesSimulator`, you can use `ParametricSimulator`.
83+
>
84+
> If you want to try the functionalities of `Tywaves` then `TywavesSimulator` is the right choice.
85+
> But, if you want to visualize waveforms of any chisel circuit without issues related to features not supported yet,
86+
> you should make use of `ParametricSimulator`.
7187
7288
The following example shows how it is possible also to:
7389

7490
- Enable the trace of the simulation
75-
- Launch the waveform viewer after the simulation
7691
- Set the name of the simulation (it will be used to create a folder with a user defined name for the traces and
7792
workspace of svsim)
93+
- Launch the waveform viewer after the simulation
7894
- Use tywaves and expect API to test the circuit
95+
### Use TywavesSimulator
96+
97+
```scala
98+
import tywaves.simulator.TywavesSimulator._
99+
import tywaves.simulator.simulatorSettings._
100+
import org.scalatest.flatspec.AnyFlatSpec
101+
102+
class GCDTest extends AnyFunSpec with Matchers {
103+
describe("TywavesSimulator") {
104+
it("runs GCD correctly") {
105+
simulate(new GCD(), Seq(VcdTrace, WithTywavesWaveforms(true)), simName = "runs_GCD_correctly_launch_tywaves") {
106+
gcd =>
107+
gcd.io.a.poke(24.U)
108+
gcd.io.b.poke(36.U)
109+
gcd.io.loadValues.poke(1.B)
110+
gcd.clock.step()
111+
gcd.io.loadValues.poke(0.B)
112+
gcd.clock.stepUntil(sentinelPort = gcd.io.resultIsValid, sentinelValue = 1, maxCycles = 10)
113+
gcd.io.resultIsValid.expect(true.B)
114+
gcd.io.result.expect(12)
115+
}
116+
}
117+
}
118+
}
119+
```
79120

121+
### Use ParametricSimulator
80122
```scala
81-
import tywaves.simulator.BetterEphemeralSimulator._
82-
import tywaves.simulator.simSettings
123+
import tywaves.simulator.ParametricSimulator._
124+
import tywaves.simulator.simulatorSettings._
83125
import org.scalatest.flatspec.AnyFlatSpec
84126

85-
class BarTest extends AnyFlatSpec {
86-
behavior of "BarTest"
87-
it should "trace simple bar" in {
88-
simulate(
89-
new Bar,
90-
Seq(simSettings.EnableTraceWithUnderscore, simSettings.LaunchTywavesWaveforms),
91-
simName = "trace_simple_bar",
92-
) { c =>
93-
c.io.a.poke(true)
94-
c.io.b.poke(false)
95-
c.io.out.expect(false.B)
96-
c.clock.step()
97-
c.io.a.poke(true)
98-
c.io.b.poke(true)
99-
c.io.out.expect(true.B)
100-
c.clock.step()
127+
class GCDTest extends AnyFunSpec with Matchers {
128+
describe("ParametricSimulator") {
129+
it("runs GCD correctly") {
130+
simulate(new GCD(), Seq(VcdTrace, SaveWorkdirFile("GCD_parametricSimulator_workdir")), simName = "runs_GCD_correctly") {
131+
gcd =>
132+
gcd.io.a.poke(24.U)
133+
gcd.io.b.poke(36.U)
134+
gcd.io.loadValues.poke(1.B)
135+
gcd.clock.step()
136+
gcd.io.loadValues.poke(0.B)
137+
gcd.clock.stepUntil(sentinelPort = gcd.io.resultIsValid, sentinelValue = 1, maxCycles = 10)
138+
gcd.io.resultIsValid.expect(true.B)
139+
gcd.io.result.expect(12)
140+
}
101141
}
102142
}
103143
}
104144
```
105145

106146
# Example output
107147

108-
The following images show the classic and tywaves waveform visualization of the [GCD](./src/test/gcd/GCD.scala) module.
148+
The following images show the classic and tywaves waveform visualization of the [GCD](./src/test/scala/gcd/GCD.scala) module.
109149
It is possible to see that the left picture does not provide any information about Chisel level types and hierarchy.
110150

111151
```scala
@@ -123,7 +163,7 @@ class GCD extends Module {
123163

124164
when(x > y)(x := x -% y).otherwise(y := y -% x)
125165
when(io.loadValues) {
126-
x := io.a;
166+
x := io.a
127167
y := io.b
128168
}
129169
io.result := x
@@ -139,7 +179,6 @@ class GCD extends Module {
139179

140180
- [x] Parse and map Chisel/FIRRTL/Verilog circuits
141181
- [x] Emit VCD traces from the simulator (both with and without underscores in the signal names)
142-
- [x]
143182
- [x] Automatically generate the symbol table for the waveform viewer
144183
- [x] Dump Chisel types in the final symbol table
145184
- [x] Represent hierarchical structures of bundles

src/main/scala/tywaves/simulator/BetterEphemeralSimulator.scala

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)