From d2c2acc85b7cb42edbd9532031db06403b125295 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:24:22 +0300 Subject: [PATCH] oppc/code: support bitwise operations --- src/openpower/oppc/pc_code.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 616bb6a5..b0bfaede 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -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 -- 2.30.2