summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kasza2020-11-16 14:21:01 -0500
committerGitHub2020-11-16 14:21:01 -0500
commit87916d55490ff04691bc59454086c82ed09646b2 (patch)
treea0f2a95adbff6016af74717bf240e810ae738606
parente6192ea75ce0d840b4b51a376921c2feecaa3b46 (diff)
Improve source locators for switch statements. (#1669)
* Improve source locators for switch statements.
-rw-r--r--src/main/scala/chisel3/util/Conditional.scala7
-rw-r--r--src/test/scala/chiselTests/SwitchSpec.scala18
2 files changed, 22 insertions, 3 deletions
diff --git a/src/main/scala/chisel3/util/Conditional.scala b/src/main/scala/chisel3/util/Conditional.scala
index ca393055..b934f27f 100644
--- a/src/main/scala/chisel3/util/Conditional.scala
+++ b/src/main/scala/chisel3/util/Conditional.scala
@@ -10,6 +10,7 @@ import scala.language.experimental.macros
import scala.reflect.macros.blackbox._
import chisel3._
+import chisel3.internal.sourceinfo.SourceInfo
@deprecated("The unless conditional is deprecated, use when(!condition){...} instead", "3.2")
object unless {
@@ -25,7 +26,7 @@ object unless {
* @note DO NOT USE. This API is subject to change without warning.
*/
class SwitchContext[T <: Element](cond: T, whenContext: Option[WhenContext], lits: Set[BigInt]) {
- def is(v: Iterable[T])(block: => Any): SwitchContext[T] = {
+ def is(v: Iterable[T])(block: => Any)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SwitchContext[T] = {
if (!v.isEmpty) {
val newLits = v.map { w =>
require(w.litOption.isDefined, "is condition must be literal")
@@ -43,8 +44,8 @@ class SwitchContext[T <: Element](cond: T, whenContext: Option[WhenContext], lit
this
}
}
- def is(v: T)(block: => Any): SwitchContext[T] = is(Seq(v))(block)
- def is(v: T, vr: T*)(block: => Any): SwitchContext[T] = is(v :: vr.toList)(block)
+ def is(v: T)(block: => Any)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SwitchContext[T] = is(Seq(v))(block)
+ def is(v: T, vr: T*)(block: => Any)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SwitchContext[T] = is(v :: vr.toList)(block)
}
/** Use to specify cases in a [[switch]] block, equivalent to a [[when$ when]] block comparing to
diff --git a/src/test/scala/chiselTests/SwitchSpec.scala b/src/test/scala/chiselTests/SwitchSpec.scala
index 78e5d59e..12bbb9e7 100644
--- a/src/test/scala/chiselTests/SwitchSpec.scala
+++ b/src/test/scala/chiselTests/SwitchSpec.scala
@@ -32,4 +32,22 @@ class SwitchSpec extends ChiselFlatSpec with Utils {
})
}
}
+ it should "provide useful source locators" in {
+ val chirrtl = ChiselStage.emitChirrtl(new Module {
+ val io = IO(new Bundle {
+ val in = Input(UInt(2.W))
+ val out = Output(UInt(2.W))
+ })
+
+ io.out := 0.U
+ switch (io.in) {
+ is (0.U) { io.out := 3.U }
+ is (1.U) { io.out := 0.U }
+ is (2.U) { io.out := 1.U }
+ is (3.U) { io.out := 3.U }
+ }
+ })
+
+ chirrtl should not include "Conditional.scala"
+ }
}