summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/When.scala
diff options
context:
space:
mode:
authorAlbert Magyar2020-07-31 11:05:13 -0700
committerGitHub2020-07-31 18:05:13 +0000
commit5ecde24d390248722f8ab6ac790fbd1d453e898e (patch)
treee92d337431500ea06392acd0731f7c021662f6e6 /core/src/main/scala/chisel3/When.scala
parent8990ca3d8d8434a6c979b0c5fc06b05a39fd31d4 (diff)
Check whether signals escape their when scopes (#1518)
* Include and check when scoping as part of reg/mem/wire/node bindings * Allow outdated 'when' behavior of CHIRRTL memory ports with enables * Extend cross-module / when-visibility checks to all data refs * Fixes #1512 * Cannot be checked if outside a module context * E.g. delayed evaluation of printf / assert args * Add basic test cases for cross-module refs / signals escaping when scopes * Remove illegal cross-module references from existing tests
Diffstat (limited to 'core/src/main/scala/chisel3/When.scala')
-rw-r--r--core/src/main/scala/chisel3/When.scala10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/src/main/scala/chisel3/When.scala b/core/src/main/scala/chisel3/When.scala
index b24bdb35..9e6accbc 100644
--- a/core/src/main/scala/chisel3/When.scala
+++ b/core/src/main/scala/chisel3/When.scala
@@ -45,6 +45,8 @@ object when {
*/
final class WhenContext(sourceInfo: SourceInfo, cond: Option[() => Bool], block: => Any, firrtlDepth: Int = 0) {
+ private var scopeOpen = false
+
/** This block of logic gets executed if above conditions have been
* false and this condition is true. The lazy argument pattern
* makes it possible to delay evaluation of cond, emitting the
@@ -65,13 +67,16 @@ final class WhenContext(sourceInfo: SourceInfo, cond: Option[() => Bool], block:
def otherwise(block: => Any)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Unit =
new WhenContext(sourceInfo, None, block, firrtlDepth + 1)
+ def active(): Boolean = scopeOpen
+
/*
*
*/
if (firrtlDepth > 0) { pushCommand(AltBegin(sourceInfo)) }
cond.foreach( c => pushCommand(WhenBegin(sourceInfo, c().ref)) )
- Builder.whenDepth += 1
+ Builder.pushWhen(this)
try {
+ scopeOpen = true
block
} catch {
case ret: scala.runtime.NonLocalReturnControl[_] =>
@@ -79,7 +84,8 @@ final class WhenContext(sourceInfo: SourceInfo, cond: Option[() => Bool], block:
" Perhaps you meant to use Mux or a Wire as a return value?"
)
}
- Builder.whenDepth -= 1
+ scopeOpen = false
+ Builder.popWhen()
cond.foreach( c => pushCommand(WhenEnd(sourceInfo,firrtlDepth)) )
if (cond.isEmpty) { pushCommand(OtherwiseEnd(sourceInfo,firrtlDepth)) }
}