annotate python/c3/builder.py @ 207:8b2f20aae086

cleaning of files
author Windel Bouwman
date Sat, 29 Jun 2013 10:05:42 +0200
parents b01429a5d695
children 003c8a976fff
rev   line source
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
1 import ppci
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
3
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
4 class Builder:
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
5 """
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
6 Generates IR-code from c3 source.
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
7 Reports errors to the diagnostics system
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
8 """
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
9 def __init__(self, diag):
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
10 self.diag = diag
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
11 self.parser = Parser(diag)
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
12 self.tc = TypeChecker(diag)
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
13 self.al = Analyzer(diag)
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
14 self.cg = CodeGenerator()
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
15 self.ap = AstPrinter()
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
16 def build(self, src):
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
17 """ Create IR-code from sources """
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
18 pkg = self.parser.parseSource(src)
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 194
diff changeset
19 self.pkg = pkg
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
20 if not pkg:
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
21 return
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
22 if not self.al.analyzePackage(pkg):
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
23 return
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
24 if not self.tc.checkPackage(pkg):
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
25 return
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 186
diff changeset
26
b01429a5d695 Fixed test
Windel Bouwman
parents: 186
diff changeset
27 # Only return ircode when everything is OK
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
28 ircode = self.cg.gencode(pkg)
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 168
diff changeset
29 return ircode
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents:
diff changeset
30