comparison python/c3/codegenerator.py @ 204:de3a68f677a5

Added long comment to c3 parser
author Windel Bouwman
date Fri, 21 Jun 2013 15:01:08 +0200
parents 46d62dadd61b
children d77cb5962cc5
comparison
equal deleted inserted replaced
203:ca1ea402f6a1 204:de3a68f677a5
17 # inner helpers: 17 # inner helpers:
18 def genModule(self, pkg): 18 def genModule(self, pkg):
19 # Take care of forward declarations: 19 # Take care of forward declarations:
20 for s in pkg.scope: 20 for s in pkg.scope:
21 if type(s) is astnodes.Function: 21 if type(s) is astnodes.Function:
22 f = self.builder.newFunc(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.newTmp(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]
32 self.builder.setFunc(f) 32 self.builder.setFunction(f)
33 bb = self.builder.newBB() 33 bb = self.builder.newBB()
34 f.entry = bb 34 f.entry = bb
35 self.builder.setBB(bb) 35 self.builder.setBB(bb)
36 # generate room for locals: 36 # generate room for locals:
37 37
43 self.varMap[sym] = v 43 self.varMap[sym] = v
44 44
45 self.genCode(s.body) 45 self.genCode(s.body)
46 # TODO handle return? 46 # TODO handle return?
47 self.builder.addIns(ir.Return()) 47 self.builder.addIns(ir.Return())
48 self.builder.setFunc(None) 48 self.builder.setFunction(None)
49 else: 49 else:
50 print(s) 50 print(s)
51 51
52 def genCode(self, code): 52 def genCode(self, code):
53 if type(code) is astnodes.CompoundStatement: 53 if type(code) is astnodes.CompoundStatement: