"dump MIR state at various points in translation"),
dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
"the directory the MIR is dumped into"),
+ dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
+ "additionally to `.mir` files, create graphviz `.dot` files"),
dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
"if set, exclude the pass number when dumping MIR (used in tests)"),
mir_emit_validate: usize = (0, parse_uint, [TRACKED],
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.dump_mir_dir = Some(String::from("abc"));
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
+ opts.debugging_opts.dump_mir_graphviz = true;
+ assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
// Make sure changing a [TRACKED] option changes the hash
opts = reference.clone();
for def_id in dump_mir_def_ids(tcx, single) {
let nodeid = tcx.hir.as_local_node_id(def_id).unwrap();
let mir = &tcx.optimized_mir(def_id);
+ write_mir_fn_graphviz(tcx, nodeid, mir, w)?;
+ }
+ Ok(())
+}
- writeln!(w, "digraph Mir_{} {{", nodeid)?;
+/// Write a graphviz DOT graph of the MIR.
+pub fn write_mir_fn_graphviz<'a, 'tcx, W>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+ nodeid: NodeId,
+ mir: &Mir,
+ w: &mut W) -> io::Result<()>
+ where W: Write
+{
+ writeln!(w, "digraph Mir_{} {{", nodeid)?;
- // Global graph properties
- writeln!(w, r#" graph [fontname="monospace"];"#)?;
- writeln!(w, r#" node [fontname="monospace"];"#)?;
- writeln!(w, r#" edge [fontname="monospace"];"#)?;
+ // Global graph properties
+ writeln!(w, r#" graph [fontname="monospace"];"#)?;
+ writeln!(w, r#" node [fontname="monospace"];"#)?;
+ writeln!(w, r#" edge [fontname="monospace"];"#)?;
- // Graph label
- write_graph_label(tcx, nodeid, mir, w)?;
+ // Graph label
+ write_graph_label(tcx, nodeid, mir, w)?;
- // Nodes
- for (block, _) in mir.basic_blocks().iter_enumerated() {
- write_node(block, mir, w)?;
- }
+ // Nodes
+ for (block, _) in mir.basic_blocks().iter_enumerated() {
+ write_node(block, mir, w)?;
+ }
- // Edges
- for (source, _) in mir.basic_blocks().iter_enumerated() {
- write_edges(source, mir, w)?;
- }
- writeln!(w, "}}")?
+ // Edges
+ for (source, _) in mir.basic_blocks().iter_enumerated() {
+ write_edges(source, mir, w)?;
}
- Ok(())
+ writeln!(w, "}}")
}
/// Write a graphviz HTML-styled label for the given basic block, with
use std::fs;
use std::io::{self, Write};
use std::path::{PathBuf, Path};
+use super::graphviz::write_mir_fn_graphviz;
const INDENT: &'static str = " ";
/// Alignment for lining up comments following MIR statements
write_mir_fn(tcx, source, mir, &mut file)?;
Ok(())
});
+
+ if tcx.sess.opts.debugging_opts.dump_mir_graphviz {
+ file_path.set_extension("dot");
+ let _ = fs::File::create(&file_path).and_then(|mut file| {
+ write_mir_fn_graphviz(tcx, source.item_id(), mir, &mut file)?;
+ Ok(())
+ });
+ }
}
/// Write out a human-readable textual representation for the given MIR.