165
|
1 import ppci
|
215
|
2 from . import Parser, TypeChecker, Analyzer, CodeGenerator
|
225
|
3 from . astprinter import AstPrinter
|
165
|
4
|
|
5 class Builder:
|
186
|
6 """
|
|
7 Generates IR-code from c3 source.
|
|
8 Reports errors to the diagnostics system
|
|
9 """
|
|
10 def __init__(self, diag):
|
226
|
11 self.diag = diag
|
|
12 self.parser = Parser(diag)
|
|
13 self.tc = TypeChecker(diag)
|
|
14 self.al = Analyzer(diag)
|
|
15 self.cg = CodeGenerator()
|
186
|
16 def build(self, src):
|
226
|
17 """ Create IR-code from sources """
|
|
18 pkg = self.parser.parseSource(src)
|
|
19 if not pkg:
|
186
|
20 return
|
226
|
21 self.pkg = pkg
|
|
22 # TODO: merge the two below?
|
|
23 #AstPrinter().printAst(pkg)
|
|
24 if not self.al.analyzePackage(pkg):
|
186
|
25 return
|
226
|
26 if not self.tc.checkPackage(pkg):
|
186
|
27 return
|
194
|
28
|
226
|
29 # Only return ircode when everything is OK
|
|
30 return self.cg.gencode(pkg)
|
165
|
31
|