oppc/code: fix if exprs check
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Jan 2024 14:19:58 +0000 (17:19 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:07 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index de0150f44d2628c99c9a205aa9bc2fd00b78404f..28dfb34a50c1181919c1589e2887082d5c5ebdef 100644 (file)
@@ -77,9 +77,12 @@ class CodeVisitor(pc_util.Visitor):
 
     def ternary(self, node):
         self[node].clear()
+        test = self.ccall(name="oppc_bool", node=node, code=[
+            self[node.test],
+        ])
         self[node].emit(stmt="(")
         with self[node]:
-            for (level, stmt) in self[node.test]:
+            for (level, stmt) in self[test]:
                 self[node].emit(stmt=stmt, level=level)
             self[node].emit(stmt="?")
             for (level, stmt) in self[node.body]:
@@ -400,9 +403,12 @@ class CodeVisitor(pc_util.Visitor):
     @pc_util.Hook(pc_ast.IfExpr)
     def IfExpr(self, node):
         yield node
+        test = self.ccall(name="oppc_bool", node=node, code=[
+            self[node.test],
+        ])
         self[node].emit(stmt="if (")
         with self[node]:
-            for (level, stmt) in self[node.test]:
+            for (level, stmt) in self[test]:
                 self[node].emit(stmt=stmt, level=level)
         self[node].emit(stmt=") {")
         for (level, stmt) in self[node.body]: