use dot;
use rustc::mir::repr::*;
-use rustc::ty;
+use rustc::ty::{self, TyCtxt};
use std::fmt::Debug;
use std::io::{self, Write};
use syntax::ast::NodeId;
+use rustc_data_structures::indexed_vec::Idx;
+
/// Write a graphviz DOT graph of a list of MIRs.
-pub fn write_mir_graphviz<'a, 't, W, I>(tcx: &ty::TyCtxt<'t>, iter: I, w: &mut W) -> io::Result<()>
+pub fn write_mir_graphviz<'a, 'b, 'tcx, W, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
+ iter: I, w: &mut W)
+ -> io::Result<()>
where W: Write, I: Iterator<Item=(&'a NodeId, &'a Mir<'a>)> {
for (&nodeid, mir) in iter {
writeln!(w, "digraph Mir_{} {{", nodeid)?;
write_graph_label(tcx, nodeid, mir, w)?;
// Nodes
- for block in mir.all_basic_blocks() {
+ for (block, _) in mir.basic_blocks().iter_enumerated() {
write_node(block, mir, w)?;
}
// Edges
- for source in mir.all_basic_blocks() {
+ for (source, _) in mir.basic_blocks().iter_enumerated() {
write_edges(source, mir, w)?;
}
writeln!(w, "}}")?
where INIT: Fn(&mut W) -> io::Result<()>,
FINI: Fn(&mut W) -> io::Result<()>
{
- let data = mir.basic_block_data(block);
+ let data = &mir[block];
write!(w, r#"<table border="0" cellborder="1" cellspacing="0">"#)?;
/// Write graphviz DOT edges with labels between the given basic block and all of its successors.
fn write_edges<W: Write>(source: BasicBlock, mir: &Mir, w: &mut W) -> io::Result<()> {
- let terminator = &mir.basic_block_data(source).terminator();
+ let terminator = mir[source].terminator();
let labels = terminator.kind.fmt_successor_labels();
for (&target, label) in terminator.successors().iter().zip(labels) {
/// 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<W: Write>(tcx: &ty::TyCtxt, nid: NodeId, mir: &Mir, w: &mut W)
--> io::Result<()> {
+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 argument types.
if i > 0 {
write!(w, ", ")?;
}
- write!(w, "{:?}: {}", Lvalue::Arg(i as u32), escape(&arg.ty))?;
+ write!(w, "{:?}: {}", Lvalue::Arg(Arg::new(i)), escape(&arg.ty))?;
}
write!(w, ") -> ")?;
write!(w, "mut ")?;
}
write!(w, r#"{:?}: {}; // {}<br align="left"/>"#,
- Lvalue::Var(i as u32), escape(&var.ty), var.name)?;
+ Lvalue::Var(Var::new(i)), escape(&var.ty), var.name)?;
}
// Compiler-introduced temporary types.
for (i, temp) in mir.temp_decls.iter().enumerate() {
write!(w, r#"let mut {:?}: {};<br align="left"/>"#,
- Lvalue::Temp(i as u32), escape(&temp.ty))?;
+ Lvalue::Temp(Temp::new(i)), escape(&temp.ty))?;
}
writeln!(w, ">;")