diff options
| author | Albert Magyar | 2017-11-22 17:51:51 -0800 |
|---|---|---|
| committer | Richard Lin | 2018-01-02 13:41:32 -0800 |
| commit | 11c1112661e04094bccfd805e737e0318eb91ebc (patch) | |
| tree | 185ea171a05d289ea8ff2ed1525b40f14c50a3bb /src | |
| parent | 7c3c18de2ffd56af51b99030c7ae7d3a321aed5f (diff) | |
Add auto clone implementation for inner Bundles (#722)
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/scala/chiselTests/AutoNestedCloneSpec.scala | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/AutoNestedCloneSpec.scala b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala new file mode 100644 index 00000000..178cb142 --- /dev/null +++ b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala @@ -0,0 +1,72 @@ +// See LICENSE for license details. + +package chiselTests +import Chisel.ChiselException +import org.scalatest._ +import chisel3._ + +class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { + behavior of "autoCloneType of inner Bundle in Chisel3" + + it should "clone a doubly-nested inner bundle successfully" in { + elaborate { + class Outer(val w: Int) extends Module { + class Middle(val w: Int) { + class InnerIOType extends Bundle { + val in = Input(UInt(w.W)) + } + def getIO = new InnerIOType + } + val io = IO((new Middle(w)).getIO) + } + new Outer(2) + } + } + + it should "clone an anonymous inner bundle successfully" in { + elaborate { + class TestTop(val w: Int) extends Module { + val io = IO(new Bundle{ val a = UInt(w.W) }) + } + new TestTop(2) + } + } + + it should "pick the correct $outer instance for an anonymous inner bundle" in { + elaborate { + class Inner(val w: Int) extends Module { + val io = IO(new Bundle{ + val in = Input(UInt(w.W)) + val out = Output(UInt(w.W)) + }) + } + class Outer(val w: Int) extends Module { + val io = IO(new Bundle{ + val in = Input(UInt(w.W)) + val out = Output(UInt(w.W)) + }) + val i = Module(new Inner(w)) + val iw = Wire(chiselTypeOf(i.io)) + iw <> io + i.io <> iw + } + new Outer(2) + } + } + + behavior of "anonymous doubly-nested inner bundle fails with clear error" + ( the[ChiselException] thrownBy { + elaborate { + class Outer(val w: Int) extends Module { + class Middle(val w: Int) { + def getIO = new Bundle { + val in = Input(UInt(w.W)) + } + } + val io = IO((new Middle(w)).getIO) + } + new Outer(2) + } + }).getMessage should include("non-trivial inner Bundle class") + +} |
