comparison python/c3/codegenerator.py @ 205:d77cb5962cc5

Added some handcoded arm code generation
author Windel Bouwman
date Sun, 23 Jun 2013 18:23:18 +0200
parents de3a68f677a5
children 8b2e5f3cd579
comparison
equal deleted inserted replaced
204:de3a68f677a5 205:d77cb5962cc5
21 if type(s) is astnodes.Function: 21 if type(s) is astnodes.Function:
22 f = self.builder.newFunction(s.name) 22 f = self.builder.newFunction(s.name)
23 self.funcMap[s] = f 23 self.funcMap[s] = f
24 for s in pkg.scope: 24 for s in pkg.scope:
25 if type(s) is astnodes.Variable: 25 if type(s) is astnodes.Variable:
26 v = self.builder.newTmp(s.name) 26 v = self.builder.newVariable(s.name)
27 #self.builder.addIns(ir.Alloc(v)) 27 #self.builder.addIns(ir.Alloc(v))
28 self.varMap[s] = v 28 self.varMap[s] = v
29 elif type(s) is astnodes.Function: 29 elif type(s) is astnodes.Function:
30 # TODO: handle arguments 30 # TODO: handle arguments
31 f = self.funcMap[s] 31 f = self.funcMap[s]
114 self.builder.addIns(i) 114 self.builder.addIns(i)
115 else: 115 else:
116 raise NotImlementedError('Unknown condition {0}'.format(expr)) 116 raise NotImlementedError('Unknown condition {0}'.format(expr))
117 elif type(expr) is astnodes.Literal: 117 elif type(expr) is astnodes.Literal:
118 if expr.val: 118 if expr.val:
119 self.builder.addIns(ir.BranchInstruction(bbtrue)) 119 self.builder.addIns(ir.Branch(bbtrue))
120 else: 120 else:
121 self.builder.addIns(ir.BranchInstruction(bbfalse)) 121 self.builder.addIns(ir.Branch(bbfalse))
122 else: 122 else:
123 print('Unknown cond', expr) 123 print('Unknown cond', expr)
124 def genExprCode(self, expr): 124 def genExprCode(self, expr):
125 if type(expr) is astnodes.Binop: 125 if type(expr) is astnodes.Binop:
126 ra = self.genExprCode(expr.a) 126 ra = self.genExprCode(expr.a)