diff options
| author | Richard Lin | 2016-06-28 10:38:25 -0700 |
|---|---|---|
| committer | GitHub | 2016-06-28 10:38:25 -0700 |
| commit | bc3813ebd752646a92987c74136bb2adb476b687 (patch) | |
| tree | cc6e0e257f57d87e828a811e8c0c85d5780bb141 /src/main/scala/chisel3/util/Enum.scala | |
| parent | 3eb51f8484ad21d8a39da1ab7b036f1bb3bbe102 (diff) | |
| parent | a367073eaad494e86883b319d3b06bd6e8f05a00 (diff) | |
Merge pull request #224 from ucb-bar/renamechisel3
renamechisel3 - "chisel" -> "chisel3"
Diffstat (limited to 'src/main/scala/chisel3/util/Enum.scala')
| -rw-r--r-- | src/main/scala/chisel3/util/Enum.scala | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/util/Enum.scala b/src/main/scala/chisel3/util/Enum.scala new file mode 100644 index 00000000..4ecc243b --- /dev/null +++ b/src/main/scala/chisel3/util/Enum.scala @@ -0,0 +1,23 @@ +// See LICENSE for license details. + +/** Enum generators, allowing circuit constants to have more meaningful names. + */ + +package chisel3.util + +import chisel3._ + +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, log2Up(n))) + + /** create n enum values of given type */ + 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 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 createValues(nodeType, l.length)).toMap +} |
