diff options
| author | Ajax <commial@gmail.com> | 2016-01-20 10:14:43 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-01-27 11:12:18 +0100 |
| commit | f95130b2fe6db1abcb64c02304fc3af72f1e4e8f (patch) | |
| tree | 7c1a7d14b2daa94536ca22679266af25166ecd14 | |
| parent | 51ec4ba8e1d9c0ddfaf23a25b3827c2bbff4e067 (diff) | |
| download | miasm-f95130b2fe6db1abcb64c02304fc3af72f1e4e8f.tar.gz miasm-f95130b2fe6db1abcb64c02304fc3af72f1e4e8f.zip | |
Rewrite _merge_blocks using MatchGraph
Conflicts: miasm2/core/asmbloc.py
| -rw-r--r-- | miasm2/core/asmbloc.py | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py index 9553d14d..aa26cfbf 100644 --- a/miasm2/core/asmbloc.py +++ b/miasm2/core/asmbloc.py @@ -10,7 +10,7 @@ import miasm2.expression.expression as m2_expr from miasm2.expression.simplifications import expr_simp from miasm2.expression.modint import moduint, modint from miasm2.core.utils import Disasm_Exception, pck -from miasm2.core.graph import DiGraph, DiGraphSimplifier +from miasm2.core.graph import DiGraph, DiGraphSimplifier, MatchGraphJoker from miasm2.core.interval import interval @@ -980,27 +980,22 @@ class AsmCFG(DiGraph): if rebuild_needed: self.rebuild_edges() -def _merge_blocks(dg, graph): - for block in graph.nodes(): +# Out of _merge_blocks to be computed only once +_acceptable_block = lambda block: (not isinstance(block, asm_block_bad) and + len(block.lines) > 0) +_parent = MatchGraphJoker(restrict_in=False, filt=_acceptable_block) +_son = MatchGraphJoker(restrict_out=False, filt=_acceptable_block) +_expgraph = _parent >> _son - # Acceptable block - if isinstance(block, asm_block_bad) or len(block.lines) == 0: - continue - # Only one son, not me - succs = graph.successors(block) - if len(succs) != 1: - continue - succ = succs[0] - if succ == block: - continue +def _merge_blocks(dg, graph): + """Graph simplification merging asm_bloc with one and only one son with this + son if this son has one and only one parent""" + for match in _expgraph.match(graph): - # Son has only one parent, me - preds = graph.predecessors(succ) - if len(preds) != 1: - continue - assert preds[0] == block + # Get matching blocks + block, succ = match[_parent], match[_son] # Remove block last instruction if needed last_instr = block.lines[-1] |