Skip to content

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

@edwardcwang

Description

@edwardcwang

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))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions