power_insn: allow sign only for SignedOperand
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 09:29:55 +0000 (12:29 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 15 Jan 2023 19:47:22 +0000 (22:47 +0300)
src/openpower/decoder/power_insn.py

index 5a89a7ebfb9f867205099a13fa0759a5757b88ae..2f187a6fa7614c02f1e7b7a8bb5cb10a89ddb517 100644 (file)
@@ -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)