OLD | NEW |
1 """A flow graph representation for Python bytecode""" | 1 """A flow graph representation for Python bytecode""" |
2 | 2 |
3 import dis | 3 import dis |
4 import types | 4 import types |
5 import sys | 5 import sys |
6 | 6 |
7 from compiler import misc | 7 from compiler import misc |
8 from compiler.consts \ | 8 from compiler.consts \ |
9 import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS | 9 import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 for c in b.get_children(): | 115 for c in b.get_children(): |
116 if c not in remaining: | 116 if c not in remaining: |
117 todo.append(c) | 117 todo.append(c) |
118 | 118 |
119 # A block is dominated by another block if that block must be emitted | 119 # A block is dominated by another block if that block must be emitted |
120 # before it. | 120 # before it. |
121 dominators = {} | 121 dominators = {} |
122 for b in remaining: | 122 for b in remaining: |
123 if __debug__ and b.next: | 123 if __debug__ and b.next: |
124 assert b is b.next[0].prev[0], (b, b.next) | 124 assert b is b.next[0].prev[0], (b, b.next) |
| 125 # Make sure every block appears in dominators, even if no |
| 126 # other block must precede it. |
| 127 dominators.setdefault(b, set()) |
125 # preceeding blocks dominate following blocks | 128 # preceeding blocks dominate following blocks |
126 for c in b.get_followers(): | 129 for c in b.get_followers(): |
127 while 1: | 130 while 1: |
128 dominators.setdefault(c, set()).add(b) | 131 dominators.setdefault(c, set()).add(b) |
129 # Any block that has a next pointer leading to c is also | 132 # Any block that has a next pointer leading to c is also |
130 # dominated because the whole chain will be emitted at once. | 133 # dominated because the whole chain will be emitted at once. |
131 # Walk backwards and add them all. | 134 # Walk backwards and add them all. |
132 if c.prev and c.prev[0] is not b: | 135 if c.prev and c.prev[0] is not b: |
133 c = c.prev[0] | 136 c = c.prev[0] |
134 else: | 137 else: |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 return -argc | 750 return -argc |
748 def BUILD_SLICE(self, argc): | 751 def BUILD_SLICE(self, argc): |
749 if argc == 2: | 752 if argc == 2: |
750 return -1 | 753 return -1 |
751 elif argc == 3: | 754 elif argc == 3: |
752 return -2 | 755 return -2 |
753 def DUP_TOPX(self, argc): | 756 def DUP_TOPX(self, argc): |
754 return argc | 757 return argc |
755 | 758 |
756 findDepth = StackDepthTracker().findDepth | 759 findDepth = StackDepthTracker().findDepth |
OLD | NEW |