From 34ee838ebc7c9e08fc1699c9b20386fcb37a5830 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Sun, 17 Jan 2016 14:21:07 -0800 Subject: Improve code generation for When The change to fix elsewhen/otherwise blew up the node count. --- src/main/scala/Chisel/When.scala | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/main') 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()) } -- cgit v1.2.3