selectable_int: allow multi-level fields
authorDmitry Selyutin <ghostmansd@gmail.com>
Wed, 17 Aug 2022 20:18:12 +0000 (23:18 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Aug 2022 19:38:11 +0000 (20:38 +0100)
src/openpower/decoder/selectable_int.py

index 5a8a9b9db3e110916ca2810f4942e941c029402b..baeab54ff22e3abee9bb731bd0db36a8bff608b5 100644 (file)
@@ -24,15 +24,27 @@ class FieldSelectableInt:
     """
 
     def __init__(self, si, br):
-        if not isinstance(si, SelectableInt):
+        if not isinstance(si, (FieldSelectableInt, SelectableInt)):
             raise ValueError(si)
-        self.si = si  # target selectable int
+
         if isinstance(br, (list, tuple, range)):
             _br = BitRange()
             for i, v in enumerate(br):
                 _br[i] = v
             br = _br
-        self.br = br  # map of indices.
+
+        if isinstance(si, FieldSelectableInt):
+            fsi = si
+            if len(br) > len(fsi.br):
+                raise OverflowError(br)
+            _br = BitRange()
+            for (i, v) in br.items():
+                _br[i] = fsi.br[v]
+            br = _br
+            si = fsi.si
+
+        self.si = si  # target selectable int
+        self.br = br  # map of indices
 
     def eq(self, b):
         if isinstance(b, int):