From: Dmitry Selyutin Date: Fri, 12 Jan 2024 19:24:22 +0000 (+0300) Subject: oppc/code: support bitwise operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d2c2acc85b7cb42edbd9532031db06403b125295;p=openpower-isa.git oppc/code: support bitwise operations --- 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