comparison python/ppci/c3/builder.py @ 301:6753763d3bec

merge codegen into ppci package
author Windel Bouwman
date Thu, 05 Dec 2013 17:02:38 +0100
parents 158068af716c
children 0615b5308710
comparison
equal deleted inserted replaced
300:158068af716c 301:6753763d3bec
1 import logging 1 import logging
2 import ppci
3 from .parser import Parser 2 from .parser import Parser
4 from .analyse import TypeChecker, Analyzer 3 from .analyse import TypeChecker, Analyzer
5 from .codegenerator import CodeGenerator 4 from .codegenerator import CodeGenerator
6 from .analyse import AddScope 5 from .analyse import AddScope
7 6
9 class Builder: 8 class Builder:
10 """ 9 """
11 Generates IR-code from c3 source. 10 Generates IR-code from c3 source.
12 Reports errors to the diagnostics system. 11 Reports errors to the diagnostics system.
13 """ 12 """
14 def __init__(self, diag): 13 def __init__(self, diag, target):
15 self.logger = logging.getLogger('c3') 14 self.logger = logging.getLogger('c3')
16 self.diag = diag 15 self.diag = diag
17 self.parser = Parser(diag) 16 self.parser = Parser(diag)
18 self.tc = TypeChecker(diag) 17 self.tc = TypeChecker(diag)
19 self.al = Analyzer(diag) 18 self.al = Analyzer(diag)
56 all_pkgs = set(doF(self.tc.checkPackage, all_pkgs)) 55 all_pkgs = set(doF(self.tc.checkPackage, all_pkgs))
57 return all_pkgs & s_pkgs 56 return all_pkgs & s_pkgs
58 57
59 def build(self, srcs, imps=[]): 58 def build(self, srcs, imps=[]):
60 """ Create IR-code from sources """ 59 """ Create IR-code from sources """
61 self.logger.info('Starting build with {}'.format(srcs)) 60 self.logger.info('Starting build with {} source files'.format(len(srcs)))
62 self.ok = True 61 self.ok = True
63 for pkg in self.checkSource(srcs, imps): 62 for pkg in self.checkSource(srcs, imps):
64 # Only return ircode when everything is OK 63 # Only return ircode when everything is OK
65 if self.ok: 64 if self.ok:
66 yield self.cg.gencode(pkg) 65 yield self.cg.gencode(pkg)