diff options
| author | Andrew Waterman | 2015-07-28 19:13:39 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-07-28 19:13:39 -0700 |
| commit | 874d830788721f270643aead3c09b86d2c3c7e9d (patch) | |
| tree | 45a95b27683f1de0dcc86d9da95f8a4562398a09 /src/main/scala/Chisel/Enum.scala | |
| parent | 3a8f37a211a8018f967e7a34143dd057904b2707 (diff) | |
Dead code elimination
Diffstat (limited to 'src/main/scala/Chisel/Enum.scala')
| -rw-r--r-- | src/main/scala/Chisel/Enum.scala | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main/scala/Chisel/Enum.scala b/src/main/scala/Chisel/Enum.scala index 3bc24220..8da9954d 100644 --- a/src/main/scala/Chisel/Enum.scala +++ b/src/main/scala/Chisel/Enum.scala @@ -32,13 +32,16 @@ package Chisel import Literal._ object Enum { + private def makeLit[T <: Bits](nodeType: T, i: Int, n: Int) = + nodeType.cloneType.makeLit(i, BigInt(n-1).bitLength) + /** create n enum values of given type */ - def apply[T <: Bits](nodeType: T, n: Int): List[T] = (Range(0, n, 1).map(x => (Lit(x, sizeof(n-1))(nodeType)))).toList; + def apply[T <: Bits](nodeType: T, n: Int): List[T] = Range(0, n).map(x => makeLit(nodeType, x, 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, 1).map(x => Lit(x, sizeof(l.length-1))(nodeType)))).toMap; + def apply[T <: Bits](nodeType: T, l: Symbol *): Map[Symbol, T] = (l.toList zip (Range(0, l.length).map(x => makeLit(nodeType, x, 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, 1).map(x => Lit(x, sizeof(l.length-1))(nodeType)))).toMap; + def apply[T <: Bits](nodeType: T, l: List[Symbol]): Map[Symbol, T] = (l zip (Range(0, l.length).map(x => makeLit(nodeType, x, l.length)))).toMap } |
