view python/tcodegen.py @ 272:e64bae57cda8

refactor ir
author Windel Bouwman
date Sat, 31 Aug 2013 17:58:54 +0200
parents 5f8c04a8d26b
children ea93e0a7a31e
line wrap: on
line source


"""
  Test individual parts of the code generation for arm using the c3 frontend.
"""

import c3
import ppci
import codegenarm
import outstream

testsrc = """
package test2;

var int phaa, foo, bar;

function int insanemath(int a, int b)
{
  var int c;
  c = a + b + 1;
  return c;
}

function void tesssst(int henkie)
{
   var int a, b, cee;
   a = 2 * 33 - 12;
   b = a * 2;
   a = b + a;
   cee = a;
   cee = cee * 2 + cee;
   if (cee + a > b and b - a+b== 3*6-b)
   {
      var int x = a;
      x = b - a + insanemath(3, 4);
      a = x * (x + a);
   }
   else
   {
      a = b + (a + b);
   }
   var int y;
   y = a - b * 53;
}
"""

if __name__ == '__main__':
    diag = ppci.DiagnosticsManager()
    builder = c3.Builder(diag)
    ir = builder.build(testsrc)
    ir.dump()
    outs = outstream.TextOutputStream()
    cga = codegenarm.ArmCodeGenerator(outs)
    cfg_file = open('cfg.gv', 'w')
    ig_file = open('ig.gv', 'w')
    ir2 = cga.generate(ir, cfg_file=cfg_file, ig_file=ig_file)
    cfg_file.close()
    ig_file.close()
    for i in ir2:
        print(i)