oppc/code: support subscript assignments
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Jan 2024 19:47:48 +0000 (22:47 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:07 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index 78d3ce55781b2c9e309b08581425af9da5a66f35..c72059466c1f48a00cf4317bf379948cfa4ee1d4 100644 (file)
@@ -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):