changeset 151:afc8c0207984

Added ir code generator stub
author Windel Bouwman
date Fri, 01 Mar 2013 17:13:56 +0100
parents 4ae0e02599de
children b73bc14a3aa3
files python/c3/__init__.py python/c3/codegenerator.py python/testc3.py
diffstat 3 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
 
-
--- /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
+
--- 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()