From 815b1c3cb311b7f4dfb7a2f00e0e2d62795bdc6b Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 11 Nov 2016 14:37:03 -0800 Subject: Add checks for misuse or omission of Module() Implemented by adding a Boolean to check for alternating invocations of object Module.apply and the constructor of abstract class Module. Fixes #192 --- .../src/main/scala/chisel3/core/Module.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'chiselFrontend/src/main/scala/chisel3/core/Module.scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index c3353d85..ca391091 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -25,9 +25,21 @@ object Module { // module de-duplication in FIRRTL emission. val childSourceInfo = UnlocatableSourceInfo + if (Builder.readyForModuleConstr) { + throwException("Error: Called Module() twice without instantiating a Module." + + sourceInfo.makeMessage(" See " + _)) + } + Builder.readyForModuleConstr = true val parent: Option[Module] = Builder.currentModule - val m = bc.setRefs() // This will set currentModule! + + val m = bc.setRefs() // This will set currentModule and unset readyForModuleConstr!!! m._commands.prepend(DefInvalid(childSourceInfo, m.io.ref)) // init module outputs + + if (Builder.readyForModuleConstr) { + throwException("Error: attempted to instantiate a Module, but nothing happened. " + + "This is probably due to rewrapping a Module instance with Module()." + + sourceInfo.makeMessage(" See " + _)) + } Builder.currentModule = parent // Back to parent! val ports = m.computePorts val component = Component(m, m.name, ports, m._commands) @@ -93,6 +105,10 @@ extends HasId { private[chisel3] val _commands = ArrayBuffer[Command]() private[core] val _ids = ArrayBuffer[HasId]() Builder.currentModule = Some(this) + if (!Builder.readyForModuleConstr) { + throwException("Error: attempted to instantiate a Module without wrapping it in Module().") + } + readyForModuleConstr = false /** Desired name of this module. */ def desiredName = this.getClass.getName.split('.').last -- cgit v1.2.3 From 822160cc8e76e70643fb56707bb39f6f7526b6fd Mon Sep 17 00:00:00 2001 From: jackkoenig Date: Thu, 22 Sep 2016 22:38:33 -0700 Subject: Add support for parameterized BlackBoxes Also restrict black boxes to not allow hardware inside of them since it was being silently dropped anyway. Resolves #289 --- chiselFrontend/src/main/scala/chisel3/core/Module.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'chiselFrontend/src/main/scala/chisel3/core/Module.scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index ca391091..62b6d5ce 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -41,8 +41,16 @@ object Module { sourceInfo.makeMessage(" See " + _)) } Builder.currentModule = parent // Back to parent! + val ports = m.computePorts - val component = Component(m, m.name, ports, m._commands) + // Blackbox inherits from Module so we have to match on it first TODO fix + val component = m match { + case bb: BlackBox => + DefBlackBox(bb, bb.name, ports, bb.params) + case mod: Module => + mod._commands.prepend(DefInvalid(childSourceInfo, mod.io.ref)) // init module outputs + DefModule(mod, mod.name, ports, mod._commands) + } m._component = Some(component) Builder.components += component // Avoid referencing 'parent' in top module -- cgit v1.2.3 From 11302f77c90512f81b882ad1cc623c53d45724f8 Mon Sep 17 00:00:00 2001 From: Donggyu Date: Mon, 21 Nov 2016 14:52:05 -0800 Subject: Remove deduplication from Chisel (#347) Remove modName from Module--- chiselFrontend/src/main/scala/chisel3/core/Module.scala | 9 --------- 1 file changed, 9 deletions(-) (limited to 'chiselFrontend/src/main/scala/chisel3/core/Module.scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 62b6d5ce..bd406529 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -124,18 +124,9 @@ extends HasId { /** Legalized name of this module. */ final val name = Builder.globalNamespace.name(desiredName) - /** FIRRTL Module name */ - private var _modName: Option[String] = None - private[chisel3] def setModName(name: String) = _modName = Some(name) - def modName = _modName match { - case Some(name) => name - case None => throwException("modName should be called after circuit elaboration") - } - /** Keep component for signal names */ private[chisel3] var _component: Option[Component] = None - /** Signal name (for simulation). */ override def instanceName = if (_parent == None) name else _component match { -- cgit v1.2.3