comparison python/ir/builder.py @ 172:5a7d37d615ee

Added function to IR
author Windel Bouwman
date Thu, 04 Apr 2013 17:58:37 +0200
parents 3eb9b9e2958d
children 3eb06f5fb987
comparison
equal deleted inserted replaced
171:3eb9b9e2958d 172:5a7d37d615ee
1 from . import Value, BasicBlock 1 from . import Value, BasicBlock, Function
2 2
3 class NameGenerator: 3 class NameGenerator:
4 def __init__(self, prefix): 4 def __init__(self, prefix):
5 self.prefix = prefix 5 self.prefix = prefix
6 def NumGen(): 6 def NumGen():
30 def __init__(self): 30 def __init__(self):
31 self.newTmp = ValueGenerator().gen 31 self.newTmp = ValueGenerator().gen
32 self.newBBint = BBGenerator().gen 32 self.newBBint = BBGenerator().gen
33 self.bb = None 33 self.bb = None
34 self.m = None 34 self.m = None
35 self.fn = None
35 36
36 # Helpers: 37 # Helpers:
37 def newBB(self): 38 def newBB(self):
38 bb = self.newBBint() 39 bb = self.newBBint()
39 self.m.addBB(bb) 40 self.fn.addBB(bb)
40 return bb 41 return bb
41 def setModule(self, m): 42 def setModule(self, m):
42 self.m = m 43 self.m = m
44 def newFunc(self, name):
45 f = Function(name)
46 self.m.addFunc(f)
47 return f
48 def setFunc(self, f):
49 self.fn = f
43 def setBB(self, bb): 50 def setBB(self, bb):
44 self.bb = bb 51 self.bb = bb
45 def addIns(self, i): 52 def addIns(self, i):
46 self.bb.addIns(i) 53 self.bb.addIns(i)
47 54