158
|
1 import c3
|
|
2 import time, ppci, x86, ir
|
148
|
3
|
162
|
4 testsrc = """package test;
|
148
|
5
|
149
|
6 var u32 c, d;
|
163
|
7 var double e;
|
|
8 var int f;
|
|
9
|
166
|
10 const int A = 1337.;
|
149
|
11
|
|
12 function void test1()
|
148
|
13 {
|
163
|
14 var u32 bdd;
|
148
|
15 var int a = 10;
|
163
|
16 bd = 20;
|
155
|
17 var int buf;
|
148
|
18 var int i;
|
|
19 i = 2;
|
155
|
20 var int zero = i - 2;
|
148
|
21 if (i > 1)
|
|
22 {
|
157
|
23 buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - 1;
|
148
|
24 }
|
155
|
25 else
|
|
26 {
|
|
27 ;;;
|
157
|
28 }
|
155
|
29
|
|
30 t2(2, 3);
|
148
|
31 }
|
|
32
|
149
|
33 function int t2(u32 a, u32 b)
|
148
|
34 {
|
157
|
35 if (a > 0)
|
|
36 {
|
|
37 a = 2 + t2(a - 1);
|
|
38 }
|
|
39
|
148
|
40 return a + b;
|
|
41 }
|
|
42
|
166
|
43 function int t3(int aap, int blah)
|
|
44 {
|
|
45 if (a > blah and blah < 45 + 33 or 33 > aap or 6 and true)
|
|
46 {
|
|
47 a = 2 + t2(a - 1);
|
|
48 }
|
|
49
|
|
50 return a + b;
|
|
51 }
|
|
52
|
155
|
53 var int hahaa = 23 * 2;
|
150
|
54
|
149
|
55
|
148
|
56 """
|
|
57
|
152
|
58 def c3compile(src, diag):
|
163
|
59 # Structures:
|
165
|
60 builder = c3.Builder(diag)
|
|
61 ir = builder.build(src)
|
|
62 # optional optimize here
|
157
|
63 x86gen = x86.X86CodeGen(diag)
|
162
|
64 ok = len(diag.diags) == 0
|
|
65 if not ok:
|
165
|
66 print('Not generating code')
|
162
|
67 return
|
165
|
68 print('generating x86 code')
|
|
69 x86gen.genBin(ir)
|
|
70 with open('dummydummy.asm', 'w') as f:
|
|
71 f.write('bits 64\n')
|
|
72 for a in x86gen.asm:
|
|
73 print(a)
|
|
74 f.write(str(a) + '\n')
|
151
|
75
|
|
76 def do():
|
152
|
77 diag = ppci.DiagnosticsManager()
|
|
78 c3compile(testsrc, diag)
|
151
|
79
|
148
|
80 do()
|
|
81
|