From 9b617cbf93544ac9b1cd0c392468cb17c8a041bf Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:24:22 +0300 Subject: [PATCH] oppc/code: support binary add/sub --- src/openpower/oppc/pc_code.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 2f7e0b5d..4e985048 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -62,6 +62,24 @@ class CodeVisitor(pc_util.Visitor): self.__regfetch[str(node.left)].append(node.left) if isinstance(node.right, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.right)].append(node.left) + if isinstance(node.left, (pc_ast.GPR, pc_ast.FPR)): + left = f"oppc_reg_fetch({str(self[node.left])})" + else: + left = str(self[node.left]) + if isinstance(node.right, (pc_ast.GPR, pc_ast.FPR)): + 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)): + op = { + pc_ast.Not: "~", + pc_ast.Add: "+", + pc_ast.Sub: "-", + }[node.op.__class__] + stmt = " ".join([left, op, right]) + self[node].emit(stmt=f"({stmt})") + else: + raise ValueError(node) @pc_util.Hook(pc_ast.UnaryExpr) def UnaryExpr(self, node): -- 2.30.2