summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel
diff options
context:
space:
mode:
authorAndrew Waterman2016-01-17 14:21:07 -0800
committerAndrew Waterman2016-01-17 14:21:07 -0800
commit34ee838ebc7c9e08fc1699c9b20386fcb37a5830 (patch)
tree2dabc92c635d1cc6f9fc6e7c4e1399a10e5f532a /src/main/scala/Chisel
parent5a4af360ecdfb376ced6e81a305b70a8aee364f0 (diff)
Improve code generation for When
The change to fix elsewhen/otherwise blew up the node count.
Diffstat (limited to 'src/main/scala/Chisel')
-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())
}