Mercurial > lcfOS
diff python/c3/codegenerator.py @ 274:ea93e0a7a31e
Move docs
author | Windel Bouwman |
---|---|
date | Wed, 04 Sep 2013 17:35:06 +0200 |
parents | e64bae57cda8 |
children | 6f2423df0675 |
line wrap: on
line diff
--- a/python/c3/codegenerator.py Mon Sep 02 17:40:21 2013 +0200 +++ b/python/c3/codegenerator.py Wed Sep 04 17:35:06 2013 +0200 @@ -7,7 +7,14 @@ class CodeGenerator(ir.Builder): - """ Generates intermediate code from a package """ + """ + Generates intermediate (IR) code from a package. The entry function is + 'genModule'. The main task of this part is to rewrite complex control + structures, such as while and for loops into simple conditional + jump statements. Also complex conditional statements are simplified. + Such as 'and' and 'or' statements are rewritten in conditional jumps. + And structured datatypes are rewritten. + """ def __init__(self): self.logger = logging.getLogger('c3cgen') @@ -48,11 +55,14 @@ # TODO: handle parameters different if sym.isParameter: print('param', sym) - ir.Parameter(sym.name) - if sym.isLocal: + v = ir.Parameter(sym.name) + f.addParameter(v) + elif sym.isLocal: print('local', sym) - - v = self.newTemp() + v = self.newTemp() + else: + v = self.newTemp() + #raise NotImplementedError('{}'.format(sym)) # TODO: make this ssa here?? self.varMap[sym] = v @@ -93,6 +103,8 @@ re = self.genExprCode(code.expr) self.emit(ir.Move(self.fn.return_value, re)) self.emit(ir.Jump(self.fn.epiloog)) + b = self.newBlock() + self.setBlock(b) else: self.builder.addIns(ir.Return()) elif type(code) is astnodes.WhileStatement: