chipsalliance / chipsalliance/chisel

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

Open
#1,871 2 comments 0 reactions 0 assignees View on GitHub
bug Feature feature request usability
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

Description

**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 `BitPat`s.

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

Contributor guide

Open the contributing guide

Research direction

Start by locating the ChiselEnum, asUInt, and litValue entry points, then trace how BitPat(ExampleEnum.Foo.asUInt) reaches litValue. Reproduce the None.get failure and verify that enum literals passed through asUInt expose the expected literal value without breaking the existing workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.