yield from self.__code[self.__root]
yield from self.__code[self.__footer]
+ def __getitem__(self, node):
+ return self.__code[node]
+
+ @pc_util.Hook(pc_ast.Scope)
+ def Scope(self, node):
+ yield node
+ with self[node]:
+ for subnode in node:
+ for (level, stmt) in self[subnode]:
+ self[node].emit(stmt=stmt, level=level)
+
@pc_util.Hook(pc_ast.AssignExpr, pc_ast.AssignIEAExpr)
def AssignExpr(self, node):
yield node
if isinstance(node.rvalue, (pc_ast.GPR, pc_ast.FPR)):
self.__regfetch[str(node.rvalue)].append(node.rvalue)
+ if str(node.lvalue) in self.__decls:
+ stmt = " ".join([
+ str(self[node.lvalue]),
+ "=",
+ str(self[node.rvalue]),
+ ])
+ self[node].emit(stmt=f"{stmt};")
+
@pc_util.Hook(pc_ast.BinaryExpr)
def BinaryExpr(self, node):
yield node
if isinstance(node.value, (pc_ast.GPR, pc_ast.FPR)):
self.__regfetch[str(node.value)].append(node.value)
+ @pc_util.Hook(pc_ast.BinLiteral, pc_ast.DecLiteral, pc_ast.HexLiteral)
+ def Integer(self, node):
+ yield node
+ if isinstance(node, pc_ast.BinLiteral):
+ base = 2
+ elif isinstance(node, pc_ast.DecLiteral):
+ base = 10
+ elif isinstance(node, pc_ast.HexLiteral):
+ base = 16
+ else:
+ raise ValueError(node)
+ self[node].emit(stmt=f"UINT64_C({hex(int(node, base))})")
+
@pc_util.Hook(pc_ast.Call.Name)
def CallName(self, node):
yield node
def Symbol(self, node):
yield node
self.__decls[str(node)].append(node)
+ self[node].emit(stmt=str(node))
def code(name, root):