Mercurial > lcfOS
comparison python/c3/codegenerator.py @ 177:460db5669efa
Added clean pass for IR
author | Windel Bouwman |
---|---|
date | Mon, 22 Apr 2013 23:54:54 +0200 |
parents | 5fd02aa38b42 |
children | 46d62dadd61b |
comparison
equal
deleted
inserted
replaced
176:5fd02aa38b42 | 177:460db5669efa |
---|---|
122 print('Unknown cond', expr) | 122 print('Unknown cond', expr) |
123 def genExprCode(self, expr): | 123 def genExprCode(self, expr): |
124 if type(expr) is astnodes.Binop: | 124 if type(expr) is astnodes.Binop: |
125 ra = self.genExprCode(expr.a) | 125 ra = self.genExprCode(expr.a) |
126 rb = self.genExprCode(expr.b) | 126 rb = self.genExprCode(expr.b) |
127 tmp = self.builder.newTmp() | 127 ops = ['+', '-', '*', '/'] |
128 ops = ['+', '-', '*', '/', 'and', 'or'] | |
129 if expr.op in ops: | 128 if expr.op in ops: |
129 tmpnames = {'+':'addtmp', '-':'subtmp', '*': 'multmp', '/':'divtmp'} | |
130 tmp = self.builder.newTmp(tmpnames[expr.op]) | |
130 op = expr.op | 131 op = expr.op |
131 ins = ir.BinaryOperator(tmp, op, ra, rb) | 132 ins = ir.BinaryOperator(tmp, op, ra, rb) |
132 self.builder.addIns(ins) | 133 self.builder.addIns(ins) |
133 return tmp | 134 return tmp |
134 else: | 135 else: |
135 print('Unknown {0}'.format(expr)) | 136 print('Unknown {0}'.format(expr)) |
137 tmp = self.builder.newTmp() | |
136 # TODO | 138 # TODO |
137 return tmp | 139 return tmp |
138 elif type(expr) is astnodes.Constant: | 140 elif type(expr) is astnodes.Constant: |
139 tmp = self.builder.newTmp() | 141 tmp = self.builder.newTmp() |
140 # TODO | 142 # TODO |