Mercurial > lcfOS
annotate python/c3/builder.py @ 288:a747a45dcd78
Various styling work
author | Windel Bouwman |
---|---|
date | Thu, 21 Nov 2013 14:26:13 +0100 |
parents | 1c7c1e619be8 |
children | bd2593de3ff8 |
rev | line source |
---|---|
254 | 1 import logging |
165 | 2 import ppci |
215 | 3 from . import Parser, TypeChecker, Analyzer, CodeGenerator |
165 | 4 |
287 | 5 |
165 | 6 class Builder: |
288 | 7 """ |
186 | 8 Generates IR-code from c3 source. |
9 Reports errors to the diagnostics system | |
10 """ | |
11 def __init__(self, diag): | |
254 | 12 self.logger = logging.getLogger('c3') |
226 | 13 self.diag = diag |
14 self.parser = Parser(diag) | |
15 self.tc = TypeChecker(diag) | |
16 self.al = Analyzer(diag) | |
17 self.cg = CodeGenerator() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
226
diff
changeset
|
18 |
287 | 19 def checkSource(self, srcs, imps=[]): |
20 """ Performs syntax and type check. """ | |
288 | 21 packages = {} |
22 s_pkgs = [] | |
287 | 23 for src in srcs: |
24 pkg = self.parser.parseSource(src) | |
25 if not pkg: | |
288 | 26 self.ok = False |
27 continue | |
287 | 28 # Store for later use: |
288 | 29 packages[pkg.name] = pkg |
30 s_pkgs.append(pkg) | |
31 if imps: | |
32 for src in imps: | |
33 pkg = self.parser.parseSource(src) | |
34 if not pkg: | |
35 self.ok = False | |
36 continue | |
37 # Store for later use: | |
38 packages[pkg.name] = pkg | |
39 for pkg in packages.values(): | |
287 | 40 # TODO: merge the two below? |
288 | 41 if not self.al.analyzePackage(pkg, packages): |
42 self.ok = False | |
43 continue | |
287 | 44 if not self.tc.checkPackage(pkg): |
288 | 45 self.ok = False |
46 continue | |
47 for pkg in s_pkgs: | |
287 | 48 yield pkg |
194 | 49 |
287 | 50 def build(self, srcs, imps=[]): |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
226
diff
changeset
|
51 """ Create IR-code from sources """ |
288 | 52 self.ok = True |
287 | 53 for pkg in self.checkSource(srcs, imps): |
288 | 54 # Only return ircode when everything is OK |
55 if self.ok: | |
56 yield self.cg.gencode(pkg) |