|
@@ -149,6 +149,11 @@ class Definition(object):
|
|
|
"""Tells if this definition produces a result that is not None."""
|
|
|
return self.value.has_value()
|
|
|
|
|
|
+ def has_bidirectional_dependencies(self):
|
|
|
+ """Tells if this instruction's dependencies are bidirectional."""
|
|
|
+ return (not isinstance(self.value, Definition)
|
|
|
+ and self.value.has_bidirectional_dependencies())
|
|
|
+
|
|
|
def insert_before(self, value):
|
|
|
"""Inserts the given value or definition before this definition."""
|
|
|
return self.block.insert_definition_before(self, value)
|
|
@@ -218,6 +223,10 @@ class FlowInstruction(Instruction):
|
|
|
"""Gets a list of basic blocks targeted by this flow instruction."""
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
+ def has_bidirectional_dependencies(self):
|
|
|
+ """Tells if this instruction's dependencies are bidirectional."""
|
|
|
+ return False
|
|
|
+
|
|
|
def has_side_effects(self):
|
|
|
"""Tells if this instruction has side-effects."""
|
|
|
# All flow-instructions have side-effects!
|
|
@@ -349,6 +358,11 @@ class Value(Instruction):
|
|
|
"""Tells if this instruction has side-effects."""
|
|
|
return False
|
|
|
|
|
|
+ def has_bidirectional_dependencies(self):
|
|
|
+ """Tells if this value has bidirectional dependencies: if so, then all dependencies
|
|
|
+ of this node on another node are also dependencies of that node on this node."""
|
|
|
+ return False
|
|
|
+
|
|
|
def ref_str(self):
|
|
|
"""Gets a string that represents this value."""
|
|
|
return str(self)
|
|
@@ -558,8 +572,9 @@ class DeallocateRootNode(Value):
|
|
|
"""Tells if this value produces a result that is not None."""
|
|
|
return False
|
|
|
|
|
|
- def has_side_effects(self):
|
|
|
- """Tells if this instruction has side-effects."""
|
|
|
+ def has_bidirectional_dependencies(self):
|
|
|
+ """Tells if this value has bidirectional dependencies: if so, then all dependencies
|
|
|
+ of this node on another node are also dependencies of that node on this node."""
|
|
|
return True
|
|
|
|
|
|
def __str__(self):
|
|
@@ -750,6 +765,31 @@ class CreateNode(Value):
|
|
|
def __str__(self):
|
|
|
return 'create-node %s' % (self.value.ref_str())
|
|
|
|
|
|
+class CreateEdge(Value):
|
|
|
+ """A value that creates a new edge."""
|
|
|
+ def __init__(self, source, target):
|
|
|
+ Value.__init__(self)
|
|
|
+ self.source = source
|
|
|
+ assert isinstance(source, Definition)
|
|
|
+ self.target = target
|
|
|
+ assert isinstance(target, Definition)
|
|
|
+
|
|
|
+ def get_dependencies(self):
|
|
|
+ """Gets all definitions and instructions on which this instruction depends."""
|
|
|
+ return [self.source, self.target]
|
|
|
+
|
|
|
+ def create(self, new_dependencies):
|
|
|
+ """Creates an instruction of this type from the given set of dependencies."""
|
|
|
+ return CreateEdge(*new_dependencies)
|
|
|
+
|
|
|
+ def has_bidirectional_dependencies(self):
|
|
|
+ """Tells if this value has bidirectional dependencies: if so, then all dependencies
|
|
|
+ of this node on another node are also dependencies of that node on this node."""
|
|
|
+ return True
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ return 'create-edge %s, %s' % (self.source.ref_str(), self.target.ref_str())
|
|
|
+
|
|
|
class Binary(Value):
|
|
|
"""A value that applies a binary operator to two other values."""
|
|
|
def __init__(self, lhs, operator, rhs):
|