Mercurial > lcfOS
diff python/ir/module.py @ 172:5a7d37d615ee
Added function to IR
author | Windel Bouwman |
---|---|
date | Thu, 04 Apr 2013 17:58:37 +0200 |
parents | 3eb9b9e2958d |
children | c1d2b6b9f9a7 |
line wrap: on
line diff
--- a/python/ir/module.py Wed Apr 03 22:20:20 2013 +0200 +++ b/python/ir/module.py Thu Apr 04 17:58:37 2013 +0200 @@ -6,24 +6,34 @@ """ Main container for a piece of code. """ def __init__(self, name): self.name = name - self.bbs = [] + self.funcs = [] def __repr__(self): return 'IR-module [{0}]'.format(self.name) def getInstructions(self): ins = [] - for bb in self.bbs: + for bb in self.BasicBlocks: ins += bb.Instructions return ins Instructions = property(getInstructions) - def addBB(self, bb): - self.bbs.append(bb) def getBBs(self): - return self.bbs + bbs = [] + for f in self.Functions: + bbs += f.BasicBlocks + return bbs BasicBlocks = property(getBBs) + def addFunc(self, f): + self.funcs.append(f) + def getFuncs(self): + return self.funcs + Functions = property(getFuncs) def dump(self): print(self) - for i in self.Instructions: - print(i, 'live vars:', list(i.live_in), 'uses', list(i.uses), 'defs', list(i.defs)) + for fn in self.Functions: + print(fn) + for bb in fn.BasicBlocks: + print(' ', bb) + for ins in bb.Instructions: + print(' ', ins) print('END') def dumpgv(self, outf): outf.write('digraph G \n{\n') @@ -46,7 +56,7 @@ def link(a, b): a.succ.add(b) b.pred.add(a) - for bb in self.bbs: + for bb in self.BasicBlocks: if not bb.Empty: if len(bb.Instructions) > 1: for i1, i2 in zip(bb.Instructions[:-1], bb.Instructions[1:]):