def visit_CallFunc(self, node, *args, **kwargs): p1expl = P1Explicate.visit_CallFunc(self, node, *args, **kwargs) # convert the remaining CallFuncs to indirect since they are from a def or a lambda if isinstance(node.node, Name) and node.node.name == 'input_int': return p1expl #CallFunc and CallFuncIndirect: node, args, star_args = None, dstar_args = None, lineno=None # def f(x): x # a[0] = f # 4 + a[0](4) # all arguments should already be explicated at this point. return CallFuncIndirect(p1expl.node, p1expl.args, p1expl.star_args, p1expl.dstar_args, p1expl.lineno)
varname = self.varalloc.get_next_var() return (Name(varname), exprstmtlist + substmtlist + [ Assign([AssName(varname, 'OP_ASSIGN')], Subscript(exprvar, node.flags, subvar)) ]) else: return P0Flattener.flatten(self, node) if __name__ == "__main__": import compiler, sys from p0parser import P0Parser from p1explicate import P1Explicate if len(sys.argv) < 2: sys.exit(1) testcases = sys.argv[1:] for testcase in testcases: #parser = P0Parser() #parser.build() #ast = parser.parseFile(testcase) ast = compiler.parseFile(testcase) varalloc = VariableAllocator() p1explicator = P1Explicate(varalloc) ast = p1explicator.explicate(ast) p1flattener = P1Flattener(varalloc, True) stmtlist = p1flattener.flatten(ast) print stmtlist print prettyAST(stmtlist) print '\n'.join([pretty(x) for x in stmtlist.node.nodes])
def __init__(self, varalloc, handleLambdas=True): P1Explicate.__init__(self, varalloc) self.handleLambdas = handleLambdas
import sys, compiler from p0parser import P0Parser from p1explicate import P1Explicate from p1flattener import P1Flattener from p1insselector import P1InstructionSelector from p1regallocator import P1RegAllocator from p1ifinsselector import P1IfInstructionSelector if len(sys.argv) < 2: sys.exit(1) testcases = sys.argv[1:] for testcase in testcases: #parser = P0Parser() #parser.build() ast = compiler.parseFile(testcase) #ast = parser.parseFile(testcase) ast = compiler.parseFile(testcase) varalloc = VariableAllocator() explicate = P1Explicate(varalloc) ast = explicate.explicate(ast) flattener = P1Flattener(varalloc) stmtlist = flattener.flatten(ast) insselector = P1InstructionSelector(varalloc) program = insselector.visit(stmtlist) regallocator = P1RegAllocator(program, varalloc) program = regallocator.substitute() ifinsselector = P1IfInstructionSelector(varalloc, insselector.labelalloc) program = ifinsselector.visit(program) print program print prettyAST(program)