oppc/code: refactor unary exprs
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:24:22 +0000 (22:24 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:24:44 +0000 (22:24 +0300)
src/openpower/oppc/pc_code.py

index 74604f45f9eedc6d22ac79ec0a36ddd86a62ab27..2f7e0b5df43e9a9c487076c8b46912ba8fb642fd 100644 (file)
@@ -67,28 +67,22 @@ class CodeVisitor(pc_util.Visitor):
     def UnaryExpr(self, node):
         yield node
         if isinstance(node.value, (pc_ast.GPR, pc_ast.FPR)):
-            self.__regfetch[str(node.value)].append(node.value)
-            stmt = "".join([
-                str(self[node.op]),
-                f"oppc_reg_fetch({str(self[node.value])})",
-            ])
+            value = f"oppc_reg_fetch({str(self[node.value])})"
         else:
-            stmt = "".join([
-                str(self[node.op]),
-                f"({str(self[node.value])})",
-            ])
-        self[node].emit(stmt=stmt)
+            value = f"({str(self[node.value])})"
+        if isinstance(node.op, (pc_ast.Not, pc_ast.Add, pc_ast.Sub)):
+            op = {
+                pc_ast.Not: "~",
+                pc_ast.Add: "+",
+                pc_ast.Sub: "-",
+            }[node.op.__class__]
+            self[node].emit(stmt="".join([op, value]))
+        else:
+            raise ValueError(node)
 
     @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub)
     def Op(self, node):
         yield node
-        mapping = {
-            pc_ast.Not: "~",
-            pc_ast.Add: "+",
-            pc_ast.Sub: "-",
-        }
-        stmt = mapping[node.__class__]
-        self[node].emit(stmt=stmt)
 
     @pc_util.Hook(pc_ast.BinLiteral, pc_ast.DecLiteral, pc_ast.HexLiteral)
     def Integer(self, node):