From f4a7f0a7d71a3df8603bf42dbe72b98078246afd Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 4 Sep 2022 13:06:24 +0300 Subject: [PATCH] power_insn: refactor immediate operands --- src/openpower/decoder/power_insn.py | 46 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 83f1487a..92ebf4d0 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -456,6 +456,11 @@ class DynamicOperand(Operand): yield str(int(value)) +@_dataclasses.dataclass(eq=True, frozen=True) +class ImmediateOperand(DynamicOperand): + pass + + @_dataclasses.dataclass(eq=True, frozen=True) class StaticOperand(Operand): value: int @@ -562,23 +567,25 @@ class Operands(tuple): else: if operand.endswith(")"): operand = operand.replace("(", " ").replace(")", "") - all_operands = operand.split(" ") + (immediate, _, operand) = operand.partition(" ") else: - all_operands = [operand] + immediate = None + + if immediate is not None: + operands.append(ImmediateOperand(name=immediate)) - for operand in all_operands: - if insn in branches and operand in branches[insn]: - dynamic_cls = branches[insn][operand] + if insn in branches and operand in branches[insn]: + dynamic_cls = branches[insn][operand] - if operand in _RegType.__members__: - regtype = _RegType[operand] - if regtype is _RegType.GPR: - dynamic_cls = DynamicOperandGPR - elif regtype is _RegType.FPR: - dynamic_cls = DynamicOperandFPR + if operand in _RegType.__members__: + regtype = _RegType[operand] + if regtype is _RegType.GPR: + dynamic_cls = DynamicOperandGPR + elif regtype is _RegType.FPR: + dynamic_cls = DynamicOperandFPR - operand = dynamic_cls(name=operand) - operands.append(operand) + operand = dynamic_cls(name=operand) + operands.append(operand) return super().__new__(cls, operands) @@ -776,17 +783,28 @@ class WordInstruction(Instruction): return "".join(map(str, bits)) def spec(self, record): + immediate = "" dynamic_operands = [] for operand in record.operands.dynamic: - dynamic_operands.append(operand.name) + name = operand.name + if immediate: + name = f"{immediate}({name})" + immediate = "" + if isinstance(operand, ImmediateOperand): + immediate = operand.name + if not immediate: + dynamic_operands.append(name) + static_operands = [] for operand in record.operands.static: static_operands.append(f"{operand.name}={operand.value}") + operands = "" if dynamic_operands: operands += f" {','.join(dynamic_operands)}" if static_operands: operands += f" ({' '.join(static_operands)})" + return f"{record.name}{operands}" def opcode(self, record): -- 2.30.2