power_insn: refactor name matching algorithm
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 1 Sep 2022 12:55:39 +0000 (15:55 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 2 Sep 2022 08:57:36 +0000 (11:57 +0300)
src/openpower/decoder/power_insn.py

index 9147446d730240350fce771ccd83ca8305d2ca3a..2ab2da11275c44bb48660e9b16b5000d37bbb9bd 100644 (file)
@@ -839,14 +839,27 @@ class PPCDatabase:
         return super().__init__()
 
     def __getitem__(self, key):
+        def exact_match(key, record):
+            for name in record.names:
+                if name == key:
+                    return True
+
+            return False
+
+        def Rc_match(key, record):
+            if not key.endswith("."):
+                return False
+
+            if not record.rc is _RCOE.RC:
+                return False
+
+            return exact_match(key[:-1], record)
+
         for (section, records) in self.__db.items():
             for record in records:
-                for name in record.names:
-                    if ((key == name) or
-                            ((record.rc is _RC.RC) and
-                                key.endswith(".") and
-                                name == key[:-1])):
-                        return (section, record)
+                if (exact_match(key, record) or
+                        Rc_match(key, record)):
+                    return (section, record)
 
         return (None, None)