Mercurial > lcfOS
comparison python/c3/codegenerator.py @ 233:d3dccf12ca88
Added hexfile tests
author | Windel Bouwman |
---|---|
date | Sun, 14 Jul 2013 12:28:23 +0200 |
parents | e621e3ba78d2 |
children | e41e4109addd |
comparison
equal
deleted
inserted
replaced
232:e621e3ba78d2 | 233:d3dccf12ca88 |
---|---|
148 op = expr.op | 148 op = expr.op |
149 ins = ir.BinaryOperator(tmp, op, ra, rb) | 149 ins = ir.BinaryOperator(tmp, op, ra, rb) |
150 self.builder.addIns(ins) | 150 self.builder.addIns(ins) |
151 return tmp | 151 return tmp |
152 else: | 152 else: |
153 print('Unknown {0}'.format(expr)) | 153 raise NotImplementedError('Unknown {0}'.format(expr)) |
154 tmp = self.builder.newTmp() | 154 tmp = self.builder.newTmp() |
155 # TODO | 155 # TODO |
156 return tmp | 156 return tmp |
157 elif type(expr) is astnodes.Unop: | 157 elif type(expr) is astnodes.Unop: |
158 ra = self.genExprCode(expr.a) | 158 ra = self.genExprCode(expr.a) |
160 # Address of operator | 160 # Address of operator |
161 tmp = self.builder.newTmp('addr') | 161 tmp = self.builder.newTmp('addr') |
162 return tmp | 162 return tmp |
163 #self.builder.addIns(ins) | 163 #self.builder.addIns(ins) |
164 else: | 164 else: |
165 raise Exception('Unknown {0}'.format(expr)) | 165 raise NotImplementedError('Unknown {0}'.format(expr)) |
166 elif type(expr) is astnodes.Constant: | 166 elif type(expr) is astnodes.Constant: |
167 tmp = self.builder.newTmp() | 167 tmp = self.builder.newTmp() |
168 # TODO | 168 # TODO |
169 return tmp | 169 return tmp |
170 elif type(expr) is astnodes.VariableUse: | 170 elif type(expr) is astnodes.VariableUse: |
202 elif isinstance(expr.a.typ, astnodes.PointerType): | 202 elif isinstance(expr.a.typ, astnodes.PointerType): |
203 return ar | 203 return ar |
204 else: | 204 else: |
205 raise Exception() | 205 raise Exception() |
206 else: | 206 else: |
207 raise Exception("not implemented") | 207 raise NotImplementedError("not implemented") |
208 elif type(expr) is astnodes.FunctionCall: | 208 elif type(expr) is astnodes.FunctionCall: |
209 tmp = self.builder.newTmp("res") | 209 tmp = self.builder.newTmp("res") |
210 args = [] | 210 args = [] |
211 for arg in expr.args: | 211 for arg in expr.args: |
212 ar = self.genExprCode(arg) | 212 ar = self.genExprCode(arg) |
214 fn = self.funcMap[expr.proc] | 214 fn = self.funcMap[expr.proc] |
215 ins = ir.Call(fn, args, tmp) | 215 ins = ir.Call(fn, args, tmp) |
216 self.builder.addIns(ins) | 216 self.builder.addIns(ins) |
217 return tmp | 217 return tmp |
218 else: | 218 else: |
219 raise CompilerError('Unknown expr {}'.format(expr)) | 219 raise NotImplementedError('Unknown expr {}'.format(expr)) |
220 | 220 |