From: Dmitry Selyutin Date: Sun, 14 Jan 2024 12:56:43 +0000 (+0300) Subject: oppc/code: eliminate redundant pseudocode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8eb1751548f2259b8c15005bda15337e52af7ba8;p=openpower-isa.git oppc/code: eliminate redundant pseudocode --- diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 77bdd429..ac68b48b 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -51,10 +51,11 @@ class CodeVisitor(pc_util.Visitor): def __getitem__(self, node): return self.__code[node] - def transient(self, node, value="UINT64_C(0)", bits="(uint8_t)OPPC_XLEN"): + def transient(self, node, + value="UINT64_C(0)", + bits="(uint8_t)OPPC_XLEN"): transient = Transient(value=value, bits=bits) - with self.pseudocode(node=node): - self.traverse(root=transient) + self.traverse(root=transient) return transient def ccall(self, node, name, code, stmt=False): @@ -71,8 +72,7 @@ class CodeVisitor(pc_util.Visitor): code = tuple(map(validate, code)) ccall = CCall(name=name, code=code, stmt=stmt) - with self.pseudocode(node=node): - self.traverse(root=ccall) + self.traverse(root=ccall) return ccall @contextlib.contextmanager @@ -125,8 +125,9 @@ class CodeVisitor(pc_util.Visitor): self[node.lvalue], rvalue, ]) - for (level, stmt) in self[ccall]: - self[node].emit(stmt=stmt, level=level) + with self.pseudocode(node=node): + for (level, stmt) in self[ccall]: + self[node].emit(stmt=stmt, level=level) @pc_util.Hook(pc_ast.BinaryExpr) def BinaryExpr(self, node): @@ -153,8 +154,9 @@ class CodeVisitor(pc_util.Visitor): self[node.left], self[node.right], ]) - for (level, stmt) in self[ccall]: - self[node].emit(stmt=stmt, level=level) + with self.pseudocode(node=node): + for (level, stmt) in self[ccall]: + self[node].emit(stmt=stmt, level=level) @pc_util.Hook(pc_ast.UnaryExpr) def UnaryExpr(self, node): @@ -162,8 +164,9 @@ class CodeVisitor(pc_util.Visitor): ccall = self.ccall(name=str(self[node.op]), node=node, code=[ self[node.value], ]) - for (level, stmt) in self[ccall]: - self[node].emit(stmt=stmt, level=level) + with self.pseudocode(node=node): + for (level, stmt) in self[ccall]: + self[node].emit(stmt=stmt, level=level) @pc_util.Hook( pc_ast.Not, pc_ast.Add, pc_ast.Sub, @@ -216,8 +219,9 @@ class CodeVisitor(pc_util.Visitor): raise NotImplementedError() value = f"UINT64_C({fmt(value)})" transient = self.transient(node=node, value=value, bits=bits) - for (level, stmt) in self[transient]: - self[node].emit(stmt=stmt, level=level) + with self.pseudocode(node=node): + for (level, stmt) in self[transient]: + self[node].emit(stmt=stmt, level=level) @pc_util.Hook(Transient) def Transient(self, node): @@ -276,8 +280,9 @@ class CodeVisitor(pc_util.Visitor): yield node (value, bits) = ("OPPC_XLEN", "(uint8_t)OPPC_XLEN") transient = self.transient(node=node, value=value, bits=bits) - for (level, stmt) in self[transient]: - self[node].emit(stmt=stmt, level=level) + with self.pseudocode(node=node): + for (level, stmt) in self[transient]: + self[node].emit(stmt=stmt, level=level) @pc_util.Hook(pc_ast.SubscriptExpr) def SubscriptExpr(self, node):