Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
278:9fca39eebe50 | 279:2ccd57b1d78c |
---|---|
153 ra = self.genExprCode(expr.a) | 153 ra = self.genExprCode(expr.a) |
154 rb = self.genExprCode(expr.b) | 154 rb = self.genExprCode(expr.b) |
155 return ir.Binop(ra, expr.op, rb) | 155 return ir.Binop(ra, expr.op, rb) |
156 elif type(expr) is astnodes.Unop and expr.op == '&': | 156 elif type(expr) is astnodes.Unop and expr.op == '&': |
157 ra = self.genExprCode(expr.a) | 157 ra = self.genExprCode(expr.a) |
158 # TODO: Make this work? | 158 assert type(ra) is ir.Mem |
159 return ra | 159 return ra.e |
160 elif type(expr) is astnodes.VariableUse: | 160 elif type(expr) is astnodes.VariableUse: |
161 return self.varMap[expr.target] | 161 # This returns the dereferenced variable. |
162 return ir.Mem(self.varMap[expr.target]) | |
162 elif type(expr) is astnodes.Deref: | 163 elif type(expr) is astnodes.Deref: |
163 # dereference pointer type: | 164 # dereference pointer type: |
164 addr = self.genExprCode(expr.ptr) | 165 addr = self.genExprCode(expr.ptr) |
165 return ir.Mem(addr) | 166 return ir.Mem(addr) |
166 elif type(expr) is astnodes.FieldRef: | 167 elif type(expr) is astnodes.FieldRef: |
167 b = self.genExprCode(expr.base) | 168 base = self.genExprCode(expr.base) |
168 #b = b.e | 169 assert type(base) is ir.Mem, type(base) |
170 base = base.e | |
169 bt = theType(expr.base.typ) | 171 bt = theType(expr.base.typ) |
170 offset = ir.Const(bt.fieldOffset(expr.field)) | 172 offset = ir.Const(bt.fieldOffset(expr.field)) |
171 return ir.Mem(ir.Binop(b, '+', offset)) | 173 return ir.Mem(ir.Add(base, offset)) |
172 elif type(expr) is astnodes.Literal: | 174 elif type(expr) is astnodes.Literal: |
173 return ir.Const(expr.val) | 175 return ir.Const(expr.val) |
174 elif type(expr) is astnodes.TypeCast: | 176 elif type(expr) is astnodes.TypeCast: |
175 # TODO: improve this mess: | 177 # TODO: improve this mess: |
176 ar = self.genExprCode(expr.a) | 178 ar = self.genExprCode(expr.a) |