use rustc::ty::TyCtxt;
use std::fmt::Debug;
use std::io::{self, Write};
-use syntax::ast::NodeId;
use rustc_data_structures::indexed_vec::Idx;
use super::pretty::dump_mir_def_ids;
/// Write a graphviz DOT graph of a list of MIRs.
-pub fn write_mir_graphviz<'a, 'tcx, W>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
- single: Option<DefId>,
- w: &mut W)
- -> io::Result<()>
+pub fn write_mir_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>,
+ single: Option<DefId>,
+ w: &mut W)
+ -> io::Result<()>
where W: Write
{
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, def_id, mir, w)?;
+ }
+ Ok(())
+}
- writeln!(w, "digraph Mir_{} {{", nodeid)?;
+/// Write a graphviz DOT graph of the MIR.
+pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>,
+ def_id: DefId,
+ mir: &Mir,
+ w: &mut W) -> io::Result<()>
+ where W: Write
+{
+ writeln!(w, "digraph Mir_{} {{", tcx.hir.as_local_node_id(def_id).unwrap())?;
- // 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, def_id, 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
/// Write the graphviz DOT label for the overall graph. This is essentially a block of text that
/// will appear below the graph, showing the type of the `fn` this MIR represents and the types of
/// all the variables and temporaries.
-fn write_graph_label<'a, 'tcx, W: Write>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
- nid: NodeId,
- mir: &Mir,
- w: &mut W)
- -> io::Result<()> {
- write!(w, " label=<fn {}(", dot::escape_html(&tcx.node_path_str(nid)))?;
+fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
+ def_id: DefId,
+ mir: &Mir,
+ w: &mut W)
+ -> io::Result<()> {
+ write!(w, " label=<fn {}(", dot::escape_html(&tcx.item_path_str(def_id)))?;
// fn argument types.
for (i, arg) in mir.args_iter().enumerate() {
write!(w, "{:?}: {}", Lvalue::Local(arg), escape(&mir.local_decls[arg].ty))?;
}
- write!(w, ") -> {}", escape(mir.return_ty))?;
+ write!(w, ") -> {}", escape(mir.return_ty()))?;
write!(w, r#"<br align="left"/>"#)?;
for local in mir.vars_and_temps_iter() {