Mercurial > lcfOS
view python/tcodegen.py @ 274:ea93e0a7a31e
Move docs
author | Windel Bouwman |
---|---|
date | Wed, 04 Sep 2013 17:35:06 +0200 |
parents | e64bae57cda8 |
children | 6f2423df0675 |
line wrap: on
line source
""" Test individual parts of the code generation for arm using the c3 frontend. """ import c3 import ppci import codegenarm import outstream import ir testsrc = """ package test2; var int phaa, foo, bar; function int insanemath(int a, int b) { var int c; c = 0; var int i; i = 9; while (i > 1) { c = a + b + 1 + c; i = i - 1; if (c > 90) { return 42; } } return c; } function void tesssst(int henkie) { var int a, b, cee; a = 2 * 33 - 12; b = a * 2; a = b + a; cee = a; cee = cee * 2 + cee; if (cee + a > b and b - a+b== 3*6-b) { var int x = a; x = b - a + insanemath(3, 4) - insanemath(33,2); a = x * (x + a); } else { a = b + (a + b); } var int y; y = a - b * 53; } """ if __name__ == '__main__': diag = ppci.DiagnosticsManager() builder = c3.Builder(diag) irc = builder.build(testsrc) if not irc: diag.printErrors(testsrc) irc.check() irc.dump() with open('ir.gv', 'w') as f: ir.dumpgv(irc, f) outs = outstream.TextOutputStream() cga = codegenarm.ArmCodeGenerator(outs) ir2 = cga.generate(irc) with open('cfg.gv', 'w') as cfg_file: print('digraph G {', file=cfg_file) #print('edge [constraint=none]', file=cfg_file) print('rankdir=TB', file=cfg_file) for f in cga.frames: print('subgraph cluster_{} {{'.format(f.name), file=cfg_file) print('label={};'.format(f.name), file=cfg_file) print('color=lightgrey;', file=cfg_file) print('style=filled;', file=cfg_file) f.cfg.to_dot(cfg_file) print('}', file=cfg_file) print('}', file=cfg_file) with open('ig.gv', 'w') as ig_file: print('digraph G {', file=ig_file) print('edge [arrowhead=none]', file=ig_file) for f in cga.frames: print('subgraph cluster_{} {{'.format(f.name), file=ig_file) print('label={};'.format(f.name), file=ig_file) print('color=lightgrey;', file=ig_file) print('style=filled;', file=ig_file) f.ig.to_dot(ig_file) print('}', file=ig_file) print('}', file=ig_file) for f in ir2: print(f) for i in f.instructions: print(' {}'.format(i))