comparison python/c3/codegenerator.py @ 275:6f2423df0675

Fixed serve arm-as
author Windel Bouwman
date Sat, 14 Sep 2013 17:29:10 +0200
parents ea93e0a7a31e
children 2ccd57b1d78c
comparison
equal deleted inserted replaced
274:ea93e0a7a31e 275:6f2423df0675
33 # Take care of forward declarations: 33 # Take care of forward declarations:
34 for s in pkg.innerScope.Functions: 34 for s in pkg.innerScope.Functions:
35 f = self.newFunction(s.name) 35 f = self.newFunction(s.name)
36 self.funcMap[s] = f 36 self.funcMap[s] = f
37 for v in pkg.innerScope.Variables: 37 for v in pkg.innerScope.Variables:
38 #print(v)
39 self.varMap[v] = self.newTemp() 38 self.varMap[v] = self.newTemp()
40 for s in pkg.innerScope.Functions: 39 for s in pkg.innerScope.Functions:
41 self.genFunction(s) 40 self.genFunction(s)
42 41
43 def genFunction(self, fn): 42 def genFunction(self, fn):
52 # generate room for locals: 51 # generate room for locals:
53 52
54 for sym in fn.innerScope: 53 for sym in fn.innerScope:
55 # TODO: handle parameters different 54 # TODO: handle parameters different
56 if sym.isParameter: 55 if sym.isParameter:
57 print('param', sym)
58 v = ir.Parameter(sym.name) 56 v = ir.Parameter(sym.name)
59 f.addParameter(v) 57 f.addParameter(v)
60 elif sym.isLocal: 58 elif sym.isLocal:
61 print('local', sym) 59 v = ir.LocalVariable(sym.name)
62 v = self.newTemp() 60 f.addLocal(v)
63 else: 61 else:
64 v = self.newTemp() 62 #v = self.newTemp()
65 #raise NotImplementedError('{}'.format(sym)) 63 raise NotImplementedError('{}'.format(sym))
66 # TODO: make this ssa here?? 64 # TODO: make this ssa here??
67 self.varMap[sym] = v 65 self.varMap[sym] = v
68 66
69 self.genCode(fn.body) 67 self.genCode(fn.body)
70 # Set the default return value to zero: 68 # Set the default return value to zero:
82 elif type(code) is astnodes.Assignment: 80 elif type(code) is astnodes.Assignment:
83 rval = self.genExprCode(code.rval) 81 rval = self.genExprCode(code.rval)
84 lval = self.genExprCode(code.lval) 82 lval = self.genExprCode(code.lval)
85 self.emit(ir.Move(lval, rval)) 83 self.emit(ir.Move(lval, rval))
86 elif type(code) is astnodes.ExpressionStatement: 84 elif type(code) is astnodes.ExpressionStatement:
87 self.genExprCode(code.ex) 85 self.emit(ir.Exp(self.genExprCode(code.ex)))
88 elif type(code) is astnodes.IfStatement: 86 elif type(code) is astnodes.IfStatement:
89 bbtrue = self.newBlock() 87 bbtrue = self.newBlock()
90 bbfalse = self.newBlock() 88 bbfalse = self.newBlock()
91 te = self.newBlock() 89 te = self.newBlock()
92 self.genCondCode(code.condition, bbtrue, bbfalse) 90 self.genCondCode(code.condition, bbtrue, bbfalse)