269
|
1
|
|
2 """
|
|
3 Test individual parts of the code generation for arm using the c3 frontend.
|
|
4 """
|
|
5
|
|
6 import c3
|
|
7 import ppci
|
|
8 import codegenarm
|
|
9 import outstream
|
274
|
10 import ir
|
269
|
11
|
|
12 testsrc = """
|
|
13 package test2;
|
|
14
|
272
|
15 var int phaa, foo, bar;
|
|
16
|
|
17 function int insanemath(int a, int b)
|
|
18 {
|
|
19 var int c;
|
274
|
20 c = 0;
|
|
21 var int i;
|
|
22 i = 9;
|
|
23 while (i > 1)
|
|
24 {
|
|
25 c = a + b + 1 + c;
|
|
26 i = i - 1;
|
|
27 if (c > 90)
|
|
28 {
|
|
29 return 42;
|
|
30 }
|
|
31 }
|
272
|
32 return c;
|
|
33 }
|
|
34
|
269
|
35 function void tesssst(int henkie)
|
|
36 {
|
|
37 var int a, b, cee;
|
|
38 a = 2 * 33 - 12;
|
|
39 b = a * 2;
|
|
40 a = b + a;
|
|
41 cee = a;
|
|
42 cee = cee * 2 + cee;
|
|
43 if (cee + a > b and b - a+b== 3*6-b)
|
|
44 {
|
|
45 var int x = a;
|
274
|
46 x = b - a + insanemath(3, 4) - insanemath(33,2);
|
269
|
47 a = x * (x + a);
|
|
48 }
|
|
49 else
|
|
50 {
|
|
51 a = b + (a + b);
|
|
52 }
|
|
53 var int y;
|
|
54 y = a - b * 53;
|
|
55 }
|
|
56 """
|
|
57
|
|
58 if __name__ == '__main__':
|
|
59 diag = ppci.DiagnosticsManager()
|
|
60 builder = c3.Builder(diag)
|
274
|
61 irc = builder.build(testsrc)
|
|
62 if not irc:
|
|
63 diag.printErrors(testsrc)
|
|
64 irc.check()
|
|
65 irc.dump()
|
|
66 with open('ir.gv', 'w') as f:
|
|
67 ir.dumpgv(irc, f)
|
269
|
68 outs = outstream.TextOutputStream()
|
|
69 cga = codegenarm.ArmCodeGenerator(outs)
|
274
|
70 ir2 = cga.generate(irc)
|
|
71
|
|
72 with open('cfg.gv', 'w') as cfg_file:
|
|
73 print('digraph G {', file=cfg_file)
|
|
74 #print('edge [constraint=none]', file=cfg_file)
|
|
75 print('rankdir=TB', file=cfg_file)
|
|
76 for f in cga.frames:
|
|
77 print('subgraph cluster_{} {{'.format(f.name), file=cfg_file)
|
|
78 print('label={};'.format(f.name), file=cfg_file)
|
|
79 print('color=lightgrey;', file=cfg_file)
|
|
80 print('style=filled;', file=cfg_file)
|
|
81 f.cfg.to_dot(cfg_file)
|
|
82 print('}', file=cfg_file)
|
|
83 print('}', file=cfg_file)
|
269
|
84
|
274
|
85 with open('ig.gv', 'w') as ig_file:
|
|
86 print('digraph G {', file=ig_file)
|
|
87 print('edge [arrowhead=none]', file=ig_file)
|
|
88 for f in cga.frames:
|
|
89 print('subgraph cluster_{} {{'.format(f.name), file=ig_file)
|
|
90 print('label={};'.format(f.name), file=ig_file)
|
|
91 print('color=lightgrey;', file=ig_file)
|
|
92 print('style=filled;', file=ig_file)
|
|
93 f.ig.to_dot(ig_file)
|
|
94 print('}', file=ig_file)
|
|
95 print('}', file=ig_file)
|
|
96
|
|
97 for f in ir2:
|
|
98 print(f)
|
|
99 for i in f.instructions:
|
|
100 print(' {}'.format(i))
|
|
101
|