annotate python/ir/function.py @ 245:66912720d712

Added grinder
author Windel Bouwman
date Wed, 24 Jul 2013 22:40:29 +0200
parents 63bb40758066
children 74c6a20302d5
rev   line source
172
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
1 from .basicblock import BasicBlock
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
2
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
3 class Function:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
4 def __init__(self, name):
172
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
5 self.name = name
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
6 self.bbs = []
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
7 self.entry = None
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 177
diff changeset
8
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
9 def __repr__(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
10 return 'Function {0}'.format(self.name)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 177
diff changeset
11
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
12 def addBB(self, bb):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
13 self.bbs.append(bb)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
14 bb.parent = self
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
15 addBasicBlock = addBB
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 177
diff changeset
16
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
17 def removeBasicBlock(self, bb):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
18 self.bbs.remove(bb)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
19 bb.parent = None
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
20
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
21 def getBBs(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
22 return self.bbs
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 177
diff changeset
23
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
24 def findBasicBlock(self, name):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
25 for bb in self.bbs:
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
26 if bb.name == name:
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
27 return bb
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
28 raise KeyError(name)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
29
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 205
diff changeset
30 BasicBlocks = property(getBBs)
172
5a7d37d615ee Added function to IR
Windel Bouwman
parents:
diff changeset
31
239
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
32 def check(self):
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
33 for bb in self.BasicBlocks:
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
34 bb.check()