From 2e62da09ed1ed0725a14185ae76a683da73b32f4 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Thu, 10 Nov 2016 10:05:15 -0800 Subject: Throw exceptions for cloneType failures - fix #358 Add a Builder.exception() method for those cases where continuing is likely to mask the initial error. --- chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | 4 ++-- chiselFrontend/src/main/scala/chisel3/internal/Builder.scala | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'chiselFrontend/src') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index de7af462..68fe0bb5 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 b4b0e028..32ba248c 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -188,6 +188,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...") -- cgit v1.2.3