From: Dmitry Selyutin Date: Sat, 3 Jun 2023 10:41:42 +0000 (+0300) Subject: insndb/db: refactor classes hierarchy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5303645a13813501bae42c6a21f6141b2e58d671;p=openpower-isa.git insndb/db: refactor classes hierarchy --- diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index c66a07e7..d59595b4 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -11,31 +11,39 @@ from openpower.insndb.core import ( ) -class GenericVisitor(Visitor): +class BaseVisitor(Visitor): def __init__(self, **_): pass -class ListVisitor(GenericVisitor): +class ListVisitor(BaseVisitor): @contextlib.contextmanager def record(self, record): print(record.name) yield record -class OpcodesVisitor(GenericVisitor): +class ConcreteInstructionVisitor(BaseVisitor): def __init__(self, insn, **_): self.__insn = insn return super().__init__() + def handler(self, record): + raise NotImplementedError + @contextlib.contextmanager def record(self, record): if record.name == self.__insn: - for opcode in record.opcodes: - print(opcode) + self.handler(record=record) yield record +class OpcodesVisitor(ConcreteInstructionVisitor): + def handler(self, record): + for opcode in record.opcodes: + print(opcode) + + def main(): visitors = { "list": ListVisitor,