return super().__new__(cls, value)
-class GPR(Literal, choices=("RA", "RA0", "RB", "RB0", "RC", "RC0", "RS", "RSp", "RT", "RTp")):
+class GPR(Literal, choices=("RA", "RB", "RC", "RS", "RSp", "RT", "RTp")):
+ pass
+
+
+class GPRZero(GPR, choices=("RA", "RB", "RC")):
pass
"""
if len(p) == 4:
def reg0(left, op, right):
- if (isinstance(left, (pc_ast.GPR, pc_ast.FPR)) and
+ if (isinstance(left, pc_ast.Symbol) and
isinstance(op, pc_ast.BitOr) and
- (isinstance(right, pc_ast.DecLiteral) and (str(right) == "0"))):
- if isinstance(left, pc_ast.GPR):
- return pc_ast.GPR(f"{str(left)}0")
- else:
- return pc_ast.FPR(f"{str(left)}0")
+ (isinstance(right, pc_ast.DecLiteral) and (str(right) == "0")) and
+ (str(left) in frozenset(pc_ast.GPRZero))):
+ return pc_ast.GPRZero(str(left))
return None
def repeat(left, op, right):
yield node
self[node].emit(stmt=str(node))
- @Hook(pc_ast.GPR, pc_ast.FPR)
+ @Hook(pc_ast.GPR, pc_ast.FPR, pc_ast.GPRZero)
def Reg(self, node):
yield node
- if node.endswith("0"):
- self[node].emit(stmt=f"({str(node)[:-1]}|0)")
+ if isinstance(node, pc_ast.GPRZero):
+ self[node].emit(stmt=f"({str(node)}|0)")
else:
self[node].emit(stmt=f"({str(node)})")