From bf208c7a6548cf6ae6ce33977a2fb8e3a463114a Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 22 Jun 2023 21:31:59 +0300 Subject: [PATCH] insndb/db: refactor extras command --- src/openpower/insndb/db.py | 54 +++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index d18df31d..4c725fee 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -1,7 +1,6 @@ import argparse import contextlib import os -import types import mdis.dispatcher import mdis.visitor @@ -15,8 +14,19 @@ from openpower.insndb.core import ( PCode, Operands, Record, + SVP64Record, Walker, ) +from openpower.decoder.power_enums import ( + SVExtra, + In1Sel, + In2Sel, + In3Sel, + OutSel, + CRInSel, + CRIn2Sel, + CROutSel, +) class Instruction(str): @@ -97,15 +107,41 @@ class PCodeVisitor(InstructionVisitor): class ExtrasVisitor(SVP64InstructionVisitor): - @mdis.dispatcher.Hook(Record) + @mdis.dispatcher.Hook( + In1Sel, In2Sel, In3Sel, CRInSel, CRIn2Sel, + OutSel, CROutSel, + ) @contextlib.contextmanager - def dispatch_record(self, node): - for (name, extra) in node.extras.items(): - print(name) - print(" sel", extra["sel"]) - print(" reg", extra["reg"]) - print(" seltype", extra["seltype"]) - print(" idx", extra["idx"]) + def dispatch_selector(self, node): + typename = node.__class__.__name__ + typename = typename.replace("CR", "CR_") + typename = typename.replace("Sel", "") + typename = typename.lower() + print(typename, node) + yield node + + @mdis.dispatcher.Hook(SVP64Record.ExtraMap) + @contextlib.contextmanager + def dispatch_extramap(self, node): + self.__index = -1 + yield node + + @mdis.dispatcher.Hook(SVP64Record.ExtraMap.Extra) + @contextlib.contextmanager + def dispatch_extramap_extra(self, node): + self.__index += 1 + yield node + + @mdis.dispatcher.Hook(SVP64Record.ExtraMap.Extra.Entry) + @contextlib.contextmanager + def dispatch_extramap_extra_entry(self, node): + idxmap = ( + SVExtra.Idx0, + SVExtra.Idx1, + SVExtra.Idx2, + SVExtra.Idx3, + ) + print(idxmap[self.__index], node) yield node -- 2.30.2