def draw_cfg(cfg, output_filename = 'output'):
"""Draw CFG and output as pdf."""
graph = Digraph(format='pdf')
for node in cfg.nodes:
stripped_label = node.label.replace(IGNORED_LABEL_NAME_CHARACHTERS, '')
if 'Exit' in stripped_label:
graph.node(stripped_label, 'Exit', shape='none')
elif 'Entry' in stripped_label:
graph.node(stripped_label, 'Entry', shape='none')
else:
graph.node(stripped_label, stripped_label)
for ingoing_node in node.ingoing:
graph.edge(ingoing_node.label.replace(IGNORED_LABEL_NAME_CHARACHTERS, ''), stripped_label)
graph = apply_styles(graph, cfg_styles)
graph.render(filename = output_filename)
评论列表
文章目录