diff options
| author | mergify[bot] | 2022-03-09 20:40:25 +0000 |
|---|---|---|
| committer | GitHub | 2022-03-09 20:40:25 +0000 |
| commit | 4ee545d7706a2d2ba59902fb86a4393287327a9a (patch) | |
| tree | 657ed76babbc56ac2edc6b49f221f474783c77d3 /src/test/scala | |
| parent | 941dd7ee76cadacbdd10b3d10d267f5d58a7ed4e (diff) | |
Support BlackBoxes in D/I (#2438) (#2442)
Also delete an errant println in InstanceSpec
(cherry picked from commit 3462c54c018a52a377f1c89121b6ed99c5b0ae1d)
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/test/scala')
| -rw-r--r-- | src/test/scala/chiselTests/experimental/hierarchy/Examples.scala | 7 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala | 69 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala index aff0a771..fa26cbde 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala @@ -47,6 +47,13 @@ object Examples { val addOneDef = Seq.fill(3)(Definition(new AddOne)) out := in + 1.U } + @instantiable + class AddOneBlackBox extends BlackBox { + @public val io = IO(new Bundle { + val in = Input(UInt(32.W)) + val out = Output(UInt(32.W)) + }) + } @instantiable class AddTwo extends Module { diff --git a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala index 407a7237..8d8f7ea5 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala @@ -43,6 +43,29 @@ class InstanceSpec extends ChiselFunSpec with Utils { val (chirrtl, _) = getFirrtlAndAnnos(new Top) chirrtl.serialize should include("inst i0 of AddOne") } + it("0.3: BlackBoxes should be supported") { + class Top extends Module { + val in = IO(Input(UInt(32.W))) + val out = IO(Output(UInt(32.W))) + val io = IO(new Bundle { + val in = Input(UInt(32.W)) + val out = Output(UInt(32.W)) + }) + val definition = Definition(new AddOneBlackBox) + val i0 = Instance(definition) + val i1 = Instance(definition) + i0.io.in := in + out := i0.io.out + io <> i1.io + } + val chirrtl = getFirrtlAndAnnos(new Top)._1.serialize + chirrtl should include("inst i0 of AddOneBlackBox") + chirrtl should include("inst i1 of AddOneBlackBox") + chirrtl should include("i0.in <= in") + chirrtl should include("out <= i0.out") + chirrtl should include("i1.in <= io.in") + chirrtl should include("io.out <= i1.out") + } } describe("1: Annotations on instances in same chisel compilation") { it("1.0: should work on a single instance, annotating the instance") { @@ -338,7 +361,6 @@ class InstanceSpec extends ChiselFunSpec with Utils { mark(i.syncReadMem, "SyncReadMem") } val (_, annos) = getFirrtlAndAnnos(new Top) - annos.foreach { x => println(x.serialize) } annos should contain(MarkAnnotation("~Top|Top/i:HasMems>mem".rt, "Mem")) annos should contain(MarkAnnotation("~Top|Top/i:HasMems>syncReadMem".rt, "SyncReadMem")) } @@ -717,6 +739,51 @@ class InstanceSpec extends ChiselFunSpec with Utils { annos should contain(e) } } + + it("7.4: should work on Views of BlackBoxes") { + @instantiable + class MyBlackBox extends BlackBox { + @public val io = IO(new Bundle { + val in = Input(UInt(8.W)) + val out = Output(UInt(8.W)) + }) + @public val innerView = io.viewAs + @public val foo = io.in.viewAs[UInt] + @public val bar = io.out.viewAs[UInt] + } + class Top extends RawModule { + val foo = IO(Input(UInt(8.W))) + val bar = IO(Output(UInt(8.W))) + val i = Instance(Definition(new MyBlackBox)) + val outerView = i.io.viewAs + i.foo := foo + bar := i.bar + mark(i.foo, "i.foo") + mark(i.bar, "i.bar") + mark(i.innerView.in, "i.innerView.in") + mark(outerView.out, "outerView.out") + } + val inst = "~Top|Top/i:MyBlackBox" + val expectedAnnos = List( + s"$inst>in".rt -> "i.foo", + s"$inst>out".rt -> "i.bar", + s"$inst>in".rt -> "i.innerView.in", + s"$inst>out".rt -> "outerView.out" + ) + val expectedLines = List( + "i.in <= foo", + "bar <= i.out" + ) + val (chirrtl, annos) = getFirrtlAndAnnos(new Top) + val text = chirrtl.serialize + for (line <- expectedLines) { + text should include(line) + } + for (e <- expectedAnnos.map(MarkAnnotation.tupled)) { + annos should contain(e) + } + } + } describe("8: @instantiable and @public should compose with CloneModuleAsRecord") { |
