Mercurial > lcfOS
comparison python/testc3.py @ 158:9683a4cd848f
Added some functions for code generation
author | Windel Bouwman |
---|---|
date | Fri, 08 Mar 2013 16:52:44 +0100 |
parents | 8f3924b6076e |
children | 10330be89bc2 |
comparison
equal
deleted
inserted
replaced
157:8f3924b6076e | 158:9683a4cd848f |
---|---|
1 import c3, time, ppci, x86 | 1 import c3 |
2 import time, ppci, x86, ir | |
2 | 3 |
3 testsrc = """ | 4 testsrc = """ |
4 package test; | 5 package test; |
5 | 6 |
6 var u32 c, d; | 7 var u32 c, d; |
60 p = c3.Parser(sema, diag) | 61 p = c3.Parser(sema, diag) |
61 tc = c3.TypeChecker(diag) | 62 tc = c3.TypeChecker(diag) |
62 al = c3.Analyzer(diag) | 63 al = c3.Analyzer(diag) |
63 cg = c3.CodeGenerator() | 64 cg = c3.CodeGenerator() |
64 x86gen = x86.X86CodeGen(diag) | 65 x86gen = x86.X86CodeGen(diag) |
65 t1 = time.time() | |
66 p.parseSource(src) | 66 p.parseSource(src) |
67 t2 = time.time() | |
68 print('parsetime: {0} [s]'.format(t2 - t1)) | |
69 t2 = time.time() | |
70 tc.checkPackage(sema.mod) | 67 tc.checkPackage(sema.mod) |
71 t3 = time.time() | |
72 print('checktime: {0} [s]'.format(t3 - t2)) | |
73 print('{0} errors'.format(len(diag.diags))) | 68 print('{0} errors'.format(len(diag.diags))) |
74 | 69 |
75 for d in diag.diags: | 70 for d in diag.diags: |
76 print('ERROR:') | 71 print('ERROR:') |
77 ppci.printError(testsrc, d) | 72 ppci.printError(testsrc, d) |
78 print('[2] ast:') | 73 print('[2] ast:') |
79 #printAst(sema.mod) | 74 #printAst(sema.mod) |
80 | 75 |
81 ok = len(diag.diags) == 0 | 76 ok = len(diag.diags) == 0 |
82 if ok: | 77 if ok: |
83 print('Generating code') | 78 print('Generating ir-code') |
84 i = cg.gencode(sema.mod) | 79 i = cg.gencode(sema.mod) |
80 #ir.printIr(i) | |
85 | 81 |
86 print(i) | 82 print('generating x86 code') |
87 print(i.Globals) | 83 |
88 x86gen.genBin(i) | 84 x86gen.genBin(i) |
85 | |
86 with open('dummydummy.asm', 'w') as f: | |
87 f.write('bits 64\n') | |
88 for a in x86gen.asm: | |
89 f.write(str(a) + '\n') | |
89 else: | 90 else: |
90 print('Not generating code') | 91 print('Not generating code') |
91 | 92 |
92 def do(): | 93 def do(): |
93 diag = ppci.DiagnosticsManager() | 94 diag = ppci.DiagnosticsManager() |