power_fields: allow getting individual field bits
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 6 Sep 2022 18:26:53 +0000 (21:26 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 6 Sep 2022 19:53:05 +0000 (22:53 +0300)
src/openpower/decoder/power_fields.py

index 48cd23d45dd2f8f02fd265462a76ac1f31ff8278..fe2713d2de1f4938c1b1537f965ecf64a4a1c95a 100644 (file)
@@ -175,6 +175,13 @@ class Field(Reference, metaclass=FieldMeta):
         for bit in self.__class__:
             yield self.storage[bit]
 
+    def __getitem__(self, key):
+        if isinstance(key, int):
+            bit = self.storage[self.__class__.__members__[key]]
+            return _SelectableInt(value=bit, bits=1)
+
+        return _selectconcat(*(self[bit] for bit in tuple(key)))
+
 
 class ArrayMeta(type):
     def __new__(metacls, clsname, bases, ns, items=()):