# HG changeset patch # User Windel Bouwman # Date 1362154436 -3600 # Node ID afc8c020798404f662322dd19e12b42f5a3933ba # Parent 4ae0e02599de0c12859fa47a3062be4aed714a16 Added ir code generator stub diff -r 4ae0e02599de -r afc8c0207984 python/c3/__init__.py --- a/python/c3/__init__.py Fri Mar 01 16:53:22 2013 +0100 +++ b/python/c3/__init__.py Fri Mar 01 17:13:56 2013 +0100 @@ -1,9 +1,8 @@ - -# Convenience: +# Convenience imports: from .parser import Parser from .semantics import Semantics from .typecheck import TypeChecker from .analyse import Analyzer +from .codegenerator import CodeGenerator - diff -r 4ae0e02599de -r afc8c0207984 python/c3/codegenerator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/c3/codegenerator.py Fri Mar 01 17:13:56 2013 +0100 @@ -0,0 +1,8 @@ + +#from ppci import ircode + +class CodeGenerator: + """ Generates intermediate code """ + def gencode(self, ast): + pass + diff -r 4ae0e02599de -r afc8c0207984 python/testc3.py --- a/python/testc3.py Fri Mar 01 16:53:22 2013 +0100 +++ b/python/testc3.py Fri Mar 01 17:13:56 2013 +0100 @@ -50,17 +50,18 @@ for c in ast.getChildren(): printAst(c, indent + ' ') -def do(): +def c3compile(src): print('[0] source:') - print(testsrc) + print(src) print('[1] parsing') diag = Diagnostics() sema = c3.Semantics(diag) p = c3.Parser(sema, diag) tc = c3.TypeChecker(diag) al = c3.Analyzer(diag) + cg = c3.CodeGenerator() t1 = time.time() - p.parseSource(testsrc) + p.parseSource(src) t2 = time.time() print('parsetime: {0} [s]'.format(t2 - t1)) t2 = time.time() @@ -75,5 +76,14 @@ print('[2] ast:') printAst(sema.mod) + ok = len(diag.diags) == 0 + if ok: + cg.gencode(sema.mod) + else: + print('Not generating code') + +def do(): + c3compile(testsrc) + do()