|
@@ -11,9 +11,9 @@ class Instruction(object):
|
|
|
next instruction."""
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
- def get_reachable(self):
|
|
|
+ def get_reachable(self, filter_children=lambda _: True):
|
|
|
"""Gets the set of all instructions that are reachable from the given instruction, including
|
|
|
- this instruction."""
|
|
|
+ this instruction. A function can be used to filter out certain instructions' children."""
|
|
|
results = set()
|
|
|
stack = [self]
|
|
|
while len(stack) > 0:
|
|
@@ -22,10 +22,12 @@ class Instruction(object):
|
|
|
next_instr = instr.next_instruction
|
|
|
if next_instr is not None and next_instr not in results:
|
|
|
stack.append(next_instr)
|
|
|
- for other in instr.get_directly_reachable():
|
|
|
- if other not in results:
|
|
|
- assert other is not None
|
|
|
- stack.append(other)
|
|
|
+
|
|
|
+ if filter_children(instr):
|
|
|
+ for other in instr.get_directly_reachable():
|
|
|
+ if other not in results:
|
|
|
+ assert other is not None
|
|
|
+ stack.append(other)
|
|
|
|
|
|
return results
|
|
|
|