diff options
| author | Jack Koenig | 2017-01-10 18:34:13 -0800 |
|---|---|---|
| committer | Jack Koenig | 2017-02-08 18:00:32 -0800 |
| commit | 132b80edee2fb8e730d3b6f5eb5f36051a819525 (patch) | |
| tree | ac5e31aaabe74e991fbb9fbea12178bf5406a5a4 | |
| parent | f902b119069732910ca4b26ab45e0d6392464b3b (diff) | |
Add counter for depth of when scope
3 files changed, 18 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index de13c078..3ff68772 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -31,16 +31,25 @@ object Module { } Builder.readyForModuleConstr = true val parent: Option[Module] = Builder.currentModule + val whenDepth: Int = Builder.whenDepth - val m = bc.setRefs() // This will set currentModule and unset readyForModuleConstr!!! + // Execute the module, this has the following side effects: + // - set currentModule + // - unset readyForModuleConstr + // - reset whenDepth to 0 + val m = bc.setRefs() m._commands.prepend(DefInvalid(childSourceInfo, m.io.ref)) // init module outputs + if (Builder.whenDepth != 0) { + throwException("Internal Error! When depth is != 0, this should not be possible") + } 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! + Builder.whenDepth = whenDepth val ports = m.computePorts // Blackbox inherits from Module so we have to match on it first TODO fix @@ -118,6 +127,7 @@ extends HasId { private[chisel3] val _commands = ArrayBuffer[Command]() private[core] val _ids = ArrayBuffer[HasId]() Builder.currentModule = Some(this) + Builder.whenDepth = 0 if (!Builder.readyForModuleConstr) { throwException("Error: attempted to instantiate a Module without wrapping it in Module().") } diff --git a/chiselFrontend/src/main/scala/chisel3/core/When.scala b/chiselFrontend/src/main/scala/chisel3/core/When.scala index 7501ebb1..9b646855 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/When.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/When.scala @@ -54,6 +54,8 @@ final class WhenContext(sourceInfo: SourceInfo, cond: Bool, prevCond: => Bool, b new WhenContext(sourceInfo, prevCond, null, block) pushCommand(WhenBegin(sourceInfo, cond.ref)) + Builder.whenDepth += 1 block + Builder.whenDepth -= 1 pushCommand(WhenEnd(sourceInfo)) } diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index d8202da6..9e389788 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -150,6 +150,7 @@ private[chisel3] class DynamicContext() { // Set by object Module.apply before calling class Module constructor // Used to distinguish between no Module() wrapping, multiple wrappings, and rewrapping var readyForModuleConstr: Boolean = false + var whenDepth: Int = 0 // Depth of when nesting val errors = new ErrorLog val namingStack = new internal.naming.NamingStack } @@ -181,6 +182,10 @@ private[chisel3] object Builder { def readyForModuleConstr_=(target: Boolean): Unit = { dynamicContext.readyForModuleConstr = target } + def whenDepth: Int = dynamicContext.whenDepth + def whenDepth_=(target: Int): Unit = { + dynamicContext.whenDepth = target + } // TODO(twigg): Ideally, binding checks and new bindings would all occur here // However, rest of frontend can't support this yet. |
