oppc/code: support string literals
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Jan 2024 18:23:43 +0000 (21:23 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Jan 2024 19:10:07 +0000 (22:10 +0300)
src/openpower/oppc/pc_code.py

index 107099fac84ad2302a5673f3346d8bfeafeef52e..4a2b4f759d84b2b88acf2c3e4469f3b24a7d01b3 100644 (file)
@@ -279,6 +279,12 @@ class CodeVisitor(pc_util.Visitor):
         }[node.__class__]
         self[node].emit(stmt=op)
 
+    @pc_util.Hook(pc_ast.StringLiteral)
+    def StringLiteral(self, node):
+        yield node
+        escaped = repr(str(node))[1:-1]
+        self[node].emit(stmt=f"\"{escaped}\"")
+
     @pc_util.Hook(pc_ast.BinLiteral, pc_ast.DecLiteral, pc_ast.HexLiteral)
     def Integer(self, node):
         yield node