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 /chiselFrontend/src/main/scala/chisel3/core | |
| parent | f902b119069732910ca4b26ab45e0d6392464b3b (diff) | |
Add counter for depth of when scope
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Module.scala | 12 | ||||
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/When.scala | 2 |
2 files changed, 13 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)) } |
