power_insn: allow sign only for SignedOperand
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 09:29:55 +0000 (12:29 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:16 +0000 (19:51 +0100)
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)