From e27657118ff5915b96f8e3a467d464245fe09769 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Wed, 20 Dec 2017 15:54:25 -0800 Subject: Add compileOptions to Module.apply, use for invalidating submod ports (#747) Fixes #746 Also add test for https://github.com/freechipsproject/firrtl/issues/705 --- .../src/main/scala/chisel3/core/BlackBox.scala | 4 ++-- .../src/main/scala/chisel3/core/Module.scala | 8 +++++--- .../src/main/scala/chisel3/core/UserModule.scala | 23 ++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'chiselFrontend') diff --git a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala index f5e0d5ba..aa0f8064 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala @@ -80,7 +80,7 @@ abstract class ExtModule(val params: Map[String, Param] = Map.empty[String, Para component } - private[core] def initializeInParent() { + private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit = { implicit val sourceInfo = UnlocatableSourceInfo for (x <- getModulePorts) { @@ -165,7 +165,7 @@ abstract class BlackBox(val params: Map[String, Param] = Map.empty[String, Param component } - private[core] def initializeInParent() { + private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit = { for ((_, port) <- io.elements) { pushCommand(DefInvalid(UnlocatableSourceInfo, port.ref)) } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 0e919d3c..fa9ab082 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -23,7 +23,9 @@ object Module { */ def apply[T <: BaseModule](bc: => T): T = macro InstTransform.apply[T] - def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = { + def do_apply[T <: BaseModule](bc: => T) + (implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions): T = { if (Builder.readyForModuleConstr) { throwException("Error: Called Module() twice without instantiating a Module." + sourceInfo.makeMessage(" See " + _)) @@ -62,7 +64,7 @@ object Module { // Handle connections at enclosing scope if(!Builder.currentModule.isEmpty) { pushCommand(DefInstance(sourceInfo, module, component.ports)) - module.initializeInParent() + module.initializeInParent(compileOptions) } module } @@ -124,7 +126,7 @@ abstract class BaseModule extends HasId { /** Sets up this module in the parent context */ - private[core] def initializeInParent() + private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit // // Chisel Internals diff --git a/chiselFrontend/src/main/scala/chisel3/core/UserModule.scala b/chiselFrontend/src/main/scala/chisel3/core/UserModule.scala index c99d53cf..9c923037 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/UserModule.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/UserModule.scala @@ -81,8 +81,15 @@ abstract class UserModule(implicit moduleCompileOptions: CompileOptions) component } - // There is no initialization to be done by default. - private[core] def initializeInParent() {} + private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit = { + implicit val sourceInfo = UnlocatableSourceInfo + + if (!parentCompileOptions.explicitInvalidate) { + for (port <- getModulePorts) { + pushCommand(DefInvalid(sourceInfo, port.ref)) + } + } + } } /** Abstract base class for Modules, which behave much like Verilog modules. @@ -100,14 +107,10 @@ abstract class ImplicitModule(implicit moduleCompileOptions: CompileOptions) // Setup ClockAndReset Builder.currentClockAndReset = Some(ClockAndReset(clock, reset)) - private[core] override def initializeInParent() { + private[core] override def initializeInParent(parentCompileOptions: CompileOptions): Unit = { implicit val sourceInfo = UnlocatableSourceInfo - if (!compileOptions.explicitInvalidate) { - for (port <- getModulePorts) { - pushCommand(DefInvalid(sourceInfo, port.ref)) - } - } + super.initializeInParent(parentCompileOptions) clock := Builder.forcedClock reset := Builder.forcedReset } @@ -173,12 +176,12 @@ abstract class LegacyModule(implicit moduleCompileOptions: CompileOptions) super.generateComponent() } - private[core] override def initializeInParent() { + private[core] override def initializeInParent(parentCompileOptions: CompileOptions): Unit = { // Don't generate source info referencing parents inside a module, since this interferes with // module de-duplication in FIRRTL emission. implicit val sourceInfo = UnlocatableSourceInfo - if (!compileOptions.explicitInvalidate) { + if (!parentCompileOptions.explicitInvalidate) { pushCommand(DefInvalid(sourceInfo, io.ref)) } -- cgit v1.2.3