Mercurial > lcfOS
comparison python/testc3.py @ 165:598d3888a11c
Added front class and fided AST view
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 15:12:38 +0100 |
parents | 8104fc8b5e90 |
children | da0087b82fbe |
comparison
equal
deleted
inserted
replaced
164:e023d3ce1d63 | 165:598d3888a11c |
---|---|
44 | 44 |
45 | 45 |
46 """ | 46 """ |
47 | 47 |
48 def c3compile(src, diag): | 48 def c3compile(src, diag): |
49 print('[0] source:') | |
50 print(src) | |
51 print('[1] parsing') | |
52 # Structures: | 49 # Structures: |
53 sema = c3.Semantics(diag) | 50 builder = c3.Builder(diag) |
54 p = c3.Parser(sema, diag) | 51 ir = builder.build(src) |
55 tc = c3.TypeChecker(diag) | 52 # optional optimize here |
56 al = c3.Analyzer(diag) | |
57 cg = c3.CodeGenerator() | |
58 ap = c3.AstPrinter() | |
59 | |
60 x86gen = x86.X86CodeGen(diag) | 53 x86gen = x86.X86CodeGen(diag) |
61 p.parseSource(src) | |
62 ok = len(diag.diags) == 0 | 54 ok = len(diag.diags) == 0 |
63 if not ok: | 55 if not ok: |
56 print('Not generating code') | |
64 return | 57 return |
65 al.analyzePackage(sema.mod) | 58 print('generating x86 code') |
66 tc.checkPackage(sema.mod) | 59 x86gen.genBin(ir) |
67 print('{0} errors'.format(len(diag.diags))) | 60 with open('dummydummy.asm', 'w') as f: |
68 | 61 f.write('bits 64\n') |
69 for d in diag.diags: | 62 for a in x86gen.asm: |
70 print('ERROR:') | 63 print(a) |
71 ppci.printError(testsrc, d) | 64 f.write(str(a) + '\n') |
72 print('[2] ast:') | |
73 ap.printAst(sema.mod) | |
74 | |
75 #printAst(sema.mod) | |
76 | |
77 ok = len(diag.diags) == 0 | |
78 if ok: | |
79 print('Generating ir-code') | |
80 i = cg.gencode(sema.mod) | |
81 #ir.printIr(i) | |
82 | |
83 print('generating x86 code') | |
84 | |
85 x86gen.genBin(i) | |
86 | |
87 with open('dummydummy.asm', 'w') as f: | |
88 f.write('bits 64\n') | |
89 for a in x86gen.asm: | |
90 print(a) | |
91 f.write(str(a) + '\n') | |
92 else: | |
93 print('Not generating code') | |
94 | 65 |
95 def do(): | 66 def do(): |
96 diag = ppci.DiagnosticsManager() | 67 diag = ppci.DiagnosticsManager() |
97 c3compile(testsrc, diag) | 68 c3compile(testsrc, diag) |
98 | 69 |