diff python/testir.py @ 171:3eb9b9e2958d

Improved IR code
author Windel Bouwman
date Wed, 03 Apr 2013 22:20:20 +0200
parents
children 5a7d37d615ee
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/testir.py	Wed Apr 03 22:20:20 2013 +0200
@@ -0,0 +1,51 @@
+import c3, ppci, ir, x86
+import os
+
+testsrc = """
+package test2;
+
+function void tst()
+{
+   var int a, b;
+   a = 2 * 33 - 12;
+   b = a * 2 + 13;
+   a = b + a;
+   if (a > b and b *3 - a+8*b== 3*6-b)
+   {
+      var int x = a;
+      x = b * 2 - a;
+      a = x * x;
+   }
+   else
+   {
+      a = b + a;
+   }
+   var int y;
+   y = a - b * 53;
+}
+
+"""
+
+if __name__ == '__main__':
+   diag = ppci.DiagnosticsManager()
+   builder = c3.Builder(diag)
+   cgenx86 = x86.X86CodeGen(diag)
+   ir = builder.build(testsrc)
+   ir.check()
+   ir.analyze()
+   #ir.constantProp()
+   ir.dump()
+   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')
+
+   # Dump a graphiz file:
+   with open('graaf.gv', 'w') as f:
+      ir.dumpgv(f)
+   os.system('dot -Tpdf -ograaf.pdf graaf.gv')
+
+