annotate python/ir/function.py @ 256:225f444019b1

Added build and flash menu option
author Windel Bouwman
date Sun, 04 Aug 2013 18:32:04 +0200
parents 74c6a20302d5
children 5ec7580976d9
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
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
32 @property
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
33 def Entry(self):
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
34 return self.BasicBlocks[0]
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
35
239
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
36 def check(self):
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
37 for bb in self.BasicBlocks:
63bb40758066 added check
Windel Bouwman
parents: 230
diff changeset
38 bb.check()
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
39
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
40 def call(self, *args):
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
41 varmap = {}
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
42 bb = self.Entry
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
43 ip = 0
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
44 while True:
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
45 i = bb.Instructions[ip]
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
46 ip += 1
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
47 return
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
48
74c6a20302d5 Added better logging
Windel Bouwman
parents: 239
diff changeset
49