diff options
| author | Ajax <commial@gmail.com> | 2018-06-11 12:25:36 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2018-06-11 12:25:36 +0200 |
| commit | 9907c7589f708dc409d641ddf1ccb5e165806072 (patch) | |
| tree | df03117e8beb449a5ddf624f1bc4e74c42b045e4 /miasm2/core/asmblock.py | |
| parent | 0c9d78d3a209176ee98b570e3c8ef423231213cb (diff) | |
| download | miasm-9907c7589f708dc409d641ddf1ccb5e165806072.tar.gz miasm-9907c7589f708dc409d641ddf1ccb5e165806072.zip | |
AsmCFG: use higher level API for merge
Diffstat (limited to '')
| -rw-r--r-- | miasm2/core/asmblock.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py index c2b7aa0a..22261927 100644 --- a/miasm2/core/asmblock.py +++ b/miasm2/core/asmblock.py @@ -667,14 +667,9 @@ class AsmCFG(DiGraph): def add_uniq_edge(self, src, dst, constraint): """ - Add an edge from @src to @dst if it doesn't already exist - @src: LocKey instance, source - @dst: LocKey instance, destination - @constraint: constraint associated to this edge + Synonym for `add_edge` """ - if (src not in self._nodes_succ or - dst not in self._nodes_succ[src]): - self.add_edge(src, dst, constraint) + self.add_edge(src, dst, constraint) def del_edge(self, src, dst): """Delete the edge @src->@dst and its associated constraint""" @@ -743,14 +738,16 @@ class AsmCFG(DiGraph): def merge(self, graph): """Merge with @graph, taking in account constraints""" + # Add known blocks + for block in graph.blocks: + self.add_block(block) + # Add nodes not already in it (ie. not linked to a block) + for node in graph.nodes(): + self.add_node(node) # -> add_edge(x, y, constraint) - self._loc_key_to_block.update(graph._loc_key_to_block) - for loc_key in graph._nodes: - self.add_node(loc_key) - if loc_key in graph._loc_key_to_block: - self.add_block(graph._loc_key_to_block[loc_key]) for edge in graph._edges: - # Use "_uniq_" beacause the edge can already exist due to add_node + # May fail if there is an incompatibility in edges constraints + # between the two graphs self.add_edge(*edge, constraint=graph.edges2constraint[edge]) |