oppc/code: support bitwise operations
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 616bb6a5888420e28291df95745daf0f73bf446f..b0bfaede9ba1a7946d1046d3ac1cb99eeaa463f1 100644 (file)
@@ -54,6 +54,8 @@ class CodeVisitor(pc_util.Visitor):
                 str(self[node.rvalue]),
             ])
             self[node].emit(stmt=f"{stmt};")
+        else:
+            raise ValueError(node)
 
     @pc_util.Hook(pc_ast.BinaryExpr)
     def BinaryExpr(self, node):
@@ -75,6 +77,8 @@ class CodeVisitor(pc_util.Visitor):
                     pc_ast.Lt, pc_ast.Le,
                     pc_ast.Eq, pc_ast.NotEq,
                     pc_ast.Ge, pc_ast.Gt,
+                    pc_ast.LShift, pc_ast.RShift,
+                    pc_ast.BitAnd, pc_ast.BitOr, pc_ast.BitXor,
                 )):
             op = {
                 pc_ast.Not: "~",
@@ -89,6 +93,11 @@ class CodeVisitor(pc_util.Visitor):
                 pc_ast.NotEq: "!=",
                 pc_ast.Ge: ">=",
                 pc_ast.Gt: ">",
+                pc_ast.LShift: "<<",
+                pc_ast.RShift: "<<",
+                pc_ast.BitAnd: "&",
+                pc_ast.BitOr: "|",
+                pc_ast.BitXor: "^",
             }[node.op.__class__]
             stmt = " ".join([left, op, right])
             self[node].emit(stmt=f"({stmt})")
@@ -118,6 +127,8 @@ class CodeVisitor(pc_util.Visitor):
             pc_ast.Lt, pc_ast.Le,
             pc_ast.Eq, pc_ast.NotEq,
             pc_ast.Ge, pc_ast.Gt,
+            pc_ast.LShift, pc_ast.RShift,
+            pc_ast.BitAnd, pc_ast.BitOr, pc_ast.BitXor,
         )
     def Op(self, node):
         yield node