summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/Chisel/When.scala15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main/scala/Chisel/When.scala b/src/main/scala/Chisel/When.scala
index 506661b9..af6b3555 100644
--- a/src/main/scala/Chisel/When.scala
+++ b/src/main/scala/Chisel/When.scala
@@ -24,8 +24,8 @@ object when { // scalastyle:ignore object.name
* }
* }}}
*/
- def apply(cond: => Bool)(block: => Unit): WhenContext = {
- new WhenContext(cond, Bool(true))(block)
+ def apply(cond: Bool)(block: => Unit): WhenContext = {
+ new WhenContext(cond, !cond)(block)
}
}
@@ -36,20 +36,21 @@ object when { // scalastyle:ignore object.name
* that both the condition is true and all the previous conditions have been
* false.
*/
-class WhenContext(cond: => Bool, prevCond: Bool)(block: => Unit) {
+class WhenContext(cond: Bool, prevCond: => Bool)(block: => Unit) {
/** This block of logic gets executed if above conditions have been false
* and this condition is true.
*/
- def elsewhen (elseCond: => Bool)(block: => Unit): WhenContext =
- new WhenContext(elseCond, prevCond && !cond)(block)
+ def elsewhen (elseCond: Bool)(block: => Unit): WhenContext = {
+ new WhenContext(prevCond && elseCond, prevCond && !elseCond)(block)
+ }
/** This block of logic gets executed only if the above conditions were all
* false. No additional logic blocks may be appended past the `otherwise`.
*/
def otherwise(block: => Unit): Unit =
- new WhenContext(Bool(true), prevCond && !cond)(block)
+ new WhenContext(prevCond, null)(block)
- pushCommand(WhenBegin((cond && prevCond).ref))
+ pushCommand(WhenBegin(cond.ref))
block
pushCommand(WhenEnd())
}