diff options
| author | Andrew Waterman | 2015-10-21 15:33:58 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-10-21 15:33:58 -0700 |
| commit | d40c0009383dc8c8d9c8514478a5b406a5e789a8 (patch) | |
| tree | 2722ab57c0d38fc9c94cd4e190a4c18d7272f4d4 /src/main/scala/Chisel/Utils.scala | |
| parent | f7b496d14087c9838e3ed02413bb924f61a8d774 (diff) | |
| parent | 57c760c22177ca7e41888729d5036daf35c739ed (diff) | |
Merge pull request #28 from ucb-bar/scalastyle-rest
Scalastyle fixes involving changing code
Diffstat (limited to 'src/main/scala/Chisel/Utils.scala')
| -rw-r--r-- | src/main/scala/Chisel/Utils.scala | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/main/scala/Chisel/Utils.scala b/src/main/scala/Chisel/Utils.scala index 61bf28a8..a7a18193 100644 --- a/src/main/scala/Chisel/Utils.scala +++ b/src/main/scala/Chisel/Utils.scala @@ -9,14 +9,17 @@ import scala.reflect.runtime.universe._ import scala.reflect.macros.blackbox._ object Enum { + /** Returns a sequence of Bits subtypes with values from 0 until n. Helper method. */ + private def createValues[T <: Bits](nodeType: T, n: Int): Seq[T] = (0 until n).map(x => nodeType.fromInt(x)) + /** create n enum values of given type */ - def apply[T <: Bits](nodeType: T, n: Int): List[T] = Range(0, n).map(x => nodeType.fromInt(x)).toList + def apply[T <: Bits](nodeType: T, n: Int): List[T] = createValues(nodeType, n).toList /** create enum values of given type and names */ - def apply[T <: Bits](nodeType: T, l: Symbol *): Map[Symbol, T] = (l.toList zip (Range(0, l.length).map(x => nodeType.fromInt(x)))).toMap + def apply[T <: Bits](nodeType: T, l: Symbol *): Map[Symbol, T] = (l zip createValues(nodeType, l.length)).toMap /** create enum values of given type and names */ - def apply[T <: Bits](nodeType: T, l: List[Symbol]): Map[Symbol, T] = (l zip (Range(0, l.length).map(x => nodeType.fromInt(x)))).toMap + def apply[T <: Bits](nodeType: T, l: List[Symbol]): Map[Symbol, T] = (l zip createValues(nodeType, l.length)).toMap } /** Compute the log2 rounded up with min value of 1 */ @@ -156,9 +159,17 @@ class SwitchContext[T <: Bits](cond: T) { * It is equivalent to a [[Chisel.when$ when]] block comparing to the condition * Use outside of a switch statement is illegal */ object is { // Begin deprecation of non-type-parameterized is statements. - def apply(v: Iterable[Bits])(block: => Unit) { Builder.error("The 'is' keyword may not be used outside of a switch.") } - def apply(v: Bits)(block: => Unit) { Builder.error("The 'is' keyword may not be used outside of a switch.") } - def apply(v: Bits, vr: Bits*)(block: => Unit) { Builder.error("The 'is' keyword may not be used outside of a switch.") } + def apply(v: Iterable[Bits])(block: => Unit) { + Builder.error("The 'is' keyword may not be used outside of a switch.") + } + + def apply(v: Bits)(block: => Unit) { + Builder.error("The 'is' keyword may not be used outside of a switch.") + } + + def apply(v: Bits, vr: Bits*)(block: => Unit) { + Builder.error("The 'is' keyword may not be used outside of a switch.") + } } /** Conditional logic to form a switch block |
