From: Dmitry Selyutin Date: Fri, 12 Jan 2024 20:23:36 +0000 (+0300) Subject: oppc/code: support ternary conditionals X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=68f519390b665bd5906983dce68a7363e1d866f0;p=openpower-isa.git oppc/code: support ternary conditionals --- diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index 63a03eee..126125d2 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -62,6 +62,7 @@ do i = 0 to 1 result[n+8:n+19] <- DPD_TO_BCD(src[n+12:n+21]) result[n+20:n+31] <- DPD_TO_BCD(src[n+22:n+31]) RA <- result[64-XLEN:63] +RA <- (C ? A : B) if a < b then RT <- (RA) else RT <- (RB) """ diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index f014eaf1..bf16efaa 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -47,13 +47,23 @@ class CodeVisitor(pc_util.Visitor): if isinstance(node.rvalue, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.rvalue)].append(node.rvalue) + rvalue = str(self[node.rvalue]) + if isinstance(node.rvalue, pc_ast.IfExpr): + rvalue = " ".join([ + str(self[node.rvalue.test]), + "?", + str(self[node.rvalue.body[0]]), + ":", + str(self[node.rvalue.orelse[0]]), + ]) + if isinstance(node.lvalue, pc_ast.SubscriptExpr): index = str(self[node.lvalue.index]) subject = str(self[node.lvalue.subject]) args = ", ".join([ f"&{subject}", index, - str(self[node.rvalue]), + rvalue, ]) self[node].emit(f"oppc_subscript_assign({args});") elif isinstance(node.lvalue, pc_ast.RangeSubscriptExpr): @@ -64,14 +74,14 @@ class CodeVisitor(pc_util.Visitor): f"&{subject}", start, end, - str(self[node.rvalue]), + rvalue, ]) self[node].emit(f"oppc_range_subscript_assign({args});") else: stmt = " ".join([ str(self[node.lvalue]), "=", - str(self[node.rvalue]), + rvalue, ]) self[node].emit(stmt=f"{stmt};")