annotate python/c3/builder.py @ 226:240111e0456f

Work on named types
author Windel Bouwman
date Fri, 12 Jul 2013 17:25:31 +0200
parents 1c7364bd74c7
children 6ed3d3a82a63
rev   line source
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
1 import ppci
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
2 from . import Parser, TypeChecker, Analyzer, CodeGenerator
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 215
diff changeset
3 from . astprinter import AstPrinter
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
4
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
5 class Builder:
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
6 """
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
7 Generates IR-code from c3 source.
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
8 Reports errors to the diagnostics system
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
9 """
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
10 def __init__(self, diag):
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
11 self.diag = diag
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
12 self.parser = Parser(diag)
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
13 self.tc = TypeChecker(diag)
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
14 self.al = Analyzer(diag)
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
15 self.cg = CodeGenerator()
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
16 def build(self, src):
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
17 """ Create IR-code from sources """
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
18 pkg = self.parser.parseSource(src)
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
19 if not pkg:
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
20 return
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
21 self.pkg = pkg
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
22 # TODO: merge the two below?
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
23 #AstPrinter().printAst(pkg)
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
24 if not self.al.analyzePackage(pkg):
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
25 return
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
26 if not self.tc.checkPackage(pkg):
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
27 return
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 186
diff changeset
28
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
29 # Only return ircode when everything is OK
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
30 return self.cg.gencode(pkg)
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
31