Mercurial > lcfOS
annotate python/c3/builder.py @ 293:6aa721e7b10b
Try to improve build sequence
author | Windel Bouwman |
---|---|
date | Thu, 28 Nov 2013 20:39:37 +0100 |
parents | bd2593de3ff8 |
children | 917eab04b8b7 |
rev | line source |
---|---|
254 | 1 import logging |
165 | 2 import ppci |
215 | 3 from . import Parser, TypeChecker, Analyzer, CodeGenerator |
289 | 4 from .analyse import AddScope |
165 | 5 |
287 | 6 |
165 | 7 class Builder: |
288 | 8 """ |
186 | 9 Generates IR-code from c3 source. |
10 Reports errors to the diagnostics system | |
11 """ | |
12 def __init__(self, diag): | |
254 | 13 self.logger = logging.getLogger('c3') |
226 | 14 self.diag = diag |
15 self.parser = Parser(diag) | |
16 self.tc = TypeChecker(diag) | |
17 self.al = Analyzer(diag) | |
18 self.cg = CodeGenerator() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
226
diff
changeset
|
19 |
287 | 20 def checkSource(self, srcs, imps=[]): |
21 """ Performs syntax and type check. """ | |
293 | 22 iter(srcs) |
23 iter(imps) | |
24 def doParse(srcs): | |
25 for src in srcs: | |
288 | 26 pkg = self.parser.parseSource(src) |
293 | 27 if pkg: |
28 yield pkg | |
29 else: | |
288 | 30 self.ok = False |
293 | 31 s_pkgs = set(doParse(srcs)) |
32 print(s_pkgs) | |
33 i_pkgs = set(doParse(imps)) | |
34 all_pkgs = s_pkgs | i_pkgs | |
289 | 35 # Fix scopes: |
293 | 36 def doF(f, pkgs): |
37 for pkg in pkgs: | |
38 if f(pkg): | |
39 yield pkg | |
40 else: | |
41 self.ok = False | |
42 all_pkgs = set(doF(AddScope(self.diag).addScope, all_pkgs)) | |
289 | 43 # TODO: fix error handling better |
293 | 44 def doA(pkgs): |
45 packages = {pkg.name: pkg for pkg in pkgs} | |
46 for pkg in pkgs: | |
47 if self.al.analyzePackage(pkg, packages): | |
48 yield pkg | |
49 else: | |
50 self.ok = False | |
51 all_pkgs = set(doA(all_pkgs)) | |
52 all_pkgs = set(doF(self.tc.checkPackage, all_pkgs)) | |
53 return all_pkgs & s_pkgs | |
194 | 54 |
287 | 55 def build(self, srcs, imps=[]): |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
226
diff
changeset
|
56 """ Create IR-code from sources """ |
288 | 57 self.ok = True |
287 | 58 for pkg in self.checkSource(srcs, imps): |
288 | 59 # Only return ircode when everything is OK |
60 if self.ok: | |
61 yield self.cg.gencode(pkg) |