power_insn: support tables priorities
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)
openpower/isatables/insndb.csv
src/openpower/decoder/power_insn.py

index 80b483de35f488f271d13064e0b39d5ed79d9b5f..b8f8ad2f75ef482e88db137ec9bf5a76383966d1 100644 (file)
@@ -1,13 +1,13 @@
-path,opcode,bitsel,suffix,mode
-minor_19.csv,19,21:30,NONE,pattern
-minor_30.csv,30,27:30,NONE,pattern
-minor_31.csv,31,21:30,0b101,integer
-minor_58.csv,58,30:31,NONE,integer
-minor_62.csv,62,30:31,NONE,integer
-minor_22.csv,22,21:31,NONE,pattern
-minor_5.csv,5,21:31,NONE,pattern
-minor_4.csv,4,26:31,NONE,integer
-minor_63.csv,63,21:30,NONE,pattern
-minor_59.csv,59,21:30,NONE,pattern
-major.csv,NONE,0:5,NONE,integer
-extra.csv,NONE,0:31,NONE,pattern
+path,opcode,bitsel,suffix,mode,priority
+minor_19.csv,19,21:30,NONE,pattern,normal
+minor_30.csv,30,27:30,NONE,pattern,normal
+minor_31.csv,31,21:30,0b101,integer,normal
+minor_58.csv,58,30:31,NONE,integer,normal
+minor_62.csv,62,30:31,NONE,integer,normal
+minor_22.csv,22,21:31,NONE,pattern,normal
+minor_5.csv,5,21:31,NONE,pattern,normal
+minor_4.csv,4,26:31,NONE,integer,normal
+minor_63.csv,63,21:30,NONE,pattern,normal
+minor_59.csv,59,21:30,NONE,pattern,normal
+major.csv,NONE,0:5,NONE,integer,normal
+extra.csv,NONE,0:31,NONE,pattern,high
index cc5d0e5c3257c89e5d814201e2d520d9f0f8f387..1eabff0331040ea5aab6731b3a9459e0decd807f 100644 (file)
@@ -62,6 +62,29 @@ class Verbosity(_enum.Enum):
         return (self.value < other.value)
 
 
+@_functools.total_ordering
+class Priority(_enum.Enum):
+    LOW = -1
+    NORMAL = 0
+    HIGH = +1
+
+    @classmethod
+    def _missing_(cls, value):
+        if isinstance(value, str):
+            value = value.upper()
+        try:
+            return cls[value]
+        except ValueError:
+            return super()._missing_(value)
+
+    def __lt__(self, other):
+        if not isinstance(other, self.__class__):
+            return NotImplemented
+
+        # NOTE: the order is inversed, LOW < NORMAL < HIGH
+        return (self.value > other.value)
+
+
 def dataclass(cls, record, keymap=None, typemap=None):
     if keymap is None:
         keymap = {}
@@ -488,6 +511,12 @@ class Section:
     suffix: Suffix
     mode: Mode
     opcode: IntegerOpcode = None
+    priority: Priority = Priority.NORMAL
+
+    def __lt__(self, other):
+        if not isinstance(other, self.__class__):
+            return NotImplemented
+        return (self.priority < other.priority)
 
     @classmethod
     def CSV(cls, record):
@@ -2335,7 +2364,7 @@ class PPCDatabase:
         records = _collections.defaultdict(set)
         path = (root / "insndb.csv")
         with open(path, "r", encoding="UTF-8") as stream:
-            for section in parse(stream, Section.CSV):
+            for section in sorted(parse(stream, Section.CSV)):
                 path = (root / section.path)
                 opcode_cls = {
                     section.Mode.INTEGER: IntegerOpcode,