oppc/code: refactor declarations order
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:09:45 +0000 (22:09 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:08 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index 123d65b33d68617ac32a45200f8aec8c26823387..f6d7b908bb644e9a594a7995c5492dc0903a067c 100644 (file)
@@ -39,7 +39,7 @@ class CodeVisitor(pc_util.Visitor):
 
         self.__root = root
         self.__insn = insn
-        self.__decls = set()
+        self.__vars = set()
         self.__header = object()
         self.__footer = object()
         self.__code = collections.defaultdict(lambda: pc_util.Code())
@@ -49,11 +49,11 @@ class CodeVisitor(pc_util.Visitor):
 
         super().__init__(root=root)
 
-        for decl in (operand.name for operand in insn.dynamic_operands):
-            if decl not in self.__decls:
-                self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};")
-        for decl in sorted(self.__decls):
-            self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};")
+        operands = tuple(operand.name for operand in insn.dynamic_operands)
+        for var in operands:
+            self.__code[self.__header].emit(stmt=f"struct oppc_value {var};")
+        for var in filter(lambda var: var not in operands, sorted(self.__vars)):
+            self.__code[self.__header].emit(stmt=f"struct oppc_value {var};")
         self.__code[self.__header].emit()
 
         for operand in insn.dynamic_operands:
@@ -643,14 +643,14 @@ class CodeVisitor(pc_util.Visitor):
     def Symbol(self, node):
         yield node
         with self.pseudocode(node=node):
-            decl = str(node)
-            if decl not in ("fallthrough",):
-                if decl in ("TRAP",):
-                    self[node].emit(stmt=f"OPPC_CALL_{decl}();")
+            var = str(node)
+            if var not in ("fallthrough",):
+                if var in ("TRAP",):
+                    self[node].emit(stmt=f"OPPC_CALL_{var}();")
                 else:
                     if node in self.__pseudocode:
-                        self.__decls.add(decl)
-                    self[node].emit(stmt=f"&{decl}")
+                        self.__vars.add(var)
+                    self[node].emit(stmt=f"&{var}")
 
     @pc_util.Hook(Instruction)
     def Instruction(self, node):