# HG changeset patch # User windel # Date 1356430284 -3600 # Node ID 63937c8d1478ffe5850b9049eff56557522f04ae # Parent af0d7913677add4c09cd73c3209b6619e1b2d51c Fixes and start with ir generator diff -r af0d7913677a -r 63937c8d1478 python/ide.py --- 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 """ diff -r af0d7913677a -r 63937c8d1478 python/ppci/builtin.py --- 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)) - diff -r af0d7913677a -r 63937c8d1478 python/ppci/compilers/kscompiler.py --- 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): diff -r af0d7913677a -r 63937c8d1478 python/ppci/core/__init__.py --- 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' diff -r af0d7913677a -r 63937c8d1478 python/ppci/core/module.py --- 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!') diff -r af0d7913677a -r 63937c8d1478 python/ppci/frontends/ks/__init__.py --- 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): diff -r af0d7913677a -r 63937c8d1478 python/ppci/frontends/ks/builtin.py --- /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)) + diff -r af0d7913677a -r 63937c8d1478 python/ppci/frontends/ks/parser.py --- 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