From: Dmitry Selyutin Date: Tue, 9 Jan 2024 18:29:45 +0000 (+0300) Subject: oppc: simplify ternary conditionals X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=037abe809bd7d841bbaa46130143ba31d436f47b;p=openpower-isa.git oppc: simplify ternary conditionals --- diff --git a/src/openpower/oppc/pc_pseudocode.py b/src/openpower/oppc/pc_pseudocode.py index 76058ecb..f6b5a56c 100644 --- a/src/openpower/oppc/pc_pseudocode.py +++ b/src/openpower/oppc/pc_pseudocode.py @@ -103,32 +103,22 @@ class PseudocodeVisitor(mdis.visitor.ContextVisitor): rvalue = str(self[node.rvalue]) if isinstance(node.rvalue, pc_ast.IfExpr): - # All right, this deserves an explanation. - # We basically convert T <- C ? A : B into this code: - # - # if C then - # T <- A - # else - # T <- B - # - # To make things work, we must ensure that objects are unique. - # Otherwise we'll reuse the bogus code already produced before. - (body, orelse) = map(lambda node: node.clone(), - (node.rvalue.body[0], node.rvalue.orelse[0])) - body = pc_ast.Scope([node.__class__(lvalue=node.lvalue.clone(), rvalue=body)]) - orelse = pc_ast.Scope([node.__class__(lvalue=node.lvalue.clone(), rvalue=orelse)]) - tmpnode = node.rvalue.clone(body=body, orelse=orelse) - walker = mdis.walker.Walker() - traverse(root=tmpnode, visitor=self, walker=walker) - for (level, stmt) in self[tmpnode]: - self[node].emit(stmt=stmt, level=level) + stmt = " ".join([ + lvalue, + mapping[node.__class__], + str(self[node.rvalue.test]), + "?", + str(self[node.rvalue.body[0]]), + ":", + str(self[node.rvalue.orelse[0]]), + ]) else: stmt = " ".join([ lvalue, mapping[node.__class__], rvalue, ]) - self[node].emit(stmt=stmt) + self[node].emit(stmt=stmt) @Hook(pc_ast.BinaryExpr) def BinaryExpr(self, node):