diff python/tcodegen.py @ 275:6f2423df0675

Fixed serve arm-as
author Windel Bouwman
date Sat, 14 Sep 2013 17:29:10 +0200
parents ea93e0a7a31e
children 9fca39eebe50
line wrap: on
line diff
--- a/python/tcodegen.py	Wed Sep 04 17:35:06 2013 +0200
+++ b/python/tcodegen.py	Sat Sep 14 17:29:10 2013 +0200
@@ -40,10 +40,11 @@
    a = b + a;
    cee = a;
    cee = cee * 2 + cee;
-   if (cee + a > b and b - a+b== 3*6-b)
+   insanemath(2, 3);
+   if (cee + a > b and b - a+b== 3*6-insanemath(b, 2))
    {
       var int x = a;
-      x = b - a + insanemath(3, 4) - insanemath(33,2);
+      x = b - a + insanemath(3, 4) - insanemath(33, insanemath(2, 0));
       a = x * (x + a);
    }
    else
@@ -55,6 +56,50 @@
 }
 """
 
+testsrc = """
+package test3;
+
+function int ab(int a, int b)
+{
+  var int c;
+  c = 0;
+  c = c + a + b;
+  return c; 
+}
+
+function void tesssst()
+{
+   var int a, b;
+   a = 2;
+   b = 3;
+   ab(ab(a, b) + ab(9,b), 0);
+}
+"""
+def dump_cfg(cga, 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)
+
+def dump_ig(cga, 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)
+
 if __name__ == '__main__':
     diag = ppci.DiagnosticsManager()
     builder = c3.Builder(diag)
@@ -70,32 +115,15 @@
     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)
+        dump_cfg(cga, 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)
+        dump_ig(cga, ig_file)
         
     for f in ir2:
         print(f)
         for i in f.instructions:
             print('   {}'.format(i))
 
+    outs.dump()
+