Mercurial > lcfOS
comparison python/testc3.py @ 155:b28a11c01dbe
Simplified IR classes
author | Windel Bouwman |
---|---|
date | Sun, 03 Mar 2013 13:20:03 +0100 |
parents | b73bc14a3aa3 |
children | 8f3924b6076e |
comparison
equal
deleted
inserted
replaced
154:81e08e2e7777 | 155:b28a11c01dbe |
---|---|
8 function void test1() | 8 function void test1() |
9 { | 9 { |
10 var u32 b; | 10 var u32 b; |
11 var int a = 10; | 11 var int a = 10; |
12 b = 20; | 12 b = 20; |
13 var int88 buf; | 13 var int buf; |
14 var int i; | 14 var int i; |
15 i = 2; | 15 i = 2; |
16 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 - one | 19 buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - 1 |
20 } | 20 } |
21 else | |
22 { | |
23 ;;; | |
24 }; | |
25 | |
26 t2(2, 3); | |
21 } | 27 } |
22 | 28 |
23 function int t2(u32 a, u32 b) | 29 function int t2(u32 a, u32 b) |
24 { | 30 { |
25 return a + b; | 31 return a + b; |
26 a = 2 | 32 a = 2;// + t2(2); |
27 } | 33 } |
28 | 34 |
29 var u8 hahaa = 23 * 2; | 35 var int hahaa = 23 * 2; |
30 | 36 |
31 function int t2(u32 a, u32 b) | |
32 { | |
33 return a + b; | |
34 a = 2 + 33 * 1 - 3; | |
35 a = a - 2 | |
36 } | |
37 | 37 |
38 """ | 38 """ |
39 | 39 |
40 def printAst(ast, indent=''): | 40 def printAst(ast, indent=''): |
41 print(indent + str(ast)) | 41 print(indent + str(ast)) |
48 for c in ast.getChildren(): | 48 for c in ast.getChildren(): |
49 printAst(c, indent + ' ') | 49 printAst(c, indent + ' ') |
50 | 50 |
51 def c3compile(src, diag): | 51 def c3compile(src, diag): |
52 print('[0] source:') | 52 print('[0] source:') |
53 print(src) | 53 #print(src) |
54 print('[1] parsing') | 54 print('[1] parsing') |
55 sema = c3.Semantics(diag) | 55 sema = c3.Semantics(diag) |
56 p = c3.Parser(sema, diag) | 56 p = c3.Parser(sema, diag) |
57 tc = c3.TypeChecker(diag) | 57 tc = c3.TypeChecker(diag) |
58 al = c3.Analyzer(diag) | 58 al = c3.Analyzer(diag) |
69 | 69 |
70 for d in diag.diags: | 70 for d in diag.diags: |
71 print('ERROR:') | 71 print('ERROR:') |
72 ppci.printError(testsrc, d) | 72 ppci.printError(testsrc, d) |
73 print('[2] ast:') | 73 print('[2] ast:') |
74 printAst(sema.mod) | 74 #printAst(sema.mod) |
75 | 75 |
76 ok = len(diag.diags) == 0 | 76 ok = len(diag.diags) == 0 |
77 if ok: | 77 if ok: |
78 cg.gencode(sema.mod) | 78 print('Generating code') |
79 i = cg.gencode(sema.mod) | |
80 print(i) | |
81 print(i.Globals) | |
79 else: | 82 else: |
80 print('Not generating code') | 83 print('Not generating code') |
81 | 84 |
82 def do(): | 85 def do(): |
83 diag = ppci.DiagnosticsManager() | 86 diag = ppci.DiagnosticsManager() |