Mercurial > lcfOS
annotate python/ppci/codegen/flowgraph.py @ 367:577ed7fb3fe4
Try to make thumb work again
author | Windel Bouwman |
---|---|
date | Fri, 21 Mar 2014 10:27:57 +0100 |
parents | b00219172a42 |
children |
rev | line source |
---|---|
296 | 1 from .graph import DiGraph, DiNode |
269 | 2 |
3 | |
296 | 4 class FlowGraphNode(DiNode): |
269 | 5 """ A node in the flow graph """ |
6 def __init__(self, g, ins): | |
7 super().__init__(g) | |
8 self.ins = ins | |
9 self.uses = set(ins.src) | |
10 self.defs = set(ins.dst) | |
11 self.live_in = set() | |
12 self.live_out = set() | |
13 | |
14 def __repr__(self): | |
274 | 15 r = '{}'.format(self.ins) |
16 if self.uses: | |
17 r += ' uses:' + ', '.join(str(u) for u in self.uses) | |
18 if self.defs: | |
19 r += ' defs:' + ', '.join(str(d) for d in self.defs) | |
20 return r | |
269 | 21 |
22 | |
337 | 23 |
296 | 24 class FlowGraph(DiGraph): |
269 | 25 def __init__(self, instrs): |
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 | 28 self._map = {} |
29 # Add nodes: | |
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 | 33 self.add_node(n) |
269 | 34 |
35 # Make edges: | |
36 prev = None | |
37 for ins in instrs: | |
38 n = self._map[ins] | |
39 if prev: | |
40 self.addEdge(prev, n) | |
41 if ins.jumps: | |
42 prev = None | |
43 for j in ins.jumps: | |
44 to_n = self._map[j] | |
45 self.addEdge(n, to_n) | |
46 else: | |
47 prev = n |