oppc: check for special symbols
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 9 Jan 2024 19:48:26 +0000 (22:48 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 9 Jan 2024 19:52:15 +0000 (22:52 +0300)
src/openpower/oppc/pc_ast.py
src/openpower/oppc/pc_parser.py

index 9812107c869a4900ed1f7fc69173681bdc43f902..de77765e2fea8edb3a8318a82073afea2a2a0409 100644 (file)
@@ -145,6 +145,26 @@ class XER(Literal, choices=("OV", "OV32", "CA", "CA32", "SO")):
     pass
 
 
+class Reserve(Literal, choices=("RESERVE", "RESERVE_LENGTH", "RESERVE_ADDR")):
+    pass
+
+
+class Overflow(Literal, choices=("overflow",)):
+    pass
+
+
+class Special(Literal, choices=(
+            "CR", "LR", "CTR", "TAR", "FPSCR", "MSR",
+            "SVSTATE", "SVREMAP", "SRR0", "SRR1",
+            "SVSHAPE0", "SVSHAPE1", "SVSHAPE2", "SVSHAPE3",
+        )):
+    pass
+
+
+class XLEN(Literal, choices=("XLEN",)):
+    pass
+
+
 class IntLiteral(Literal):
     pass
 
index 33d2d8dbcd2655e8da4faa061e30aa206ae5992c..d88e67dd7eb06fe254eea5d15c090715fa0ab3d5 100644 (file)
@@ -441,7 +441,23 @@ class Parser:
         """
         atom : NAME
         """
-        p[0] = p[1]
+        # Note: GPR and FPR are handled separately.
+        specials = {frozenset(cls):cls for cls in (
+            pc_ast.CR3,
+            pc_ast.CR5,
+            pc_ast.XER,
+            pc_ast.Reserve,
+            pc_ast.Overflow,
+            pc_ast.Special,
+            pc_ast.XLEN,
+        )}
+        value = str(p[1])
+        for (variants, cls) in specials.items():
+            if value in variants:
+                p[0] = cls(value)
+                break
+        else:
+            p[0] = p[1]
 
     def p_atom_number(self, p):
         """