From c5d0d6ab03582bf78d37665f646f5661a9a3d9b4 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 12 Jan 2024 22:47:48 +0300 Subject: [PATCH] oppc/code: support subscript assignments --- src/openpower/oppc/pc_code.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 78d3ce55..c7205946 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -47,12 +47,33 @@ class CodeVisitor(pc_util.Visitor): if isinstance(node.rvalue, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.rvalue)].append(node.rvalue) - stmt = " ".join([ - str(self[node.lvalue]), - "=", - str(self[node.rvalue]), - ]) - self[node].emit(stmt=f"{stmt};") + 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]), + ]) + self[node].emit(f"oppc_subscript_assign({args});") + elif isinstance(node.lvalue, pc_ast.RangeSubscriptExpr): + start = str(self[node.lvalue.start]) + end = str(self[node.lvalue.end]) + subject = str(self[node.lvalue.subject]) + args = ", ".join([ + f"&{subject}", + start, + end, + str(self[node.rvalue]), + ]) + self[node].emit(f"oppc_range_subscript_assign({args});") + else: + stmt = " ".join([ + str(self[node.lvalue]), + "=", + str(self[node.rvalue]), + ]) + self[node].emit(stmt=f"{stmt};") @pc_util.Hook(pc_ast.BinaryExpr) def BinaryExpr(self, node): -- 2.30.2