Mercurial > lcfOS
comparison python/flowgraph.py @ 277:046017431c6a
Started register allocator
author | Windel Bouwman |
---|---|
date | Thu, 26 Sep 2013 21:14:25 +0200 |
parents | ea93e0a7a31e |
children | 9fca39eebe50 |
comparison
equal
deleted
inserted
replaced
276:56d37ed4b4d2 | 277:046017431c6a |
---|---|
1 import graph | |
1 | 2 |
2 | |
3 import graph | |
4 | 3 |
5 class FlowGraphNode(graph.Node): | 4 class FlowGraphNode(graph.Node): |
6 """ A node in the flow graph """ | 5 """ A node in the flow graph """ |
7 def __init__(self, g, ins): | 6 def __init__(self, g, ins): |
8 super().__init__(g) | 7 super().__init__(g) |
22 | 21 |
23 | 22 |
24 class FlowGraph(graph.Graph): | 23 class FlowGraph(graph.Graph): |
25 def __init__(self, instrs): | 24 def __init__(self, instrs): |
26 """ Create a flowgraph from a list of abstract instructions """ | 25 """ Create a flowgraph from a list of abstract instructions """ |
27 super().__init__() | 26 super().__init__(True) |
28 self._map = {} | 27 self._map = {} |
29 # Add nodes: | 28 # Add nodes: |
30 for ins in instrs: | 29 for ins in instrs: |
31 n = self.newNode(ins) | 30 n = self.newNode(ins) |
32 self._map[ins] = n | |
33 | 31 |
34 # Make edges: | 32 # Make edges: |
35 prev = None | 33 prev = None |
36 for ins in instrs: | 34 for ins in instrs: |
37 n = self._map[ins] | 35 n = self._map[ins] |
46 prev = n | 44 prev = n |
47 | 45 |
48 def newNode(self, ins): | 46 def newNode(self, ins): |
49 """ Override new node to make flow graph node """ | 47 """ Override new node to make flow graph node """ |
50 n = FlowGraphNode(self, ins) | 48 n = FlowGraphNode(self, ins) |
51 self.nodes.append(n) | 49 self._map[ins] = n |
50 self.addNode(n) | |
52 return n | 51 return n |
53 | 52 |
54 | 53 |
55 |