comparison python/codegen/canon.py @ 300:158068af716c

yafm
author Windel Bouwman
date Tue, 03 Dec 2013 18:00:22 +0100
parents 9417caea2eb3
children
comparison
equal deleted inserted replaced
299:674789d9ff37 300:158068af716c
24 24
25 # Visit all nodes with some function: 25 # Visit all nodes with some function:
26 # TODO: rewrite into visitor. 26 # TODO: rewrite into visitor.
27 27
28 # Rewrite rewrites call instructions into Eseq instructions. 28 # Rewrite rewrites call instructions into Eseq instructions.
29
29 30
30 def rewriteStmt(stmt, frame): 31 def rewriteStmt(stmt, frame):
31 if isinstance(stmt, ir.Jump): 32 if isinstance(stmt, ir.Jump):
32 pass 33 pass
33 elif isinstance(stmt, ir.CJump): 34 elif isinstance(stmt, ir.CJump):
97 exp.arguments = p 98 exp.arguments = p
98 return exp, sp 99 return exp, sp
99 else: 100 else:
100 raise NotImplementedError('NI: {}'.format(exp)) 101 raise NotImplementedError('NI: {}'.format(exp))
101 102
103
102 def flattenStmt(stmt): 104 def flattenStmt(stmt):
103 if isinstance(stmt, ir.Jump): 105 if isinstance(stmt, ir.Jump):
104 return [stmt] 106 return [stmt]
105 elif isinstance(stmt, ir.CJump): 107 elif isinstance(stmt, ir.CJump):
106 stmt.a, sa = flattenExp(stmt.a) 108 stmt.a, sa = flattenExp(stmt.a)
123 """ 125 """
124 Move seq instructions to top and flatten these in an instruction list 126 Move seq instructions to top and flatten these in an instruction list
125 """ 127 """
126 i = list(flattenStmt(s) for s in block.instructions) 128 i = list(flattenStmt(s) for s in block.instructions)
127 block.instructions = list(chain.from_iterable(i)) 129 block.instructions = list(chain.from_iterable(i))
128