4 from collections
import defaultdict
6 from graph
import Graph
7 from utils
import pairwise
, natural_sort_key
10 def node_name_strip(s
):
12 if s
[0] == '"' and s
[-1] == '"':
22 if l
.startswith("digraph"):
26 l
= re
.sub(r
"\[.+\]$", "", l
)
29 nodes
= [node_name_strip(n
) for n
in l
.split("->")]
31 for from_n
, to_n
in pairwise(nodes
, trailing
=False):
32 cfg
.add_edge(from_n
, to_n
)
38 with
open(sys
.argv
[1]) as f
:
41 all_nodes
= sorted(cfg
.nodes(), key
=natural_sort_key
)
43 for n
, next_n
in pairwise(all_nodes
):
51 print(" goto %s" % succ
[0])
54 succ
= [x
for x
in succ
if x
!= next_n
]
56 if len(succ
) == old_len
:
57 # next_n wasn't in succ
60 s
= ", ".join(["($cond) goto %s" % x
for x
in succ
])
62 s
+= ", else goto %s" % else_node
66 if __name__
== "__main__":