From 5ac100524978ede331298792b7a69e2406ec4a32 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Mon, 8 Jan 2024 15:48:13 +0300 Subject: [PATCH] oppc: introduce GPRZero class --- src/openpower/oppc/pc_ast.py | 6 +++++- src/openpower/oppc/pc_parser.py | 10 ++++------ src/openpower/oppc/pc_util.py | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/openpower/oppc/pc_ast.py b/src/openpower/oppc/pc_ast.py index 0a51e62f..5a8d0a06 100644 --- a/src/openpower/oppc/pc_ast.py +++ b/src/openpower/oppc/pc_ast.py @@ -125,7 +125,11 @@ class Literal(Token, metaclass=LiteralMeta): 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 diff --git a/src/openpower/oppc/pc_parser.py b/src/openpower/oppc/pc_parser.py index aa8cd1c7..596830ed 100644 --- a/src/openpower/oppc/pc_parser.py +++ b/src/openpower/oppc/pc_parser.py @@ -377,13 +377,11 @@ class Parser: """ 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): diff --git a/src/openpower/oppc/pc_util.py b/src/openpower/oppc/pc_util.py index 7ab38929..183f6feb 100644 --- a/src/openpower/oppc/pc_util.py +++ b/src/openpower/oppc/pc_util.py @@ -379,11 +379,11 @@ class PseudocodeVisitor(mdis.visitor.ContextVisitor): 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)})") -- 2.30.2