@@ -30,29 +30,38 @@ pub fn write_mir_graphviz<'a, 'tcx, W>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
30
30
for def_id in dump_mir_def_ids ( tcx, single) {
31
31
let nodeid = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
32
32
let mir = & tcx. optimized_mir ( def_id) ;
33
+ write_mir_fn_graphviz ( tcx, nodeid, mir, w) ?;
34
+ }
35
+ Ok ( ( ) )
36
+ }
33
37
34
- writeln ! ( w, "digraph Mir_{} {{" , nodeid) ?;
38
+ /// Write a graphviz DOT graph of the MIR.
39
+ pub fn write_mir_fn_graphviz < ' a , ' tcx , W > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
40
+ nodeid : NodeId ,
41
+ mir : & Mir ,
42
+ w : & mut W ) -> io:: Result < ( ) >
43
+ where W : Write
44
+ {
45
+ writeln ! ( w, "digraph Mir_{} {{" , nodeid) ?;
35
46
36
- // Global graph properties
37
- writeln ! ( w, r#" graph [fontname="monospace"];"# ) ?;
38
- writeln ! ( w, r#" node [fontname="monospace"];"# ) ?;
39
- writeln ! ( w, r#" edge [fontname="monospace"];"# ) ?;
47
+ // Global graph properties
48
+ writeln ! ( w, r#" graph [fontname="monospace"];"# ) ?;
49
+ writeln ! ( w, r#" node [fontname="monospace"];"# ) ?;
50
+ writeln ! ( w, r#" edge [fontname="monospace"];"# ) ?;
40
51
41
- // Graph label
42
- write_graph_label ( tcx, nodeid, mir, w) ?;
52
+ // Graph label
53
+ write_graph_label ( tcx, nodeid, mir, w) ?;
43
54
44
- // Nodes
45
- for ( block, _) in mir. basic_blocks ( ) . iter_enumerated ( ) {
46
- write_node ( block, mir, w) ?;
47
- }
55
+ // Nodes
56
+ for ( block, _) in mir. basic_blocks ( ) . iter_enumerated ( ) {
57
+ write_node ( block, mir, w) ?;
58
+ }
48
59
49
- // Edges
50
- for ( source, _) in mir. basic_blocks ( ) . iter_enumerated ( ) {
51
- write_edges ( source, mir, w) ?;
52
- }
53
- writeln ! ( w, "}}" ) ?
60
+ // Edges
61
+ for ( source, _) in mir. basic_blocks ( ) . iter_enumerated ( ) {
62
+ write_edges ( source, mir, w) ?;
54
63
}
55
- Ok ( ( ) )
64
+ writeln ! ( w , "}}" )
56
65
}
57
66
58
67
/// Write a graphviz HTML-styled label for the given basic block, with
0 commit comments