comparison python/c3/builder.py @ 165:598d3888a11c

Added front class and fided AST view
author Windel Bouwman
date Fri, 22 Mar 2013 15:12:38 +0100
parents
children da0087b82fbe
comparison
equal deleted inserted replaced
164:e023d3ce1d63 165:598d3888a11c
1 import ppci
2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter
3
4 class Builder:
5 def __init__(self, diag):
6 self.diag = diag
7 self.sema = Semantics(diag)
8 self.p = Parser(self.sema, diag)
9 self.tc = TypeChecker(diag)
10 self.al = Analyzer(diag)
11 self.cg = CodeGenerator()
12 self.ap = AstPrinter()
13 def build(self, src):
14 # Store src for later:
15 self.src = src
16 print('[0] source:')
17 print(src)
18 print('[1] parsing')
19 self.p.parseSource(src)
20 ok = len(self.diag.diags) == 0
21 if not ok:
22 return
23 pkg = self.sema.mod
24 self.pkg = pkg
25 self.al.analyzePackage(pkg)
26 self.tc.checkPackage(pkg)
27 print('{0} errors'.format(len(self.diag.diags)))
28
29 for d in self.diag.diags:
30 print('ERROR:')
31 ppci.printError(src, d)
32 print('[2] ast:')
33 self.ap.printAst(pkg)
34
35 #printAst(sema.mod)
36
37 ok = len(self.diag.diags) == 0
38 if ok:
39 print('Generating ir-code')
40 i = cg.gencode(pkg)
41 return i
42