annotate python/tcodegen.py @ 269:5f8c04a8d26b

Towards better modularity
author Windel Bouwman
date Sun, 18 Aug 2013 17:43:18 +0200
parents
children e64bae57cda8
rev   line source
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
1
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
2 """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
3 Test individual parts of the code generation for arm using the c3 frontend.
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
4 """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
5
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
6 import c3
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
7 import ppci
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
8 import codegenarm
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
9 import outstream
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
10
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
11 testsrc = """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
12 package test2;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
13
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
14 function void tesssst(int henkie)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
15 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
16 var int a, b, cee;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
17 a = 2 * 33 - 12;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
18 b = a * 2;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
19 a = b + a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
20 cee = a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
21 cee = cee * 2 + cee;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
22 if (cee + a > b and b - a+b== 3*6-b)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
23 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
24 var int x = a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
25 x = b - a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
26 a = x * (x + a);
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
27 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
28 else
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
29 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
30 a = b + (a + b);
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
31 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
32 var int y;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
33 y = a - b * 53;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
34 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
35 """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
36
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
37 if __name__ == '__main__':
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
38 diag = ppci.DiagnosticsManager()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
39 builder = c3.Builder(diag)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
40 ir = builder.build(testsrc)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
41 ir.dump()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
42 outs = outstream.TextOutputStream()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
43 cga = codegenarm.ArmCodeGenerator(outs)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
44 cfg_file = open('cfg.gv', 'w')
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
45 ig_file = open('ig.gv', 'w')
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
46 cga.generate(ir, cfg_file=cfg_file, ig_file=ig_file)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
47 cfg_file.close()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
48 ig_file.close()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
49