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