Mercurial > lcfOS
comparison python/ppci/codegen/canon.py @ 364:c49459768aaa
Work on globals
author | Windel Bouwman |
---|---|
date | Wed, 19 Mar 2014 20:24:03 +0100 |
parents | 5477e499b039 |
children | 988f3fb861e4 |
comparison
equal
deleted
inserted
replaced
363:396e5cefba13 | 364:c49459768aaa |
---|---|
59 elif isinstance(exp, ir.Parameter): | 59 elif isinstance(exp, ir.Parameter): |
60 return frame.parMap[exp] | 60 return frame.parMap[exp] |
61 elif isinstance(exp, ir.LocalVariable): | 61 elif isinstance(exp, ir.LocalVariable): |
62 offset = frame.allocVar(exp) | 62 offset = frame.allocVar(exp) |
63 return ir.Add(frame.fp, ir.Const(offset)) | 63 return ir.Add(frame.fp, ir.Const(offset)) |
64 elif isinstance(exp, ir.GlobalVariable): | |
65 #frame.load_global_address(ir.label_name(exp)) | |
66 return exp | |
64 elif isinstance(exp, ir.Mem): | 67 elif isinstance(exp, ir.Mem): |
65 exp.e = rewriteExp(exp.e, frame) | 68 exp.e = rewriteExp(exp.e, frame) |
66 return exp | 69 return exp |
67 elif isinstance(exp, ir.Addr): | 70 elif isinstance(exp, ir.Addr): |
68 exp.e = rewriteExp(exp.e, frame) | 71 exp.e = rewriteExp(exp.e, frame) |
72 # Rewrite call into eseq: | 75 # Rewrite call into eseq: |
73 t = newTemp() | 76 t = newTemp() |
74 return ir.Eseq(ir.Move(t, exp), t) | 77 return ir.Eseq(ir.Move(t, exp), t) |
75 else: | 78 else: |
76 raise NotImplementedError('NI: {}, {}'.format(exp, type(exp))) | 79 raise NotImplementedError('NI: {}, {}'.format(exp, type(exp))) |
77 | 80 |
78 # The flatten functions pull out seq instructions to the sequence list. | 81 # The flatten functions pull out seq instructions to the sequence list. |
79 | 82 |
80 def flattenExp(exp): | 83 def flattenExp(exp): |
81 if isinstance(exp, ir.Binop): | 84 if isinstance(exp, ir.Binop): |
82 exp.a, sa = flattenExp(exp.a) | 85 exp.a, sa = flattenExp(exp.a) |
87 elif isinstance(exp, ir.Const): | 90 elif isinstance(exp, ir.Const): |
88 return exp, [] | 91 return exp, [] |
89 elif isinstance(exp, ir.Mem): | 92 elif isinstance(exp, ir.Mem): |
90 exp.e, s = flattenExp(exp.e) | 93 exp.e, s = flattenExp(exp.e) |
91 return exp, s | 94 return exp, s |
95 elif isinstance(exp, ir.GlobalVariable): | |
96 return exp, [] | |
92 elif isinstance(exp, ir.Addr): | 97 elif isinstance(exp, ir.Addr): |
93 exp.e, s = flattenExp(exp.e) | 98 exp.e, s = flattenExp(exp.e) |
94 return exp, s | 99 return exp, s |
95 elif isinstance(exp, ir.Eseq): | 100 elif isinstance(exp, ir.Eseq): |
96 s = flattenStmt(exp.stmt) | 101 s = flattenStmt(exp.stmt) |