From 11c1112661e04094bccfd805e737e0318eb91ebc Mon Sep 17 00:00:00 2001 From: Albert Magyar Date: Wed, 22 Nov 2017 17:51:51 -0800 Subject: Add auto clone implementation for inner Bundles (#722) --- .../scala/chiselTests/AutoNestedCloneSpec.scala | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/scala/chiselTests/AutoNestedCloneSpec.scala (limited to 'src/test/scala/chiselTests/AutoNestedCloneSpec.scala') 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") + +} -- cgit v1.2.3 From 48e30fab101c5552c73fc5a76cad3ccc6b38946f Mon Sep 17 00:00:00 2001 From: ducky64 Date: Wed, 22 Nov 2017 22:26:09 -0800 Subject: Support for inner classes, implicit parameter lists, supertypess --- src/test/scala/chiselTests/AutoNestedCloneSpec.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/test/scala/chiselTests/AutoNestedCloneSpec.scala') diff --git a/src/test/scala/chiselTests/AutoNestedCloneSpec.scala b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala index 178cb142..d3977213 100644 --- a/src/test/scala/chiselTests/AutoNestedCloneSpec.scala +++ b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala @@ -9,7 +9,7 @@ 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 { + elaborate { class Outer(val w: Int) extends Module { class Middle(val w: Int) { class InnerIOType extends Bundle { @@ -17,16 +17,18 @@ class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { } def getIO = new InnerIOType } - val io = IO((new Middle(w)).getIO) + val io = IO(new Bundle {}) + val myWire = Wire((new Middle(w)).getIO) } new Outer(2) } } it should "clone an anonymous inner bundle successfully" in { - elaborate { + elaborate { class TestTop(val w: Int) extends Module { - val io = IO(new Bundle{ val a = UInt(w.W) }) + val io = IO(new Bundle {}) + val myWire = Wire(new Bundle{ val a = UInt(w.W) }) } new TestTop(2) } @@ -63,10 +65,11 @@ class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { val in = Input(UInt(w.W)) } } - val io = IO((new Middle(w)).getIO) + val io = IO(new Bundle {}) + val myWire = Wire((new Middle(w)).getIO) } new Outer(2) } - }).getMessage should include("non-trivial inner Bundle class") + }).getMessage should include("Unable to determine instance") } -- cgit v1.2.3 From ade792ee7c5bb718f738f5e4c3886b2e87c68756 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Thu, 28 Dec 2017 16:56:05 -0800 Subject: Add support for autoclonetype of bound, anonymous inner Bundles Also change Data.outerModule to Bundle._outerInst since it is only used in autoclonetype. _outerInst is also Option[Object] instead of Option[BaseModule] because the outer object could also be a Bundle. --- .../scala/chiselTests/AutoNestedCloneSpec.scala | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/test/scala/chiselTests/AutoNestedCloneSpec.scala') diff --git a/src/test/scala/chiselTests/AutoNestedCloneSpec.scala b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala index d3977213..746780be 100644 --- a/src/test/scala/chiselTests/AutoNestedCloneSpec.scala +++ b/src/test/scala/chiselTests/AutoNestedCloneSpec.scala @@ -5,6 +5,12 @@ import Chisel.ChiselException import org.scalatest._ import chisel3._ +class BundleWithAnonymousInner(val w: Int) extends Bundle { + val inner = new Bundle { + val foo = Input(UInt(w.W)) + } +} + class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { behavior of "autoCloneType of inner Bundle in Chisel3" @@ -18,7 +24,7 @@ class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { def getIO = new InnerIOType } val io = IO(new Bundle {}) - val myWire = Wire((new Middle(w)).getIO) + val myWire = Wire((new Middle(w)).getIO) } new Outer(2) } @@ -56,6 +62,33 @@ class AutoNestedCloneSpec extends ChiselFlatSpec with Matchers { } } + it should "clone an anonymous, bound, inner bundle of another bundle successfully" in { + elaborate { + class TestModule(w: Int) extends Module { + val io = IO(new BundleWithAnonymousInner(w) ) + val w0 = WireInit(io) + val w1 = WireInit(io.inner) + } + new TestModule(8) + } + } + + it should "clone an anonymous, inner bundle of a Module, bound to another bundle successfully" in { + elaborate { + class TestModule(w: Int) extends Module { + val bun = new Bundle { + val foo = UInt(w.W) + } + val io = IO(new Bundle { + val inner = Input(bun) + }) + val w0 = WireInit(io) + val w1 = WireInit(io.inner) + } + new TestModule(8) + } + } + behavior of "anonymous doubly-nested inner bundle fails with clear error" ( the[ChiselException] thrownBy { elaborate { -- cgit v1.2.3