Mercurial > lcfOS
diff python/c3/codegenerator.py @ 221:848c4b15fd0b
pointers
author | Windel Bouwman |
---|---|
date | Mon, 08 Jul 2013 22:21:44 +0200 |
parents | 3f6c30a5d234 |
children | c3f1ce8b638f |
line wrap: on
line diff
--- a/python/c3/codegenerator.py Sat Jul 06 21:32:20 2013 +0200 +++ b/python/c3/codegenerator.py Mon Jul 08 22:21:44 2013 +0200 @@ -51,12 +51,13 @@ def genCode(self, code): if type(code) is astnodes.CompoundStatement: - for s in code.statements: - self.genCode(s) + for s in code.statements: + self.genCode(s) elif type(code) is astnodes.Assignment: re = self.genExprCode(code.rval) # TODO: Handle pointers - loc = self.varMap[code.lval.target] + loc = self.genExprCode(code.lval) + # determine location of variable self.builder.addIns(ir.Store(loc, re)) elif type(code) is astnodes.IfStatement: bbtrue = self.builder.newBB() @@ -70,9 +71,6 @@ self.genCode(code.falsestatement) self.builder.addIns(ir.Branch(te)) self.builder.setBB(te) - elif type(code) is astnodes.FunctionCall: - print('TODO') - pass elif type(code) is astnodes.EmptyStatement: pass elif type(code) is astnodes.ReturnStatement: @@ -126,9 +124,9 @@ if type(expr) is astnodes.Binop: ra = self.genExprCode(expr.a) rb = self.genExprCode(expr.b) - ops = ['+', '-', '*', '/'] + ops = ['+', '-', '*', '/', '|', '&'] if expr.op in ops: - tmpnames = {'+':'addtmp', '-':'subtmp', '*': 'multmp', '/':'divtmp'} + tmpnames = {'+':'add', '-':'sub', '*': 'mul', '/':'div', '|':'or', '&':'and'} tmp = self.builder.newTmp(tmpnames[expr.op]) op = expr.op ins = ir.BinaryOperator(tmp, op, ra, rb)