From 4b41a54c16242b8be434041ec70610e2338e7964 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Wed, 10 Jan 2024 23:43:59 +0300 Subject: [PATCH] oppc/code: introduce header and footer --- src/openpower/oppc/pc_code.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 24f78d17..3781d889 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -6,23 +6,27 @@ import openpower.oppc.pc_util as pc_util class CodeVisitor(pc_util.Visitor): def __init__(self, name, root): - self.__name = name - self.__code = pc_util.Code() + self.__root = root + self.__header = object() + self.__footer = object() + self.__code = collections.defaultdict(lambda: pc_util.Code()) self.__decls = collections.defaultdict(list) self.__regfetch = collections.defaultdict(list) self.__regstore = collections.defaultdict(list) super().__init__(root=root) - self.__code.emit("void") - self.__code.emit(f"oppc_{name}(void) {{") - with self.__code: + self.__code[self.__header].emit("void") + self.__code[self.__header].emit(f"oppc_{name}(void) {{") + with self.__code[self.__header]: for decl in self.__decls: - self.__code.emit(f"uint64_t {decl};") - self.__code.emit(f"}}") + self.__code[self.__header].emit(f"uint64_t {decl};") + self.__code[self.__footer].emit(f"}}") def __iter__(self): - yield from self.__code + yield from self.__code[self.__header] + yield from self.__code[self.__root] + yield from self.__code[self.__footer] @pc_util.Hook(pc_ast.AssignExpr, pc_ast.AssignIEAExpr) def AssignExpr(self, node): -- 2.30.2