From: Dmitry Selyutin Date: Sun, 14 Jan 2024 13:20:37 +0000 (+0300) Subject: oppc/code: align ternary if expressions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dc7fa8efed1452f6a038a5b35cdb6dc6cc087c0f;p=openpower-isa.git oppc/code: align ternary if expressions --- diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index ac68b48b..f713e55b 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -75,6 +75,20 @@ class CodeVisitor(pc_util.Visitor): self.traverse(root=ccall) return ccall + def ternary(self, node): + self[node].clear() + self[node].emit(stmt="(") + with self[node]: + for (level, stmt) in self[node.test]: + self[node].emit(stmt=stmt, level=level) + self[node].emit(stmt="?") + for (level, stmt) in self[node.body]: + self[node].emit(stmt=stmt, level=level) + self[node].emit(stmt=":") + for (level, stmt) in self[node.orelse]: + self[node].emit(stmt=stmt, level=level) + self[node].emit(stmt=")") + @contextlib.contextmanager def pseudocode(self, node): for (level, stmt) in self.__pseudocode[node]: @@ -97,33 +111,26 @@ class CodeVisitor(pc_util.Visitor): if isinstance(node.rvalue, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.rvalue)].append(node.rvalue) - rvalue = self[node.rvalue] if isinstance(node.rvalue, pc_ast.IfExpr): - rvalue = [(0, " ".join([ - str(self[node.rvalue.test]), - "?", - str(self[node.rvalue.body[0]]), - ":", - str(self[node.rvalue.orelse[0]]), - ]))] + self.ternary(node=node.rvalue) if isinstance(node.lvalue, pc_ast.SubscriptExpr): ccall = self.ccall(name="oppc_subscript_assign", node=node, stmt=True, code=[ self[node.lvalue.subject], self[node.lvalue.index], - rvalue, + self[node.rvalue], ]) elif isinstance(node.lvalue, pc_ast.RangeSubscriptExpr): ccall = self.ccall(name="oppc_range_subscript_assign", node=node, stmt=True, code=[ self[node.lvalue.subject], self[node.lvalue.start], self[node.lvalue.end], - rvalue, + self[node.rvalue], ]) else: ccall = self.ccall(name="oppc_assign", stmt=True, node=node, code=[ self[node.lvalue], - rvalue, + self[node.rvalue], ]) with self.pseudocode(node=node): for (level, stmt) in self[ccall]: