diff options
Diffstat (limited to '')
| -rw-r--r-- | miasm2/ir/analysis.py | 14 | ||||
| -rw-r--r-- | miasm2/ir/ir.py | 18 |
2 files changed, 17 insertions, 15 deletions
diff --git a/miasm2/ir/analysis.py b/miasm2/ir/analysis.py index 9844f58f..40a3bf64 100644 --- a/miasm2/ir/analysis.py +++ b/miasm2/ir/analysis.py @@ -61,12 +61,12 @@ class ira(ir): useful = set() - for node in self.g.nodes(): + for node in self.graph.nodes(): if node not in self.blocs: continue block = self.blocs[node] - successors = self.g.successors(node) + successors = self.graph.successors(node) has_son = bool(successors) for p_son in successors: if p_son not in self.blocs: @@ -186,7 +186,7 @@ class ira(ir): for key, value in irb.cur_reach[0].iteritems()} # Compute reach from predecessors - for n_pred in self.g.predecessors(irb.label): + for n_pred in self.graph.predecessors(irb.label): p_block = self.blocs[n_pred] # Handle each register definition @@ -225,7 +225,7 @@ class ira(ir): analysis""" fixed = True - for node in self.g.nodes(): + for node in self.graph.nodes(): if node in self.blocs: irb = self.blocs[node] if (irb.cur_reach != irb.prev_reach or @@ -241,13 +241,11 @@ class ira(ir): Source : Kennedy, K. (1979). A survey of data flow analysis techniques. IBM Thomas J. Watson Research Division, page 43 - - PRE: gen_graph() """ fixed_point = False log.debug('iteration...') while not fixed_point: - for node in self.g.nodes(): + for node in self.graph.nodes(): if node in self.blocs: self.compute_reach_block(self.blocs[node]) fixed_point = self._test_kill_reach_fix() @@ -259,8 +257,6 @@ class ira(ir): Source : Kennedy, K. (1979). A survey of data flow analysis techniques. IBM Thomas J. Watson Research Division, page 43 - - PRE: gen_graph() """ # Update r/w variables for all irblocs self.get_rw(self.ira_regs_ids()) diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py index c2bc96b6..eec24ba0 100644 --- a/miasm2/ir/ir.py +++ b/miasm2/ir/ir.py @@ -172,6 +172,8 @@ class ir(object): self.sp = arch.getsp(attrib) self.arch = arch self.attrib = attrib + # Lazy structure + self._graph = None def instr2ir(self, l): ir_bloc_cur, ir_blocs_extra = self.get_ir(l) @@ -421,14 +423,14 @@ class ir(object): return done - def gen_graph(self, link_all = True): + def _gen_graph(self, link_all = True): """ Gen irbloc digraph @link_all: also gen edges to non present irblocs """ - self.g = DiGraphIR(self.blocs) + self._graph = DiGraphIR(self.blocs) for lbl, b in self.blocs.items(): - self.g.add_node(lbl) + self._graph.add_node(lbl) dst = self.dst_trackback(b) for d in dst: if isinstance(d, m2_expr.ExprInt): @@ -436,8 +438,12 @@ class ir(object): self.symbol_pool.getby_offset_create(int(d.arg))) if asmbloc.expr_is_label(d): if d.name in self.blocs or link_all is True: - self.g.add_edge(lbl, d.name) + self._graph.add_edge(lbl, d.name) + @property def graph(self): - """Output the graphviz script""" - return self.g.dot() + """Get a DiGraph representation of current IR instance. + Lazy property, building the graph on-demand""" + if self._graph is None: + self._gen_graph() + return self._graph |