From f87478729f8d17f558ac9ca0bea2935176a7bf7a Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 4 Jun 2023 13:27:31 +0300 Subject: [PATCH] insn/core: introduce visitable extra --- src/openpower/insndb/core.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 13f3a62f..859852b9 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -9,6 +9,7 @@ import operator as _operator import pathlib as _pathlib import re as _re import types as _types +import typing as _typing try: from functools import cached_property @@ -64,6 +65,10 @@ class Visitor: def record(self, record): yield record + @_contextlib.contextmanager + def extra(self, extra): + yield extra + @_functools.total_ordering class Style(_enum.Enum): @@ -818,6 +823,23 @@ class MarkdownRecord: operands: Operands +@_dataclasses.dataclass(eq=True, frozen=True) +class VisitableExtra: + name: str + sel: _typing.Union[ + _In1Sel, _In2Sel, _In3Sel, _CRInSel, _CRIn2Sel, + _OutSel, _CROutSel, + ] + reg: _Reg + seltype: _SelType + idx: _SVExtra + + def visit(self, visitor): + with visitor.extra(extra=self) as extra: + pass + + + @_functools.total_ordering @_dataclasses.dataclass(eq=True, frozen=True) class Record: @@ -830,11 +852,16 @@ class Record: def visit(self, visitor): with visitor.record(record=self) as record: - pass + for (name, fields) in record.extras.items(): + extra = VisitableExtra(name=name, **fields) + extra.visit(visitor=visitor) @property def extras(self): - return self.svp64.extras + if self.svp64 is not None: + return self.svp64.extras + else: + return _types.MappingProxyType({}) @property def pcode(self): -- 2.30.2