From: Dmitry Selyutin Date: Tue, 16 Jan 2024 19:09:45 +0000 (+0300) Subject: oppc/code: emit only function body X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9bb6b76dbb05c92c500348c914bbdceb505d354c;p=openpower-isa.git oppc/code: emit only function body --- diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index a178a65c..d490a85d 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -32,6 +32,9 @@ class Instruction(pc_ast.Node): class CodeVisitor(pc_util.Visitor): def __init__(self, insn, root): + if not isinstance(root, pc_ast.Scope): + raise ValueError(root) + self.__root = root self.__insn = insn self.__decls = set() @@ -44,11 +47,8 @@ class CodeVisitor(pc_util.Visitor): super().__init__(root=root) - self.__code[self.__header].emit(stmt="void") - self.__code[self.__header].emit(stmt=f"oppc_{insn.name}(struct oppc_value const *insn) {{") - with self.__code[self.__header]: - for decl in self.__decls: - self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};") + for decl in self.__decls: + self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};") decls = sorted(filter(lambda decl: decl in insn.fields, self.__decls)) if decls: self.__code[self.__header].emit() @@ -58,9 +58,8 @@ class CodeVisitor(pc_util.Visitor): symbol = pc_ast.Symbol(decl) assign = pc_ast.AssignExpr(lvalue=symbol, rvalue=transient) self.traverse(root=assign) - with self[self.__header]: - for (level, stmt) in self[assign]: - self[self.__header].emit(stmt=stmt, level=level) + for (level, stmt) in self[assign]: + self[self.__header].emit(stmt=stmt, level=level) for (lbit, rbit) in enumerate(insn.fields[decl]): lsymbol = pc_ast.Symbol(decl) rsymbol = Instruction() @@ -70,19 +69,17 @@ class CodeVisitor(pc_util.Visitor): rvalue = pc_ast.SubscriptExpr(index=rindex, subject=rsymbol) assign = pc_ast.AssignExpr(lvalue=lvalue, rvalue=rvalue) self.traverse(root=assign) - with self[self.__header]: - for (level, stmt) in self[assign]: - self[self.__header].emit(stmt=stmt, level=level) + for (level, stmt) in self[assign]: + self[self.__header].emit(stmt=stmt, level=level) self.__code[self.__header].emit() if decls: self.__code[self.__header].emit() - self.__code[self.__footer].emit(stmt=f"}}") - self.__code[self.__footer].emit() def __iter__(self): - yield from self.__code[self.__header] - yield from self.__code[self.__root] - yield from self.__code[self.__footer] + yield from self[self.__header] + for (level, stmt) in self[self.__root]: + yield ((level - 1), stmt) + yield from self[self.__footer] def __getitem__(self, node): return self.__code[node]