From 0234abbe7be1b69e28850a57f2657632fa1d2975 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 14 Jan 2024 23:48:00 +0300 Subject: [PATCH] oppc/code: fix comparisons --- src/openpower/oppc/pc_code.py | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index eba51323..170c7011 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -50,8 +50,10 @@ class CodeVisitor(pc_util.Visitor): with self.__code[self.__header]: for decl in self.__decls: self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};") - self.__code[self.__header].emit() - for decl in filter(lambda decl: decl in insn.fields, sorted(self.__decls)): + decls = sorted(filter(lambda decl: decl in insn.fields, self.__decls)) + if decls: + self.__code[self.__header].emit() + for decl in decls: bits = f"{len(insn.fields[decl])}" transient = Transient(bits=bits) symbol = pc_ast.Symbol(decl) @@ -73,7 +75,8 @@ class CodeVisitor(pc_util.Visitor): for (level, stmt) in self[assign]: self[self.__header].emit(stmt=stmt, level=level) self.__code[self.__header].emit() - self.__code[self.__header].emit() + if decls: + self.__code[self.__header].emit() self.__code[self.__footer].emit(stmt=f"}}") def __iter__(self): @@ -246,12 +249,6 @@ class CodeVisitor(pc_util.Visitor): if isinstance(node.right, (pc_ast.GPR, pc_ast.FPR)): self.__regfetch[str(node.right)].append(node.left) - comparison = ( - pc_ast.Lt, pc_ast.Le, - pc_ast.Eq, pc_ast.NotEq, - pc_ast.Ge, pc_ast.Gt, - pc_ast.LtU, pc_ast.GtU, - ) if isinstance(node.left, pc_ast.IfExpr): self.fixup_ternary(node=node.left) if isinstance(node.right, pc_ast.IfExpr): @@ -261,18 +258,21 @@ class CodeVisitor(pc_util.Visitor): if isinstance(node.right, pc_ast.Attribute): self.fixup_attr(node=node.right) + comparison = ( + pc_ast.Lt, pc_ast.Le, + pc_ast.Eq, pc_ast.NotEq, + pc_ast.Ge, pc_ast.Gt, + pc_ast.LtU, pc_ast.GtU, + ) if isinstance(node.op, comparison): - call = self.call(name=str(self[node.op]), code=[ - self[node.left], - self[node.right], - ]) + transient = self.transient(bits="UINT8_C(1)") else: transient = self.transient() - call = self.call(name=str(self[node.op]), code=[ - self[transient], - self[node.left], - self[node.right], - ]) + call = self.call(name=str(self[node.op]), code=[ + self[transient], + self[node.left], + self[node.right], + ]) with self.pseudocode(node=node): for (level, stmt) in self[call]: self[node].emit(stmt=stmt, level=level) -- 2.30.2