From 90ac66777c5c0f2ad9a274547f24c555b60fad52 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 4 Jun 2023 12:29:46 +0300 Subject: [PATCH] insn/db: restrict extras command with SVP64 instructions --- src/openpower/insndb/db.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 5ed62157..707bdaaf 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -26,6 +26,14 @@ class Instruction(str): return self.__svp64 +class SVP64Instruction(Instruction): + def __new__(cls, string): + self = super().__new__(cls, string) + if not self.svp64: + raise ValueError("illegal SVP64 instruction") + return self + + class BaseVisitor(Visitor): def __init__(self, **_): pass @@ -53,6 +61,10 @@ class InstructionVisitor(BaseVisitor): yield record +class SVP64InstructionVisitor(InstructionVisitor): + pass + + class OpcodesVisitor(InstructionVisitor): def concrete_record(self, record): for opcode in record.opcodes: @@ -74,7 +86,7 @@ class PCodeVisitor(InstructionVisitor): print(line) -class ExtrasVisitor(InstructionVisitor): +class ExtrasVisitor(SVP64InstructionVisitor): def concrete_record(self, record): for (key, fields) in record.extras.items(): print(key) @@ -116,7 +128,11 @@ def main(): for (command, (visitor, help)) in commands.items(): parser = main_subparser.add_parser(command, help=help) if issubclass(visitor, InstructionVisitor): - parser.add_argument("insn", type=Instruction, + if issubclass(visitor, SVP64InstructionVisitor): + arg_cls = SVP64Instruction + else: + arg_cls = Instruction + parser.add_argument("insn", type=arg_cls, metavar="INSN", help="instruction") args = vars(main_parser.parse_args()) -- 2.30.2