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