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