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

index 67d4f42feba24e743f08b1fc10b88d9ca04f6a24..78d3ce55781b2c9e309b08581425af9da5a66f35 100644 (file)
@@ -153,6 +153,21 @@ class CodeVisitor(pc_util.Visitor):
         yield node
         self[node].emit(f"ctx->XLEN")
 
+    @pc_util.Hook(pc_ast.SubscriptExpr)
+    def SubscriptExpr(self, node):
+        yield node
+        index = str(self[node.index])
+        subject = str(self[node.subject])
+        self[node].emit(f"oppc_subscript({subject}, {index})")
+
+    @pc_util.Hook(pc_ast.RangeSubscriptExpr)
+    def RangeSubscriptExpr(self, node):
+        yield node
+        start = str(self[node.start])
+        end = str(self[node.end])
+        subject = str(self[node.subject])
+        self[node].emit(f"oppc_range_subscript({subject}, {start}, {end})")
+
     @pc_util.Hook(pc_ast.Call.Name)
     def CallName(self, node):
         yield node