Mercurial > lcfOS
comparison python/testc3.py @ 157:8f3924b6076e
Added some code generator things
author | Windel Bouwman |
---|---|
date | Sun, 03 Mar 2013 18:14:35 +0100 |
parents | b28a11c01dbe |
children | 9683a4cd848f |
comparison
equal
deleted
inserted
replaced
156:1b4a85bdd99c | 157:8f3924b6076e |
---|---|
1 import c3, time, ppci | 1 import c3, time, ppci, x86 |
2 | 2 |
3 testsrc = """ | 3 testsrc = """ |
4 package test; | 4 package test; |
5 | 5 |
6 var u32 c, d; | 6 var u32 c, d; |
14 var int i; | 14 var int i; |
15 i = 2; | 15 i = 2; |
16 var int zero = i - 2; | 16 var int zero = i - 2; |
17 if (i > 1) | 17 if (i > 1) |
18 { | 18 { |
19 buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - 1 | 19 buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - 1; |
20 } | 20 } |
21 else | 21 else |
22 { | 22 { |
23 ;;; | 23 ;;; |
24 }; | 24 } |
25 | 25 |
26 t2(2, 3); | 26 t2(2, 3); |
27 } | 27 } |
28 | 28 |
29 function int t2(u32 a, u32 b) | 29 function int t2(u32 a, u32 b) |
30 { | 30 { |
31 if (a > 0) | |
32 { | |
33 a = 2 + t2(a - 1); | |
34 } | |
35 | |
31 return a + b; | 36 return a + b; |
32 a = 2;// + t2(2); | |
33 } | 37 } |
34 | 38 |
35 var int hahaa = 23 * 2; | 39 var int hahaa = 23 * 2; |
36 | 40 |
37 | 41 |
55 sema = c3.Semantics(diag) | 59 sema = c3.Semantics(diag) |
56 p = c3.Parser(sema, diag) | 60 p = c3.Parser(sema, diag) |
57 tc = c3.TypeChecker(diag) | 61 tc = c3.TypeChecker(diag) |
58 al = c3.Analyzer(diag) | 62 al = c3.Analyzer(diag) |
59 cg = c3.CodeGenerator() | 63 cg = c3.CodeGenerator() |
64 x86gen = x86.X86CodeGen(diag) | |
60 t1 = time.time() | 65 t1 = time.time() |
61 p.parseSource(src) | 66 p.parseSource(src) |
62 t2 = time.time() | 67 t2 = time.time() |
63 print('parsetime: {0} [s]'.format(t2 - t1)) | 68 print('parsetime: {0} [s]'.format(t2 - t1)) |
64 t2 = time.time() | 69 t2 = time.time() |
75 | 80 |
76 ok = len(diag.diags) == 0 | 81 ok = len(diag.diags) == 0 |
77 if ok: | 82 if ok: |
78 print('Generating code') | 83 print('Generating code') |
79 i = cg.gencode(sema.mod) | 84 i = cg.gencode(sema.mod) |
85 | |
80 print(i) | 86 print(i) |
81 print(i.Globals) | 87 print(i.Globals) |
88 x86gen.genBin(i) | |
82 else: | 89 else: |
83 print('Not generating code') | 90 print('Not generating code') |
84 | 91 |
85 def do(): | 92 def do(): |
86 diag = ppci.DiagnosticsManager() | 93 diag = ppci.DiagnosticsManager() |