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

index 69dfad8524fa4fb6c58fbb417530424e07389296..a1cd43146a113200a0bc2ad69a495c79e3e2174b 100644 (file)
@@ -189,6 +189,17 @@ class CodeVisitor(pc_util.Visitor):
         subject = str(self[node.subject])
         self[node].emit(f"oppc_range_subscript({subject}, {start}, {end})")
 
+    @pc_util.Hook(pc_ast.ForExpr)
+    def ForExpr(self, node):
+        yield node
+        subject = str(self[node.subject])
+        start = str(self[node.start])
+        end = str(self[node.end])
+        self[node].emit(f"for ({subject} = {start}; {subject} != ({end} + 1); ++{subject}) {{")
+        for (level, stmt) in self[node.body]:
+            self[node].emit(stmt=stmt, level=level)
+        self[node].emit(f"}}")
+
     @pc_util.Hook(pc_ast.Call.Name)
     def CallName(self, node):
         yield node