annotate python/ppci/codegen/flowgraph.py @ 362:c05ab629976a

Added CPUID for arm
author Windel Bouwman
date Sat, 15 Mar 2014 10:56:34 +0100
parents b00219172a42
children
rev   line source
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 278
diff changeset
1 from .graph import DiGraph, DiNode
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
2
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
3
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 278
diff changeset
4 class FlowGraphNode(DiNode):
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
5 """ A node in the flow graph """
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
6 def __init__(self, g, ins):
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
7 super().__init__(g)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
8 self.ins = ins
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
9 self.uses = set(ins.src)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
10 self.defs = set(ins.dst)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
11 self.live_in = set()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
12 self.live_out = set()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
13
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
14 def __repr__(self):
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
15 r = '{}'.format(self.ins)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
16 if self.uses:
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
17 r += ' uses:' + ', '.join(str(u) for u in self.uses)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
18 if self.defs:
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
19 r += ' defs:' + ', '.join(str(d) for d in self.defs)
ea93e0a7a31e Move docs
Windel Bouwman
parents: 269
diff changeset
20 return r
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
21
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
22
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 301
diff changeset
23
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 278
diff changeset
24 class FlowGraph(DiGraph):
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
25 def __init__(self, instrs):
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
26 """ Create a flowgraph from a list of abstract instructions """
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
27 super().__init__()
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
28 self._map = {}
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
29 # Add nodes:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
30 for ins in instrs:
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
31 n = FlowGraphNode(self, ins)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
32 self._map[ins] = n
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 301
diff changeset
33 self.add_node(n)
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
34
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
35 # Make edges:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
36 prev = None
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
37 for ins in instrs:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
38 n = self._map[ins]
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
39 if prev:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
40 self.addEdge(prev, n)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
41 if ins.jumps:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
42 prev = None
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
43 for j in ins.jumps:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
44 to_n = self._map[j]
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
45 self.addEdge(n, to_n)
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
46 else:
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents:
diff changeset
47 prev = n