diff options
| author | Jim Lawson | 2016-12-19 12:27:15 -0800 |
|---|---|---|
| committer | GitHub | 2016-12-19 12:27:15 -0800 |
| commit | 4eebd787312792f7a3722af61ab7e6349081d3b4 (patch) | |
| tree | 333fe66fba7ea7337fa1f6ffe1ec905cd2f724f3 | |
| parent | 0233f704e83d380b1fe8311dfffa3f44f74b506b (diff) | |
| parent | dd4650d29ed18ec610ad7561f4e9c990ba887a3d (diff) | |
Merge pull request #360 from ucb-bar/exceptionfix
Throw exceptions for cloneType failures - fix #358
3 files changed, 70 insertions, 3 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index 9bbf9d0e..26c971b3 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -408,12 +408,12 @@ class Bundle extends Aggregate { constructor.newInstance(_parent.get).asInstanceOf[this.type] } catch { case _: java.lang.reflect.InvocationTargetException | _: java.lang.IllegalArgumentException => - Builder.error(s"Parameterized Bundle ${this.getClass} needs cloneType method. You are probably using " + + Builder.exception(s"Parameterized Bundle ${this.getClass} needs cloneType method. You are probably using " + "an anonymous Bundle object that captures external state and hence is un-cloneTypeable") this } case _: java.lang.reflect.InvocationTargetException | _: java.lang.IllegalArgumentException => - Builder.error(s"Parameterized Bundle ${this.getClass} needs cloneType method") + Builder.exception(s"Parameterized Bundle ${this.getClass} needs cloneType method") this } } diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index 7a77763b..6e463311 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -170,7 +170,7 @@ private[chisel3] object Builder { } def forcedModule: Module = currentModule match { case Some(module) => module - case None => throw new Exception( + case None => throwException( "Error: Not in a Module. Likely cause: Missed Module() wrap or bare chisel API call." // A bare api call is, e.g. calling Wire() from the scala console). ) @@ -200,6 +200,16 @@ private[chisel3] object Builder { def warning(m: => String): Unit = errors.warning(m) def deprecated(m: => String): Unit = errors.deprecated(m) + /** Record an exception as an error, and throw it. + * + * @param m exception message + */ + @throws(classOf[ChiselException]) + def exception(m: => String): Unit = { + error(m) + throwException(m) + } + def build[T <: Module](f: => T): Circuit = { dynamicContextVar.withValue(Some(new DynamicContext())) { errors.info("Elaborating design...") diff --git a/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala new file mode 100644 index 00000000..719484ac --- /dev/null +++ b/src/test/scala/chiselTests/MissingCloneBindingExceptionSpec.scala @@ -0,0 +1,57 @@ +// See LICENSE for license details. + +package chiselTests +import Chisel.ChiselException +import org.scalatest._ + +class MissingCloneBindingExceptionSpec extends ChiselFlatSpec with Matchers { + behavior of "missing cloneType in Chisel3" + ( the[ChiselException] thrownBy { + import chisel3._ + + class TestIO(w: Int) extends Bundle { + val a = Vec(4, UInt(width = w)).asInput + + //override def cloneType = (new TestIO(w)).asInstanceOf[this.type] + } + + class Test extends Module { + val io = IO(new TestIO(32)) + } + + class TestTop extends Module { + val io = IO(new Bundle {}) + + val subs = Vec.fill(2) { + Module(new Test).io + } + } + + elaborate(new TestTop) + }).getMessage should include("needs cloneType method") + + behavior of "missing cloneType in Chisel2" + ( the[ChiselException] thrownBy { + import Chisel._ + + class TestIO(w: Int) extends Bundle { + val a = Vec(4, UInt(width = w)).asInput + + //override def cloneType = (new TestIO(w)).asInstanceOf[this.type] + } + + class Test extends Module { + val io = IO(new TestIO(32)) + } + + class TestTop extends Module { + val io = IO(new Bundle {}) + + val subs = Vec.fill(2) { + Module(new Test).io + } + } + + elaborate(new TestTop) + }).getMessage should include("needs cloneType method") +} |
