comparison python/testir.py @ 176:5fd02aa38b42

Added while loop code generation
author Windel Bouwman
date Sat, 20 Apr 2013 12:00:51 +0200
parents a51b3c956386
children 460db5669efa
comparison
equal deleted inserted replaced
175:a51b3c956386 176:5fd02aa38b42
34 // return y - 33; 34 // return y - 33;
35 //} 35 //}
36 36
37 if (x > 13) 37 if (x > 13)
38 { 38 {
39 res = res + 2; 39 while (y > 1337)
40 {
41 res = res + 2;
42 y = y - 12;
43 }
40 } 44 }
41 return res; 45 return res;
42 } 46 }
43 47
44 """ 48 """
56 ir.check() 60 ir.check()
57 cf.run(ir) 61 cf.run(ir)
58 dcd.run(ir) 62 dcd.run(ir)
59 m2r.run(ir) 63 m2r.run(ir)
60 #ir.dump() 64 #ir.dump()
65
66 # Dump a graphiz file:
67 with open('graaf.gv', 'w') as f:
68 ir.dumpgv(f)
69 os.system('dot -Tpdf -ograaf.pdf graaf.gv')
70
61 asm = cgenx86.genBin(ir) 71 asm = cgenx86.genBin(ir)
62 #for a in asm: 72 #for a in asm:
63 # print(a) 73 # print(a)
64 with open('out.asm', 'w') as f: 74 with open('out.asm', 'w') as f:
65 f.write('BITS 64\n') 75 f.write('BITS 64\n')
66 for a in asm: 76 for a in asm:
67 f.write(str(a) + '\n') 77 f.write(str(a) + '\n')
68
69 # Dump a graphiz file:
70 with open('graaf.gv', 'w') as f:
71 ir.dumpgv(f)
72 os.system('dot -Tpdf -ograaf.pdf graaf.gv')
73