Mercurial > lcfOS
diff python/c3/builder.py @ 165:598d3888a11c
Added front class and fided AST view
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 15:12:38 +0100 |
parents | |
children | da0087b82fbe |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/c3/builder.py Fri Mar 22 15:12:38 2013 +0100 @@ -0,0 +1,42 @@ +import ppci +from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter + +class Builder: + def __init__(self, diag): + self.diag = diag + self.sema = Semantics(diag) + self.p = Parser(self.sema, diag) + self.tc = TypeChecker(diag) + self.al = Analyzer(diag) + self.cg = CodeGenerator() + self.ap = AstPrinter() + def build(self, src): + # Store src for later: + self.src = src + print('[0] source:') + print(src) + print('[1] parsing') + self.p.parseSource(src) + ok = len(self.diag.diags) == 0 + if not ok: + return + pkg = self.sema.mod + self.pkg = pkg + self.al.analyzePackage(pkg) + self.tc.checkPackage(pkg) + print('{0} errors'.format(len(self.diag.diags))) + + for d in self.diag.diags: + print('ERROR:') + ppci.printError(src, d) + print('[2] ast:') + self.ap.printAst(pkg) + + #printAst(sema.mod) + + ok = len(self.diag.diags) == 0 + if ok: + print('Generating ir-code') + i = cg.gencode(pkg) + return i +