From: Dmitry Selyutin Date: Fri, 2 Sep 2022 16:34:11 +0000 (+0300) Subject: power_fields: allow slicing fields X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e693748e57f2af7413ec119d7474921a09d66803;p=openpower-isa.git power_fields: allow slicing fields --- diff --git a/src/openpower/decoder/power_fields.py b/src/openpower/decoder/power_fields.py index 4b7d0365..e7660d83 100644 --- a/src/openpower/decoder/power_fields.py +++ b/src/openpower/decoder/power_fields.py @@ -127,6 +127,19 @@ class FieldMeta(type): def __len__(cls): return len(cls.__members__) + def __getitem__(cls, selector): + if isinstance(selector, int): + selector = (selector,) + + items = [] + for idx in selector: + if not isinstance(idx, int): + raise ValueError(selector) + item = cls.__members__[idx] + items.append(item) + + return cls.__class__(cls.__name__, (Field,), {}, items=items) + def remap(cls, scheme): if isinstance(scheme, type) and issubclass(scheme, Mapping): scheme = range(len(scheme))