Mercurial > lcfOS
diff python/ppci/c3/builder.py @ 307:e609d5296ee9
Massive rewrite of codegenerator
author | Windel Bouwman |
---|---|
date | Thu, 12 Dec 2013 20:42:56 +0100 |
parents | b145f8e6050b |
children | 2e7f55319858 |
line wrap: on
line diff
--- a/python/ppci/c3/builder.py Mon Dec 09 19:00:21 2013 +0100 +++ b/python/ppci/c3/builder.py Thu Dec 12 20:42:56 2013 +0100 @@ -1,9 +1,8 @@ import logging from .lexer import Lexer from .parser import Parser -from .analyse import TypeChecker, Analyzer from .codegenerator import CodeGenerator -from .analyse import AddScope +from .analyse import ScopeFiller from .scope import createTopScope from .visitor import AstPrinter @@ -18,9 +17,7 @@ self.diag = diag self.lexer = Lexer(diag) self.parser = Parser(diag) - self.tc = TypeChecker(diag) - self.al = Analyzer(diag) - self.cg = CodeGenerator() + self.cg = CodeGenerator(diag) self.topScope = createTopScope(target) # Scope with built in types def build(self, srcs, imps=[]): @@ -31,6 +28,7 @@ self.ok = True self.pkgs = {} + # Parsing stage (phase 1) def doParse(src): tokens = self.lexer.lex(src) return self.parser.parseSource(tokens) @@ -41,30 +39,22 @@ self.ok = False return - #for pkg in all_pkgs: - # AstPrinter().printAst(pkg) - + # Fix scopes and package refs (phase 1.5) packages = {pkg.name: pkg for pkg in all_pkgs} self.pkgs = packages + + scopeFiller = ScopeFiller(self.diag, self.topScope, packages) # Fix scopes: for pkg in all_pkgs: - AddScope(self.diag, self.topScope).addScope(pkg) + scopeFiller.addScope(pkg) if not all(pkg.ok for pkg in all_pkgs): self.ok = False return - for pkg in all_pkgs: - self.al.analyzePackage(pkg, packages) + # Generate intermediate code (phase 2) + # Only return ircode when everything is OK + for pkg in all_pkgs & s_pkgs: + yield self.cg.gencode(pkg) if not all(pkg.ok for pkg in all_pkgs): self.ok = False return - - for pkg in all_pkgs: - self.tc.checkPackage(pkg) - if not all(pkg.ok for pkg in all_pkgs): - self.ok = False - return - - # Only return ircode when everything is OK - for pkg in all_pkgs & s_pkgs: - yield self.cg.gencode(pkg)