oppc/code: support binary mul/div/mod
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 4e9850481cfa91151237d34b12662d10d0b1a728..cb7260eef7bf69a04ca2b342cae1e839f970f607 100644 (file)
@@ -70,11 +70,15 @@ class CodeVisitor(pc_util.Visitor):
             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)):
+        if isinstance(node.op, (pc_ast.Add, pc_ast.Sub,
+                pc_ast.Mul, pc_ast.Div, pc_ast.Mod)):
             op = {
                 pc_ast.Not: "~",
                 pc_ast.Add: "+",
                 pc_ast.Sub: "-",
+                pc_ast.Mul: "*",
+                pc_ast.Div: "/",
+                pc_ast.Mod: "%",
             }[node.op.__class__]
             stmt = " ".join([left, op, right])
             self[node].emit(stmt=f"({stmt})")
@@ -98,7 +102,8 @@ class CodeVisitor(pc_util.Visitor):
         else:
             raise ValueError(node)
 
-    @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub)
+    @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub,
+            pc_ast.Mul, pc_ast.Div, pc_ast.Mod)
     def Op(self, node):
         yield node