diff python/testir.py @ 252:c4370696ccc7

added optimize function
author Windel Bouwman
date Tue, 30 Jul 2013 17:57:46 +0200
parents ef683881c64e
children 74c6a20302d5
line wrap: on
line diff
--- a/python/testir.py	Mon Jul 29 20:23:13 2013 +0200
+++ b/python/testir.py	Tue Jul 30 17:57:46 2013 +0200
@@ -1,4 +1,5 @@
 import unittest, os
+import sys
 import c3, ppci, ir, x86, transform
 
 class ConstantFolderTestCase(unittest.TestCase):
@@ -47,20 +48,23 @@
    b = a * 2 + 13;
    a = b + a;
    cee = a;
-   if (a > b and b *3 - a+8*b== 3*6-b)
+   cee = cee * 2 + a + cee * 2;
+   if (cee + 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);
+      a = x * x * (x + 22 - a);
    }
    else
    {
-      a = b + a + add2(a, b);
+      a = b + a + (a + b);
    }
    var int y;
    y = a - b * 53;
 }
+"""
 
+testsrc2 = """
 function int add2(int x, int y)
 {
    var int res;
@@ -86,38 +90,32 @@
 """
 
 if __name__ == '__main__':
-   #unittest.main()
-   #sys.exit()
-   diag = ppci.DiagnosticsManager()
-   builder = c3.Builder(diag)
-   cgenx86 = x86.X86CodeGenSimple(diag)
-   ir = builder.build(testsrc)
-   diag.printErrors(testsrc)
-   ir.dump()
-   ir.check()
-   cf = transform.ConstantFolder()
-   ir.check()
-   dcd = transform.DeadCodeDeleter()
-   ir.check()
-   m2r = transform.Mem2RegPromotor()
-   ir.check()
-   clr = transform.CleanPass()
-   ir.check()
-   cf.run(ir)
-   dcd.run(ir)
-   clr.run(ir)
-   m2r.run(ir)
-   #ir.dump()
+    #unittest.main()
+    #sys.exit()
+    diag = ppci.DiagnosticsManager()
+    builder = c3.Builder(diag)
+    cgenx86 = x86.X86CodeGenSimple(diag)
+    ir = builder.build(testsrc)
+    diag.printErrors(testsrc)
+    ir.check()
+    ir.dump()
+    transform.optimize(ir)
+    print('dump IR')
+    print('dump IR')
+    print('dump IR')
+    print('dump IR')
+    ir.dump()
 
-   # Dump a graphiz file:
-   with open('graaf.gv', 'w') as f:
+    # Dump a graphiz file:
+    with open('graaf.gv', 'w') as f:
       ir.dumpgv(f)
-   os.system('dot -Tpdf -ograaf.pdf graaf.gv')
+    os.system('dot -Tsvg -ograaf.svg graaf.gv')
 
-   asm = cgenx86.genBin(ir)
-   #for a in asm:
-   #   print(a)
-   with open('out.asm', 'w') as f:
+    sys.exit()
+    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')