Mercurial > lcfOS
view python/testir.py @ 184:fe2b72381a83
Added testset for pyy
author | Windel Bouwman |
---|---|
date | Fri, 24 May 2013 16:13:23 +0200 |
parents | 25a0753da4cf |
children | de3a68f677a5 |
line wrap: on
line source
import c3, ppci, ir, x86, transform import os testsrc = """ package test2; function void tesssst(int henkie) { var int a, b, cee; a = 2 * 33 - 12; b = a * 2 + 13; a = b + a; cee = a; if (a > b and b *3 - a+8*b== 3*6-b) { var int x = a; x = b * 2 - a; a = x * x * add2(x, 22 - a); } else { a = b + a + add2(a, b); } var int y; y = a - b * 53; } function int add2(int x, int y) { var int res; res = x + y + 2 - 7 + 2; //if (y < 2) //{ // return y - 33; //} res = res + (x + 2 * y) + (x + 2 * y) + (2*8) + (2*8); if (x > 13) { while (y > 1337) { res = res + 2; y = y - 12; } } return res; } """ if __name__ == '__main__': diag = ppci.DiagnosticsManager() builder = c3.Builder(diag) cgenx86 = x86.X86CodeGenSimple(diag) ir = builder.build(testsrc) diag.printErrors(testsrc) #ir.dump() cf = transform.ConstantFolder() dcd = transform.DeadCodeDeleter() m2r = transform.Mem2RegPromotor() clr = transform.CleanPass() ir.check() cf.run(ir) dcd.run(ir) clr.run(ir) m2r.run(ir) #ir.dump() # Dump a graphiz file: with open('graaf.gv', 'w') as f: ir.dumpgv(f) os.system('dot -Tpdf -ograaf.pdf graaf.gv') asm = cgenx86.genBin(ir) #for a in asm: # print(a) with open('out.asm', 'w') as f: f.write('BITS 64\n') for a in asm: f.write(str(a) + '\n') print(a)