165
|
1 import ppci
|
|
2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter
|
|
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()
|
|
15 self.ap = AstPrinter()
|
186
|
16 def build(self, src):
|
|
17 """ Create IR-code from sources """
|
|
18 pkg = self.parser.parseSource(src)
|
207
|
19 self.pkg = pkg
|
186
|
20 if not pkg:
|
|
21 return
|
|
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
|