summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/Chisel/When.scala
diff options
context:
space:
mode:
authorducky2016-05-05 13:22:04 -0700
committerducky2016-05-20 16:02:49 -0700
commite92f2f69477a6ce86fc148a1a95db5797f2e3051 (patch)
tree2f1511e3395299fd4f1e98c3f75886e06c0cd096 /chiselFrontend/src/main/scala/Chisel/When.scala
parent84de04606bc972bd6a83f67913a0e30c4c46ee5e (diff)
Implementation of source locators
Diffstat (limited to 'chiselFrontend/src/main/scala/Chisel/When.scala')
-rw-r--r--chiselFrontend/src/main/scala/Chisel/When.scala21
1 files changed, 12 insertions, 9 deletions
diff --git a/chiselFrontend/src/main/scala/Chisel/When.scala b/chiselFrontend/src/main/scala/Chisel/When.scala
index 5f6b02c5..90b3d1a5 100644
--- a/chiselFrontend/src/main/scala/Chisel/When.scala
+++ b/chiselFrontend/src/main/scala/Chisel/When.scala
@@ -2,9 +2,12 @@
package Chisel
+import scala.language.experimental.macros
+
import internal._
import internal.Builder.pushCommand
import internal.firrtl._
+import internal.sourceinfo.{SourceInfo}
object when { // scalastyle:ignore object.name
/** Create a `when` condition block, where whether a block of logic is
@@ -24,8 +27,8 @@ object when { // scalastyle:ignore object.name
* }
* }}}
*/
- def apply(cond: Bool)(block: => Unit): WhenContext = {
- new WhenContext(cond, !cond)(block)
+ def apply(cond: Bool)(block: => Unit)(implicit sourceInfo: SourceInfo): WhenContext = {
+ new WhenContext(sourceInfo, cond, !cond, block)
}
}
@@ -36,21 +39,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) {
+final class WhenContext(sourceInfo: SourceInfo, 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(prevCond && elseCond, prevCond && !elseCond)(block)
+ def elsewhen (elseCond: Bool)(block: => Unit)(implicit sourceInfo: SourceInfo): WhenContext = {
+ new WhenContext(sourceInfo, 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(prevCond, null)(block)
+ def otherwise(block: => Unit)(implicit sourceInfo: SourceInfo): Unit =
+ new WhenContext(sourceInfo, prevCond, null, block)
- pushCommand(WhenBegin(cond.ref))
+ pushCommand(WhenBegin(sourceInfo, cond.ref))
block
- pushCommand(WhenEnd())
+ pushCommand(WhenEnd(sourceInfo))
}