From: Dmitry Selyutin Date: Sat, 17 Sep 2022 12:41:59 +0000 (+0300) Subject: power_fields: support traversing over instances X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=565ecc08f9631a5da68148b306e8a44dc66aa324;p=openpower-isa.git power_fields: support traversing over instances --- 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 = {}