Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion amaranth/lib/enum.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import builtins
import enum as py_enum
import warnings
import operator

from ..hdl import Value, ValueCastable, Shape, ShapeCastable, Const, SyntaxWarning, Format
from ..hdl import Value, ValueCastable, Shape, ShapeCastable, Const, SyntaxWarning, Format, Array


__all__ = py_enum.__all__ + ["EnumView", "FlagView"]
Expand Down Expand Up @@ -309,6 +310,12 @@ def __ne__(self, other):
raise TypeError("an EnumView can only be compared to value or other EnumView of the same enum type")
return self.target != other.target

def __getattr__(self, name):
if (attr := getattr(self.enum, name, None)) and isinstance(attr, builtins.property):
return Array(attr.fget(self.enum(n))
for n in range(max(e.value for e in self.enum) + 1))[self.target]
raise AttributeError(f"{self!r} has no attribute {name!r}")

def __repr__(self):
return f"{type(self).__qualname__}({self.enum.__qualname__}, {self.target!r})"

Expand Down