chisel icon indicating copy to clipboard operation
chisel copied to clipboard

ChiselEnum: cannot use .asUInt.litValue to get the litValue

Open edwardcwang opened this issue 4 years ago • 2 comments

Type of issue: bug report / feature request

Impact: API addition (no impact on existing code)

Development Phase: request

Other information:

When using ChiselEnum, one should be able to take enum literals and use asUInt followed by litValue. This pattern is notably useful when trying to turn enum literals into BitPats.

object ExampleEnum extends ChiselEnum {
  val Foo, Bar = Value
}

// Does not work since BitPat() internally calls .litValue which crashes with None.get
val simple = BitPat(ExampleEnum.Foo.asUInt)

// Instead we have to use a clumsy workaround
val complicated = BitPat(ExampleEnum.Foo.litValue.U(ExampleEnum.getWidth.W))

edwardcwang avatar Apr 21 '21 04:04 edwardcwang

This sounds like a good idea. Would you be interested in making a PR?

ekiwi avatar Apr 21 '21 15:04 ekiwi

Related to https://github.com/chipsalliance/chisel3/pull/2327

carlosedp avatar Jan 10 '22 14:01 carlosedp