power_insn: provide operands helpers
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 72aea8bd1617893941303e07d08915d49d0b1b59..cc5d0e5c3257c89e5d814201e2d520d9f0f8f387 100644 (file)
@@ -793,13 +793,18 @@ class Record:
     extra_idx_cr_in2 = property(lambda self: self.svp64.extra_idx_cr_in2)
     extra_idx_cr_out = property(lambda self: self.svp64.extra_idx_cr_out)
 
+    def __contains__(self, key):
+        return self.mdwn.operands.__contains__(key)
+
+    def __getitem__(self, key):
+        (cls, kwargs) = self.mdwn.operands.__getitem__(key)
+        return cls(record=self, **kwargs)
+
     @cached_property
     def Rc(self):
-        (cls, kwargs) = self.mdwn.operands["Rc"]
-        Rc = cls(record=self, **kwargs)
-        if Rc is None:
+        if "Rc" not in self:
             return False
-        return bool(Rc.value)
+        return bool(self["Rc"])
 
 
 @_dataclasses.dataclass(eq=True, frozen=True)