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)
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):
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):
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)