diff options
| author | mergify[bot] | 2022-08-25 18:14:54 +0000 |
|---|---|---|
| committer | GitHub | 2022-08-25 18:14:54 +0000 |
| commit | 998913f9379440db26b6aeeaa09e7a11d7615351 (patch) | |
| tree | 6db66270f24a054cc0933e580ac3c410781479b0 /src/test | |
| parent | ae33fe50a5a9ef99125bb325fc5f10c831bb4186 (diff) | |
Bugfix - OpaqueSlot replace invalid localName (backport #2701) (#2702)
* Bugfix - OpaqueSlot replace invalid localName (#2701)
(cherry picked from commit fb8ea2a2fac227f2570da992d7877de2eb1cf801)
* Fix cloneTypes (#2703)
Co-authored-by: Aditya Naik <91489422+adkian-sifive@users.noreply.github.com>
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/chiselTests/RecordSpec.scala | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/RecordSpec.scala b/src/test/scala/chiselTests/RecordSpec.scala index 718c1acb..5080f15f 100644 --- a/src/test/scala/chiselTests/RecordSpec.scala +++ b/src/test/scala/chiselTests/RecordSpec.scala @@ -132,6 +132,35 @@ trait RecordSpecUtils { out := in1 + in2 } + class InnerRecord extends Record { + val k = new InnerInnerRecord + val elements = SeqMap("" -> k) + override def opaqueType = elements.size == 1 + override def cloneType: this.type = (new InnerRecord).asInstanceOf[this.type] + } + + class InnerInnerRecord extends Record { + val k = new SingleElementRecord + val elements = SeqMap("" -> k) + override def opaqueType = elements.size == 1 + override def cloneType: this.type = (new InnerInnerRecord).asInstanceOf[this.type] + } + + class NestedRecordModule extends Module { + val in = IO(Input(new InnerRecord)) + val out = IO(Output(new InnerRecord)) + val inst = Module(new InnerModule) + inst.foo := in + out := inst.bar + } + class InnerModule extends Module { + val foo = IO(Input(new InnerRecord)) + val bar = IO(Output(new InnerRecord)) + + // DO NOT do this; just for testing element connections + bar.elements.head._2 := foo.elements.head._2 + } + class NamedSingleElementRecord extends Record { private val underlying = UInt(8.W) val elements = SeqMap("unused" -> underlying) @@ -205,6 +234,31 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils with Utils { singleElementChirrtl should include("add(in1, in2)") } + they should "work correctly for toTarget in nested opaque type Records" in { + var mod: NestedRecordModule = null + ChiselStage.elaborate { mod = new NestedRecordModule; mod } + val testStrings = Seq( + mod.in.toTarget.toString(), + mod.in.k.toTarget.toString(), + mod.in.k.k.toTarget.toString(), + mod.in.elements.head._2.toTarget.toString(), + mod.in.k.elements.head._2.toTarget.toString(), + mod.in.k.k.elements.head._2.toTarget.toString() + ) + testStrings.foreach(x => assert(x == "~NestedRecordModule|NestedRecordModule>in")) + } + + they should "work correctly when connecting nested opaque type elements" in { + val nestedRecordChirrtl = ChiselStage.emitChirrtl { new NestedRecordModule } + nestedRecordChirrtl should include("input in : UInt<8>") + nestedRecordChirrtl should include("output out : UInt<8>") + nestedRecordChirrtl should include("inst.foo <= in") + nestedRecordChirrtl should include("out <= inst.bar") + nestedRecordChirrtl should include("input foo : UInt<8>") + nestedRecordChirrtl should include("output bar : UInt<8>") + nestedRecordChirrtl should include("bar <= foo") + } + they should "throw an error when map contains a named element and opaqueType is overriden to true" in { (the[Exception] thrownBy extractCause[Exception] { ChiselStage.elaborate { new NamedSingleElementModule } |
