From 7c3c18de2ffd56af51b99030c7ae7d3a321aed5f Mon Sep 17 00:00:00 2001 From: ducky Date: Fri, 3 Nov 2017 18:34:46 -0700 Subject: Autoclonetype initial prototype --- src/main/scala/chisel3/compatibility.scala | 12 ++++---- src/main/scala/chisel3/testers/BasicTester.scala | 9 ++++-- src/test/scala/chiselTests/AutoClonetypeSpec.scala | 34 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/test/scala/chiselTests/AutoClonetypeSpec.scala (limited to 'src') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index f299a287..3c12b483 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -250,9 +250,9 @@ package object Chisel { // scalastyle:ignore package.object.name abstract class BlackBox(params: Map[String, Param] = Map.empty[String, Param]) extends chisel3.core.BlackBox(params) { // This class auto-wraps the BlackBox with IO(...), allowing legacy code (where IO(...) wasn't // required) to build. - override def _autoWrapPorts(): Unit = { // scalastyle:ignore method.name - if (!_ioPortBound()) { - IO(io) + override def _compatAutoWrapPorts(): Unit = { // scalastyle:ignore method.name + if (!_compatIoPortBound()) { + _bindIoInPlace(io) } } } @@ -278,9 +278,9 @@ package object Chisel { // scalastyle:ignore package.object.name def this(_clock: Clock, _reset: Bool)(implicit moduleCompileOptions: CompileOptions) = this(Option(_clock), Option(_reset))(moduleCompileOptions) - override def _autoWrapPorts(): Unit = { // scalastyle:ignore method.name - if (!_ioPortBound() && io != null) { - IO(io) + override def _compatAutoWrapPorts(): Unit = { // scalastyle:ignore method.name + if (!_compatIoPortBound() && io != null) { + _bindIoInPlace(io) } } } diff --git a/src/main/scala/chisel3/testers/BasicTester.scala b/src/main/scala/chisel3/testers/BasicTester.scala index 6d1a4913..4cd03863 100644 --- a/src/main/scala/chisel3/testers/BasicTester.scala +++ b/src/main/scala/chisel3/testers/BasicTester.scala @@ -11,9 +11,14 @@ import internal.firrtl._ import internal.sourceinfo.SourceInfo //import chisel3.core.ExplicitCompileOptions.NotStrict -class BasicTester extends Module() { +class TesterIO extends Bundle { // The testbench has no IOs, rather it should communicate using printf, assert, and stop. - val io = IO(new Bundle()) + // This is here (instead of just `new Bundle()`, since that has an implicit compileOptions + // constructor argument which is misapplied by clonetype +} + +class BasicTester extends Module() { + val io = IO(new TesterIO) def popCount(n: Long): Int = n.toBinaryString.count(_=='1') diff --git a/src/test/scala/chiselTests/AutoClonetypeSpec.scala b/src/test/scala/chiselTests/AutoClonetypeSpec.scala new file mode 100644 index 00000000..93031c1c --- /dev/null +++ b/src/test/scala/chiselTests/AutoClonetypeSpec.scala @@ -0,0 +1,34 @@ +// See LICENSE for license details. + +package chiselTests + +import chisel3._ + +import chisel3.testers.BasicTester + +class BundleWithIntArg(val i: Int) extends Bundle { + val out = Output(UInt(i.W)) +} + +class ModuleWithInner extends Module { + class InnerBundle(val i: Int) extends Bundle { + val out = Output(UInt(i.W)) + } + + val io = IO(new InnerBundle(14)) + io.out := 1.U +} + + +class AutoClonetypeSpec extends ChiselFlatSpec { + "Bundles with Scala args" should "not need clonetype" in { + elaborate { new Module { + val io = IO(new BundleWithIntArg(8)) + io.out := 1.U + } } + } + + "Inner bundles with Scala args" should "not need clonetype" in { + elaborate { new ModuleWithInner } + } +} -- cgit v1.2.3