From 5575a3f3e2809b1c096a3b84e83e73158d06e0f4 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 6 Nov 2022 12:29:55 +0300 Subject: [PATCH] power_insn: allow sign only for SignedOperand --- src/openpower/decoder/power_insn.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 5a89a7eb..2f187a6f 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -538,6 +538,8 @@ class Operand: span = tuple(map(lambda bit: (bit + 32), span)) if isinstance(value, str): value = int(value, 0) + if value < 0: + raise ValueError("signed operands not allowed") insn[span] = value def disassemble(self, insn, record, @@ -563,6 +565,11 @@ class DynamicOperand(Operand): class SignedOperand(DynamicOperand): + def assemble(self, value, insn, record): + if isinstance(value, str): + value = int(value, 0) + return super().assemble(value=value, insn=insn, record=record) + def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): span = self.span(record=record) -- 2.30.2