oppc/code: support binary add/sub
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:24:22 +0000 (22:24 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:07 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index 2f7e0b5df43e9a9c487076c8b46912ba8fb642fd..4e9850481cfa91151237d34b12662d10d0b1a728 100644 (file)
@@ -62,6 +62,24 @@ class CodeVisitor(pc_util.Visitor):
             self.__regfetch[str(node.left)].append(node.left)
         if isinstance(node.right, (pc_ast.GPR, pc_ast.FPR)):
             self.__regfetch[str(node.right)].append(node.left)
+        if isinstance(node.left, (pc_ast.GPR, pc_ast.FPR)):
+            left = f"oppc_reg_fetch({str(self[node.left])})"
+        else:
+            left = str(self[node.left])
+        if isinstance(node.right, (pc_ast.GPR, pc_ast.FPR)):
+            right = f"oppc_reg_fetch({str(self[node.right])})"
+        else:
+            right = str(self[node.right])
+        if isinstance(node.op, (pc_ast.Add, pc_ast.Sub)):
+            op = {
+                pc_ast.Not: "~",
+                pc_ast.Add: "+",
+                pc_ast.Sub: "-",
+            }[node.op.__class__]
+            stmt = " ".join([left, op, right])
+            self[node].emit(stmt=f"({stmt})")
+        else:
+            raise ValueError(node)
 
     @pc_util.Hook(pc_ast.UnaryExpr)
     def UnaryExpr(self, node):