From defb275d8948332dfc6ad8b9e1367cdaa89d7a6c Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:24:22 +0300 Subject: [PATCH] oppc/code: refactor unary exprs --- src/openpower/oppc/pc_code.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 74604f45..2f7e0b5d 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -67,28 +67,22 @@ class CodeVisitor(pc_util.Visitor): def UnaryExpr(self, node): yield node if isinstance(node.value, (pc_ast.GPR, pc_ast.FPR)): - self.__regfetch[str(node.value)].append(node.value) - stmt = "".join([ - str(self[node.op]), - f"oppc_reg_fetch({str(self[node.value])})", - ]) + value = f"oppc_reg_fetch({str(self[node.value])})" else: - stmt = "".join([ - str(self[node.op]), - f"({str(self[node.value])})", - ]) - self[node].emit(stmt=stmt) + value = f"({str(self[node.value])})" + if isinstance(node.op, (pc_ast.Not, pc_ast.Add, pc_ast.Sub)): + op = { + pc_ast.Not: "~", + pc_ast.Add: "+", + pc_ast.Sub: "-", + }[node.op.__class__] + self[node].emit(stmt="".join([op, value])) + else: + raise ValueError(node) @pc_util.Hook(pc_ast.Not, pc_ast.Add, pc_ast.Sub) def Op(self, node): yield node - mapping = { - pc_ast.Not: "~", - pc_ast.Add: "+", - pc_ast.Sub: "-", - } - stmt = mapping[node.__class__] - self[node].emit(stmt=stmt) @pc_util.Hook(pc_ast.BinLiteral, pc_ast.DecLiteral, pc_ast.HexLiteral) def Integer(self, node): -- 2.30.2