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
|
|
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
|
155
|
43 var int hahaa = 23 * 2;
|
150
|
44
|
149
|
45
|
148
|
46 """
|
|
47
|
152
|
48 def c3compile(src, diag):
|
163
|
49 # Structures:
|
165
|
50 builder = c3.Builder(diag)
|
|
51 ir = builder.build(src)
|
|
52 # optional optimize here
|
157
|
53 x86gen = x86.X86CodeGen(diag)
|
162
|
54 ok = len(diag.diags) == 0
|
|
55 if not ok:
|
165
|
56 print('Not generating code')
|
162
|
57 return
|
165
|
58 print('generating x86 code')
|
|
59 x86gen.genBin(ir)
|
|
60 with open('dummydummy.asm', 'w') as f:
|
|
61 f.write('bits 64\n')
|
|
62 for a in x86gen.asm:
|
|
63 print(a)
|
|
64 f.write(str(a) + '\n')
|
151
|
65
|
|
66 def do():
|
152
|
67 diag = ppci.DiagnosticsManager()
|
|
68 c3compile(testsrc, diag)
|
151
|
69
|
148
|
70 do()
|
|
71
|