From 565ecc08f9631a5da68148b306e8a44dc66aa324 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sat, 17 Sep 2022 15:41:59 +0300 Subject: [PATCH] power_fields: support traversing over instances --- src/openpower/decoder/power_fields.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/openpower/decoder/power_fields.py b/src/openpower/decoder/power_fields.py index 9e4758b4..1212687a 100644 --- a/src/openpower/decoder/power_fields.py +++ b/src/openpower/decoder/power_fields.py @@ -162,9 +162,6 @@ class FieldMeta(type): def span(cls): return cls.__members__ - def traverse(cls, path): - yield (path, cls.__members__) - class Field(Reference, metaclass=FieldMeta): def __len__(self): @@ -184,6 +181,10 @@ class Field(Reference, metaclass=FieldMeta): return _selectconcat(*(self[bit] for bit in tuple(key))) + def traverse(self, path): + span = self.__class__.__members__ + yield (path, self.storage[span], span) + class MappingMeta(type): def __new__(metacls, clsname, bases, ns): @@ -255,15 +256,6 @@ class MappingMeta(type): for field in cls.__members__.values(): yield from field.span - def traverse(cls, path=""): - for (name, field) in cls: - if name == "_": - yield from field.traverse(path=path) - elif path == "": - yield from field.traverse(path=name) - else: - yield from field.traverse(path=f"{path}.{name}") - class Mapping(Reference, metaclass=MappingMeta): def __init__(self, storage, **kwargs): @@ -288,6 +280,15 @@ class Mapping(Reference, metaclass=MappingMeta): return self.__members[key] + def traverse(self, path=""): + for (name, member) in self.__members.items(): + if name == "_": + yield from member.traverse(path=path) + elif path == "": + yield from member.traverse(path=name) + else: + yield from member.traverse(path=f"{path}.{name}") + def decode_instructions(form): res = {} -- 2.30.2