summaryrefslogtreecommitdiff
path: root/python/basicblock.py
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-02-18 00:41:37 -0500
committerRusty Wagner <rusty@vector35.com>2017-02-18 00:41:37 -0500
commit96f6bc8a3099754bf79a05af7a1ec342f8030335 (patch)
tree9ff52b5339140d453fb0163a0eb7bba3501d0a27 /python/basicblock.py
parentc46c3a9540f4d15eff8aa9660df69e374f7fd2f5 (diff)
Add back edge property to block edges
Diffstat (limited to 'python/basicblock.py')
-rw-r--r--python/basicblock.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/python/basicblock.py b/python/basicblock.py
index 9d48d3cb..e332cc3c 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -29,8 +29,9 @@ import function
class BasicBlockEdge(object):
- def __init__(self, branch_type, target):
+ def __init__(self, branch_type, source, target):
self.type = branch_type
+ self.source = source
self.target = target
def __repr__(self):
@@ -41,6 +42,11 @@ class BasicBlockEdge(object):
else:
return "<%s: %#x>" % (BranchType(self.type).name, self.target.start)
+ @property
+ def back_edge(self):
+ """Whether the edge is a back edge (end of a loop)"""
+ return self.target in self.source.dominators
+
class BasicBlock(object):
def __init__(self, view, handle):
@@ -108,7 +114,7 @@ class BasicBlock(object):
target = BasicBlock(self.view, core.BNNewBasicBlockReference(edges[i].target))
else:
target = None
- result.append(BasicBlockEdge(branch_type, target))
+ result.append(BasicBlockEdge(branch_type, self, target))
core.BNFreeBasicBlockEdgeList(edges, count.value)
return result
@@ -124,7 +130,7 @@ class BasicBlock(object):
target = BasicBlock(self.view, core.BNNewBasicBlockReference(edges[i].target))
else:
target = None
- result.append(BasicBlockEdge(branch_type, target))
+ result.append(BasicBlockEdge(branch_type, self, target))
core.BNFreeBasicBlockEdgeList(edges, count.value)
return result