From 2416d1d44a2bd73bd0556437ece7a7a24d649a7a Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Thu, 25 Oct 2018 13:37:00 -0400 Subject: Make BaseModule.name lazy This changes BaseModule.name to be lazy (instead of eager) to enable a desiredName to be a function of a sub-instance. This includes a test case showing the new behavior. Signed-off-by: Schuyler Eldridge --- chiselFrontend/src/main/scala/chisel3/core/Module.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chiselFrontend/src/main/scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 88013bae..89dd2dee 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -180,7 +180,7 @@ abstract class BaseModule extends HasId { def desiredName = this.getClass.getName.split('.').last /** Legalized name of this module. */ - final val name = Builder.globalNamespace.name(desiredName) + final lazy val name = Builder.globalNamespace.name(desiredName) /** Returns a FIRRTL ModuleName that references this object * @note Should not be called until circuit elaboration is complete -- cgit v1.2.3 From f64388e7cfe71004df93ddeef88447978f37ecb1 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Thu, 25 Oct 2018 16:27:49 -0400 Subject: Check BaseModule.name for NullPointerException This wraps the evaluation of BaseModule.name in try/catch to look for a NullPointerException that may result from trying to evaluate desiredName before it's ready. This catches a test case of using a desiredName that depends on a later defined eager subinstance. h/t @jackkoenig Signed-off-by: Schuyler Eldridge --- chiselFrontend/src/main/scala/chisel3/core/Module.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'chiselFrontend/src/main/scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 89dd2dee..3bdc86d6 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -180,7 +180,13 @@ abstract class BaseModule extends HasId { def desiredName = this.getClass.getName.split('.').last /** Legalized name of this module. */ - final lazy val name = Builder.globalNamespace.name(desiredName) + final lazy val name = try { + Builder.globalNamespace.name(desiredName) + } catch { + case e: NullPointerException => throwException( + s"Error: desiredName of ${this.getClass.getName} is null. Did you evaluate 'name' before all values needed by desiredName were available?", e) + case t: Throwable => throw t + } /** Returns a FIRRTL ModuleName that references this object * @note Should not be called until circuit elaboration is complete -- cgit v1.2.3