annotate test/tcodegen.py @ 322:44f336460c2a

Half of use of burg spec for arm
author Windel Bouwman
date Mon, 27 Jan 2014 19:58:07 +0100
parents 7b38782ed496
children
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
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
10 import ir
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
11
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
12 testsrc = """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
13 package test2;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
14
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
15 var int phaa, foo, bar;
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
16
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
17 function int insanemath(int a, int b)
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
18 {
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
19 var int c;
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
20 c = 0;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
21 var int i;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
22 i = 9;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
23 while (i > 1)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
24 {
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
25 c = a + b + 1 + c;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
26 i = i - 1;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
27 if (c > 90)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
28 {
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
29 return 42;
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
30 }
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
31 }
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
32 return c;
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
33 }
e64bae57cda8 refactor ir
Windel Bouwman
parents: 269
diff changeset
34
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
35 function void tesssst(int henkie)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
36 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
37 var int a, b, cee;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
38 a = 2 * 33 - 12;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
39 b = a * 2;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
40 a = b + a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
41 cee = a;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
42 cee = cee * 2 + cee;
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
43 insanemath(2, 3);
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
44 if (cee + a > b and b - a+b== 3*6-insanemath(b, 2))
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
45 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
46 var int x = a;
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
47 x = b - a + insanemath(3, 4) - insanemath(33, insanemath(2, 0));
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
48 a = x * (x + a);
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
49 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
50 else
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
51 {
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
52 a = b + (a + b);
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
53 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
54 var int y;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
55 y = a - b * 53;
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
56 }
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
57 """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
58
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
59 testsrc = """
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
60 package test3;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
61
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
62 function int ab(int a, int b)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
63 {
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
64 var int c;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
65 c = 0;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
66 c = c + a + b;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
67 return c;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
68 }
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
69
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
70 function void tesssst()
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
71 {
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
72 var int a, b;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
73 a = 2;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
74 b = 3;
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
75 ab(ab(a, b) + ab(9,b), 0);
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
76 }
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
77 """
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
78
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
79 testsrc = """
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
80 package test3;
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
81
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
82 function int ab(int a, int b)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
83 {
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
84 var int c;
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
85 var int *a2;
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
86 a2 = cast<int*>(2);
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
87 *a2 = 2;
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
88 *a2 = *a2 + 2;
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
89 c = 0;
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
90 c = c + a + b;
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
91 return c;
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
92 }
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
93
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
94 """
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
95 def dump_cfg(cga, cfg_file):
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
96 print('digraph G {', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
97 #print('edge [constraint=none]', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
98 print('rankdir=TB', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
99 for f in cga.frames:
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
100 print('subgraph cluster_{} {{'.format(f.name), file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
101 print('label={};'.format(f.name), file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
102 print('color=lightgrey;', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
103 print('style=filled;', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
104 f.cfg.to_dot(cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
105 print('}', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
106 print('}', file=cfg_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
107
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
108 def dump_ig(cga, ig_file):
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
109 print('digraph G {', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
110 print('edge [arrowhead=none]', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
111 for f in cga.frames:
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
112 print('subgraph cluster_{} {{'.format(f.name), file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
113 print('label={};'.format(f.name), file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
114 print('color=lightgrey;', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
115 print('style=filled;', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
116 f.ig.to_dot(ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
117 print('}', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
118 print('}', file=ig_file)
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
119
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
120 if __name__ == '__main__':
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
121 diag = ppci.DiagnosticsManager()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
122 builder = c3.Builder(diag)
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
123 irc = builder.build(testsrc)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
124 if not irc:
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
125 diag.printErrors(testsrc)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
126 irc.check()
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 275
diff changeset
127 #irc.dump()
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
128 with open('ir.gv', 'w') as f:
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
129 ir.dumpgv(irc, f)
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
130 outs = outstream.TextOutputStream()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
131 cga = codegenarm.ArmCodeGenerator(outs)
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
132 ir2 = cga.generate(irc)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
133
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
134 with open('cfg.gv', 'w') as cfg_file:
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
135 dump_cfg(cga, cfg_file)
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
136
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
137 with open('ig.gv', 'w') as ig_file:
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 278
diff changeset
138 dump_ig(cga, ig_file)
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 272
diff changeset
139
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
140 outs.dump()
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
141