changeset 102:63937c8d1478

Fixes and start with ir generator
author windel
date Tue, 25 Dec 2012 11:11:24 +0100
parents af0d7913677a
children 28a35161ef23
files python/ide.py python/ppci/builtin.py python/ppci/compilers/kscompiler.py python/ppci/core/__init__.py python/ppci/core/module.py python/ppci/frontends/ks/__init__.py python/ppci/frontends/ks/builtin.py python/ppci/frontends/ks/parser.py
diffstat 8 files changed, 19 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/python/ide.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ide.py	Tue Dec 25 11:11:24 2012 +0100
@@ -317,8 +317,8 @@
         source = ce.source
         self.buildOutput.clear()
         self.buildOutput.append(str(self.compiler))
-        print(source)
-        self.compiler.compilesource(source)
+        ast = self.compiler.compilesource(source)
+        self.astViewer.setAst(ast)
         self.buildOutput.append("Done!")
   def buildProject(self):
      """ Build project """
--- a/python/ppci/builtin.py	Mon Dec 24 17:55:08 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-from .nodes import *
-
-boolean = BaseType('boolean', 8) # Choose: 1 or 8 bytes?
-integer = BaseType('integer', 8)
-real = BaseType('real', 8)
-char = BaseType('char', 1)
-void = BaseType('void', 0)
-
-chr_func = BuiltinProcedure('chr', ProcedureType([Parameter('value', 'x', integer)], char))
-
--- a/python/ppci/compilers/kscompiler.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ppci/compilers/kscompiler.py	Tue Dec 25 11:11:24 2012 +0100
@@ -1,6 +1,7 @@
 import hashlib
 # Import compiler components:
 from ..frontends.ks import KsParser
+from ..frontends.ks import KsIrGenerator
 #from .codegenerator import CodeGenerator
 #from .nodes import ExportedSymbol
 from ..core.errors import CompilerException
@@ -31,16 +32,10 @@
       # TODO: implement optimization
 
       # Pass 3: code generation
-      CodeGenerator().generatecode(ast)
+      ir = KsIrGenerator().generateIr(ast)
       # Attach a signature:
       ast.signature = self.generateSignature(src)
       # Generate exported symbols:
-      ast.exports = []
-      for proc in ast.procs:
-         if proc.public:
-            sym = ExportedSymbol(proc.name, proc.typ)
-            sym.imageoffset = proc.entrypoint
-            ast.exports.append(sym)
       return ast
 
    def compileProject(self, project):
--- a/python/ppci/core/__init__.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ppci/core/__init__.py	Tue Dec 25 11:11:24 2012 +0100
@@ -3,6 +3,7 @@
 from .value import *
 from .bitreader import BitReader
 from .errors import CompilerException
+from .module import Module
 
 
 version='0.0.1'
--- a/python/ppci/core/module.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ppci/core/module.py	Tue Dec 25 11:11:24 2012 +0100
@@ -1,4 +1,5 @@
 
 class Module:
-   pass
+   def __init__(self):
+      print('new module!')
    
--- a/python/ppci/frontends/ks/__init__.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ppci/frontends/ks/__init__.py	Tue Dec 25 11:11:24 2012 +0100
@@ -5,6 +5,7 @@
 """
 
 from .parser import KsParser
+from .irgenerator import KsIrGenerator
 
 class KsFrontend:
    def __init__(self):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/ppci/frontends/ks/builtin.py	Tue Dec 25 11:11:24 2012 +0100
@@ -0,0 +1,10 @@
+from .nodes import *
+
+boolean = BaseType('boolean', 8) # Choose: 1 or 8 bytes?
+integer = BaseType('integer', 8)
+real = BaseType('real', 8)
+char = BaseType('char', 1)
+void = BaseType('void', 0)
+
+chr_func = BuiltinProcedure('chr', ProcedureType([Parameter('value', 'x', integer)], char))
+
--- a/python/ppci/frontends/ks/parser.py	Mon Dec 24 17:55:08 2012 +0100
+++ b/python/ppci/frontends/ks/parser.py	Tue Dec 25 11:11:24 2012 +0100
@@ -5,7 +5,7 @@
 from .symboltable import SymbolTable
 from .nodes import *
 from ...core.errors import CompilerException, Error
-#from .builtin import *
+from .builtin import *
 #from . import assembler
 from .lexer import tokenize