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