pub trait MirWithFlowState<'tcx> {
type BD: BitDenotation<'tcx>;
fn def_id(&self) -> DefId;
- fn mir(&self) -> &Body<'tcx>;
+ fn body(&self) -> &Body<'tcx>;
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>;
}
{
type BD = BD;
fn def_id(&self) -> DefId { self.def_id }
- fn mir(&self) -> &Body<'tcx> { self.flow_state.mir() }
+ fn body(&self) -> &Body<'tcx> { self.flow_state.body() }
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { &self.flow_state.flow_state }
}
-struct Graph<'a, 'tcx, MWF:'a, P> where
+struct Graph<'a, 'tcx, MWF, P> where
MWF: MirWithFlowState<'tcx>
{
mbcx: &'a MWF,
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Edge { source: BasicBlock, index: usize }
-fn outgoing(mir: &Body<'_>, bb: BasicBlock) -> Vec<Edge> {
- (0..mir[bb].terminator().successors().count())
+fn outgoing(body: &Body<'_>, bb: BasicBlock) -> Vec<Edge> {
+ (0..body[bb].terminator().successors().count())
.map(|index| Edge { source: bb, index: index}).collect()
}
// | [00-00] | _7 = const Foo::twiddle(move _8) | [0c-00] | [f3-0f] |
// +---------+----------------------------------+------------------+------------------+
let mut v = Vec::new();
- self.node_label_internal(n, &mut v, *n, self.mbcx.mir()).unwrap();
+ self.node_label_internal(n, &mut v, *n, self.mbcx.body()).unwrap();
dot::LabelText::html(String::from_utf8(v).unwrap())
}
}
fn edge_label(&'a self, e: &Edge) -> dot::LabelText<'a> {
- let term = self.mbcx.mir()[e.source].terminator();
+ let term = self.mbcx.body()[e.source].terminator();
let label = &term.kind.fmt_successor_labels()[e.index];
dot::LabelText::label(label.clone())
}
n: &Node,
w: &mut W,
block: BasicBlock,
- mir: &Body<'_>) -> io::Result<()> {
+ body: &Body<'_>) -> io::Result<()> {
// Header rows
const HDRS: [&str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"];
const HDR_FMT: &str = "bgcolor=\"grey\"";
write!(w, "</tr>")?;
// Data row
- self.node_label_verbose_row(n, w, block, mir)?;
- self.node_label_final_row(n, w, block, mir)?;
+ self.node_label_verbose_row(n, w, block, body)?;
+ self.node_label_final_row(n, w, block, body)?;
write!(w, "</table>")?;
Ok(())
n: &Node,
w: &mut W,
block: BasicBlock,
- mir: &Body<'_>)
+ body: &Body<'_>)
-> io::Result<()> {
let i = n.index();
// MIR statements
write!(w, "<td>")?;
{
- let data = &mir[block];
+ let data = &body[block];
for (i, statement) in data.statements.iter().enumerate() {
write!(w, "{}<br align=\"left\"/>",
dot::escape_html(&format!("{:3}: {:?}", i, statement)))?;
n: &Node,
w: &mut W,
block: BasicBlock,
- mir: &Body<'_>)
+ body: &Body<'_>)
-> io::Result<()> {
let i = n.index();
// Terminator
write!(w, "<td>")?;
{
- let data = &mir[block];
+ let data = &body[block];
let mut terminator_head = String::new();
data.terminator().kind.fmt_head(&mut terminator_head).unwrap();
write!(w, "{}", dot::escape_html(&terminator_head))?;
type Node = Node;
type Edge = Edge;
fn nodes(&self) -> dot::Nodes<'_, Node> {
- self.mbcx.mir()
+ self.mbcx.body()
.basic_blocks()
.indices()
.collect::<Vec<_>>()
}
fn edges(&self) -> dot::Edges<'_, Edge> {
- let mir = self.mbcx.mir();
+ let body = self.mbcx.body();
- mir.basic_blocks()
+ body.basic_blocks()
.indices()
- .flat_map(|bb| outgoing(mir, bb))
+ .flat_map(|bb| outgoing(body, bb))
.collect::<Vec<_>>()
.into()
}
}
fn target(&self, edge: &Edge) -> Node {
- let mir = self.mbcx.mir();
- *mir[edge.source].terminator().successors().nth(edge.index).unwrap()
+ let body = self.mbcx.body();
+ *body[edge.source].terminator().successors().nth(edge.index).unwrap()
}
}