Mercurial > lcfOS
diff python/c3/codegenerator.py @ 279:2ccd57b1d78c
Fix register allocator to do burn2 OK
author | Windel Bouwman |
---|---|
date | Sat, 12 Oct 2013 09:56:23 +0200 |
parents | 6f2423df0675 |
children | 02385f62f250 |
line wrap: on
line diff
--- a/python/c3/codegenerator.py Sun Sep 29 14:08:15 2013 +0200 +++ b/python/c3/codegenerator.py Sat Oct 12 09:56:23 2013 +0200 @@ -155,20 +155,22 @@ return ir.Binop(ra, expr.op, rb) elif type(expr) is astnodes.Unop and expr.op == '&': ra = self.genExprCode(expr.a) - # TODO: Make this work? - return ra + assert type(ra) is ir.Mem + return ra.e elif type(expr) is astnodes.VariableUse: - return self.varMap[expr.target] + # This returns the dereferenced variable. + return ir.Mem(self.varMap[expr.target]) elif type(expr) is astnodes.Deref: # dereference pointer type: addr = self.genExprCode(expr.ptr) return ir.Mem(addr) elif type(expr) is astnodes.FieldRef: - b = self.genExprCode(expr.base) - #b = b.e + base = self.genExprCode(expr.base) + assert type(base) is ir.Mem, type(base) + base = base.e bt = theType(expr.base.typ) offset = ir.Const(bt.fieldOffset(expr.field)) - return ir.Mem(ir.Binop(b, '+', offset)) + return ir.Mem(ir.Add(base, offset)) elif type(expr) is astnodes.Literal: return ir.Const(expr.val) elif type(expr) is astnodes.TypeCast: