Mercurial > lcfOS
comparison python/c3/builder.py @ 186:46d62dadd61b
Improved testsuite
author | Windel Bouwman |
---|---|
date | Sat, 25 May 2013 14:26:25 +0200 |
parents | 49f1ab80d040 |
children | b01429a5d695 |
comparison
equal
deleted
inserted
replaced
185:51a6440d6398 | 186:46d62dadd61b |
---|---|
1 import ppci | 1 import ppci |
2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter | 2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter |
3 | 3 |
4 class Builder: | 4 class Builder: |
5 def __init__(self, diag): | 5 """ |
6 Generates IR-code from c3 source. | |
7 Reports errors to the diagnostics system | |
8 """ | |
9 def __init__(self, diag): | |
6 self.diag = diag | 10 self.diag = diag |
7 self.p = Parser(diag) | 11 self.parser = Parser(diag) |
8 self.tc = TypeChecker(diag) | 12 self.tc = TypeChecker(diag) |
9 self.al = Analyzer(diag) | 13 self.al = Analyzer(diag) |
10 self.cg = CodeGenerator() | 14 self.cg = CodeGenerator() |
11 self.ap = AstPrinter() | 15 self.ap = AstPrinter() |
12 def build(self, src): | 16 def build(self, src): |
13 # Store src for later: | 17 """ Create IR-code from sources """ |
14 self.src = src | 18 pkg = self.parser.parseSource(src) |
15 self.pkg = self.p.parseSource(src) | 19 if not pkg: |
16 self.al.analyzePackage(self.pkg) | 20 return |
17 self.tc.checkPackage(self.pkg) | 21 if not self.al.analyzePackage(pkg): |
18 ok = len(self.diag.diags) == 0 | 22 return |
19 if ok: | 23 if not self.tc.checkPackage(pkg): |
20 i = self.cg.gencode(self.pkg) | 24 return |
21 return i | 25 ircode = self.cg.gencode(pkg) |
26 return ircode | |
22 | 27 |