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)
|
|
19 if not pkg:
|
|
20 return
|
|
21 if not self.al.analyzePackage(pkg):
|
|
22 return
|
|
23 if not self.tc.checkPackage(pkg):
|
|
24 return
|
194
|
25
|
|
26 # Only return ircode when everything is OK
|
186
|
27 ircode = self.cg.gencode(pkg)
|
|
28 return ircode
|
165
|
29
|