comparison python/testc3.py @ 151:afc8c0207984

Added ir code generator stub
author Windel Bouwman
date Fri, 01 Mar 2013 17:13:56 +0100
parents 4ae0e02599de
children b73bc14a3aa3
comparison
equal deleted inserted replaced
150:4ae0e02599de 151:afc8c0207984
48 for s in ast.scope: 48 for s in ast.scope:
49 printAst(s, indent + ' ') 49 printAst(s, indent + ' ')
50 for c in ast.getChildren(): 50 for c in ast.getChildren():
51 printAst(c, indent + ' ') 51 printAst(c, indent + ' ')
52 52
53 def do(): 53 def c3compile(src):
54 print('[0] source:') 54 print('[0] source:')
55 print(testsrc) 55 print(src)
56 print('[1] parsing') 56 print('[1] parsing')
57 diag = Diagnostics() 57 diag = Diagnostics()
58 sema = c3.Semantics(diag) 58 sema = c3.Semantics(diag)
59 p = c3.Parser(sema, diag) 59 p = c3.Parser(sema, diag)
60 tc = c3.TypeChecker(diag) 60 tc = c3.TypeChecker(diag)
61 al = c3.Analyzer(diag) 61 al = c3.Analyzer(diag)
62 cg = c3.CodeGenerator()
62 t1 = time.time() 63 t1 = time.time()
63 p.parseSource(testsrc) 64 p.parseSource(src)
64 t2 = time.time() 65 t2 = time.time()
65 print('parsetime: {0} [s]'.format(t2 - t1)) 66 print('parsetime: {0} [s]'.format(t2 - t1))
66 t2 = time.time() 67 t2 = time.time()
67 tc.checkPackage(sema.mod) 68 tc.checkPackage(sema.mod)
68 t3 = time.time() 69 t3 = time.time()
73 print('ERROR:') 74 print('ERROR:')
74 printError(testsrc, d) 75 printError(testsrc, d)
75 print('[2] ast:') 76 print('[2] ast:')
76 printAst(sema.mod) 77 printAst(sema.mod)
77 78
79 ok = len(diag.diags) == 0
80 if ok:
81 cg.gencode(sema.mod)
82 else:
83 print('Not generating code')
84
85 def do():
86 c3compile(testsrc)
87
78 do() 88 do()
79 89