From e2784f087a37f5436a8bf96dc8339cba5cf033ad Mon Sep 17 00:00:00 2001 From: Costa Shulyupin Date: Sun, 22 Jul 2018 17:16:40 +0300 Subject: [PATCH] reduce_graph --- srcxray.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/srcxray.py b/srcxray.py index d459792..34597a4 100755 --- a/srcxray.py +++ b/srcxray.py @@ -245,6 +245,17 @@ def my_graph(name=None): return g +def reduce_graph(g): + print(type(g)) + rm = set() + for e in g: + if not g.out_degree(e): + rm.add(e) + print(rm) + g.remove_nodes_from(rm) + return g + + def syscalls(): sc = my_graph('syscalls') scd = 'SYSCALL_DEFINE.list' @@ -293,11 +304,11 @@ def digraph_print(dg): def digraph_print_sub(node=None, printed=None, level=0): outs = [_ for _ in dg.successors(node)] if node in printed: - print_limited(level*'\t' + node + ' ^') + print_limited(level*'\t' + str(node) + ' ^') return else: s = ' ...' if level > level_limit - 2 and outs else '' - print_limited(level*'\t' + node + s) + print_limited(level*'\t' + str(node) + s) printed.add(node) if level > level_limit - 2: return ''