oppc/code: support simple conditions
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 cb7260eef7bf69a04ca2b342cae1e839f970f607..616bb6a5888420e28291df95745daf0f73bf446f 100644 (file)
@@ -71,7 +71,11 @@ class CodeVisitor(pc_util.Visitor):
         else:
             right = str(self[node.right])
         if isinstance(node.op, (pc_ast.Add, pc_ast.Sub,
-                pc_ast.Mul, pc_ast.Div, pc_ast.Mod)):
+                    pc_ast.Mul, pc_ast.Div, pc_ast.Mod,
+                    pc_ast.Lt, pc_ast.Le,
+                    pc_ast.Eq, pc_ast.NotEq,
+                    pc_ast.Ge, pc_ast.Gt,
+                )):
             op = {
                 pc_ast.Not: "~",
                 pc_ast.Add: "+",
@@ -79,6 +83,12 @@ class CodeVisitor(pc_util.Visitor):
                 pc_ast.Mul: "*",
                 pc_ast.Div: "/",
                 pc_ast.Mod: "%",
+                pc_ast.Lt: "<",
+                pc_ast.Le: "<=",
+                pc_ast.Eq: "==",
+                pc_ast.NotEq: "!=",
+                pc_ast.Ge: ">=",
+                pc_ast.Gt: ">",
             }[node.op.__class__]
             stmt = " ".join([left, op, right])
             self[node].emit(stmt=f"({stmt})")
@@ -102,8 +112,13 @@ class CodeVisitor(pc_util.Visitor):
         else:
             raise ValueError(node)
 
-    @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub,
-            pc_ast.Mul, pc_ast.Div, pc_ast.Mod)
+    @pc_util.Hook(
+            pc_ast.Not, pc_ast.Add, pc_ast.Sub,
+            pc_ast.Mul, pc_ast.Div, pc_ast.Mod,
+            pc_ast.Lt, pc_ast.Le,
+            pc_ast.Eq, pc_ast.NotEq,
+            pc_ast.Ge, pc_ast.Gt,
+        )
     def Op(self, node):
         yield node