From: Dmitry Selyutin Date: Fri, 2 Sep 2022 21:34:29 +0000 (+0300) Subject: power_fields: allow slicing mappings X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f6611dcbd20495172522b2caf2890eca7513a23c;p=openpower-isa.git power_fields: allow slicing mappings --- diff --git a/src/openpower/decoder/power_fields.py b/src/openpower/decoder/power_fields.py index e7660d83..48cd23d4 100644 --- a/src/openpower/decoder/power_fields.py +++ b/src/openpower/decoder/power_fields.py @@ -330,6 +330,19 @@ class MappingMeta(type): length = max(length, len(field)) return length + def __getitem__(cls, selector): + best_min = 0 + best_max = 0 + for field in cls.__members__.values(): + length = len(field) + best_min = min(best_min, length) + best_max = max(best_max, length) + + items = tuple(range(best_min, best_max)) + field = FieldMeta(cls.__name__, (Field,), {}, items=items) + + return field[selector] + def remap(cls, scheme): ns = {} annotations = {}