summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/Conditional.scala
diff options
context:
space:
mode:
authorJim Lawson2016-09-23 16:50:39 -0700
committerJim Lawson2016-09-23 16:50:39 -0700
commit3e174cc55be350a06e6e95ac6505a77167bd5a29 (patch)
tree01813d93be83432a7c13fed6b1f56d9b9b942ca0 /src/main/scala/chisel3/util/Conditional.scala
parent9c88d767e04ac25ab72380c39f30e39c83abf563 (diff)
parent785620b1403d827986bf60c2a001d8d6f71eed72 (diff)
Merge branch 'master' into gsdt
Diffstat (limited to 'src/main/scala/chisel3/util/Conditional.scala')
-rw-r--r--src/main/scala/chisel3/util/Conditional.scala51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/main/scala/chisel3/util/Conditional.scala b/src/main/scala/chisel3/util/Conditional.scala
index 6218feb0..5830e014 100644
--- a/src/main/scala/chisel3/util/Conditional.scala
+++ b/src/main/scala/chisel3/util/Conditional.scala
@@ -12,50 +12,71 @@ import scala.reflect.macros.blackbox._
import chisel3._
-/** This is identical to [[Chisel.when when]] with the condition inverted */
object unless { // scalastyle:ignore object.name
+ /** Does the same thing as [[when$ when]], but with the condition inverted.
+ */
def apply(c: Bool)(block: => Unit) {
when (!c) { block }
}
}
+/** Implementation details for [[switch]]. See [[switch]] and [[chisel3.util.is is]] for the
+ * user-facing API.
+ */
class SwitchContext[T <: Bits](cond: T) {
def is(v: Iterable[T])(block: => Unit) {
- if (!v.isEmpty) when (v.map(_.asUInt === cond.asUInt).reduce(_||_)) { block }
+ if (!v.isEmpty) {
+ when (v.map(_.asUInt === cond.asUInt).reduce(_||_)) {
+ block
+ }
+ }
}
def is(v: T)(block: => Unit) { is(Seq(v))(block) }
def is(v: T, vr: T*)(block: => Unit) { is(v :: vr.toList)(block) }
}
-/** An object for separate cases in [[Chisel.switch switch]]
- * It is equivalent to a [[Chisel.when$ when]] block comparing to the condition
- * Use outside of a switch statement is illegal */
+/** Use to specify cases in a [[switch]] block, equivalent to a [[when$ when]] block comparing to
+ * the condition variable.
+ *
+ * @note illegal outside a [[switch]] block
+ * @note multiple conditions may fire simultaneously
+ * @note dummy implementation, a macro inside [[switch]] transforms this into the actual
+ * implementation
+ */
object is { // scalastyle:ignore object.name
- // Begin deprecation of non-type-parameterized is statements.
+ // TODO: Begin deprecation of non-type-parameterized is statements.
+ /** Executes `block` if the switch condition is equal to any of the values in `v`.
+ */
def apply(v: Iterable[Bits])(block: => Unit) {
require(false, "The 'is' keyword may not be used outside of a switch.")
}
+ /** Executes `block` if the switch condition is equal to `v`.
+ */
def apply(v: Bits)(block: => Unit) {
require(false, "The 'is' keyword may not be used outside of a switch.")
}
+ /** Executes `block` if the switch condition is equal to any of the values in the argument list.
+ */
def apply(v: Bits, vr: Bits*)(block: => Unit) {
require(false, "The 'is' keyword may not be used outside of a switch.")
}
}
-/** Conditional logic to form a switch block
- * @example
- * {{{ ... // default values here
- * switch ( myState ) {
- * is( state1 ) {
- * ... // some logic here
+/** Conditional logic to form a switch block. See [[is$ is]] for the case API.
+ *
+ * @example {{{
+ * switch (myState) {
+ * is (state1) {
+ * // some logic here that runs when myState === state1
* }
- * is( state2 ) {
- * ... // some logic here
+ * is (state2) {
+ * // some logic here that runs when myState === state2
* }
- * } }}}*/
+ * }
+ * }}}
+ */
object switch { // scalastyle:ignore object.name
def apply[T <: Bits](cond: T)(x: => Unit): Unit = macro impl
def impl(c: Context)(cond: c.Tree)(x: c.Tree): c.Tree = { import c.universe._