Use DefId
to create globally unique basic block labels
This commit is contained in:
parent
cae898781f
commit
cbf69296cb
@ -55,12 +55,12 @@ where
|
||||
|
||||
// Nodes
|
||||
for (block, _) in body.basic_blocks().iter_enumerated() {
|
||||
write_node(block, body, w)?;
|
||||
write_node(def_id, block, body, w)?;
|
||||
}
|
||||
|
||||
// Edges
|
||||
for (source, _) in body.basic_blocks().iter_enumerated() {
|
||||
write_edges(source, body, w)?;
|
||||
write_edges(def_id, source, body, w)?;
|
||||
}
|
||||
writeln!(w, "}}")
|
||||
}
|
||||
@ -115,21 +115,33 @@ pub fn write_node_label<W: Write, INIT, FINI>(block: BasicBlock,
|
||||
}
|
||||
|
||||
/// Write a graphviz DOT node for the given basic block.
|
||||
fn write_node<W: Write>(block: BasicBlock, body: &Body<'_>, w: &mut W) -> io::Result<()> {
|
||||
fn write_node<W: Write>(
|
||||
def_id: DefId,
|
||||
block: BasicBlock,
|
||||
body: &Body<'_>,
|
||||
w: &mut W,
|
||||
) -> io::Result<()> {
|
||||
// Start a new node with the label to follow, in one of DOT's pseudo-HTML tables.
|
||||
write!(w, r#" {} [shape="none", label=<"#, node(block))?;
|
||||
write!(w, r#" {} [shape="none", label=<"#, node(def_id, block))?;
|
||||
write_node_label(block, body, w, 1, |_| Ok(()), |_| Ok(()))?;
|
||||
// Close the node label and the node itself.
|
||||
writeln!(w, ">];")
|
||||
}
|
||||
|
||||
/// Write graphviz DOT edges with labels between the given basic block and all of its successors.
|
||||
fn write_edges<W: Write>(source: BasicBlock, body: &Body<'_>, w: &mut W) -> io::Result<()> {
|
||||
fn write_edges<W: Write>(
|
||||
def_id: DefId,
|
||||
source: BasicBlock,
|
||||
body: &Body<'_>,
|
||||
w: &mut W,
|
||||
) -> io::Result<()> {
|
||||
let terminator = body[source].terminator();
|
||||
let labels = terminator.kind.fmt_successor_labels();
|
||||
|
||||
for (&target, label) in terminator.successors().zip(labels) {
|
||||
writeln!(w, r#" {} -> {} [label="{}"];"#, node(source), node(target), label)?;
|
||||
let src = node(def_id, source);
|
||||
let trg = node(def_id, target);
|
||||
writeln!(w, r#" {} -> {} [label="{}"];"#, src, trg, label)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -181,8 +193,8 @@ fn write_graph_label<'tcx, W: Write>(
|
||||
writeln!(w, ">;")
|
||||
}
|
||||
|
||||
fn node(block: BasicBlock) -> String {
|
||||
format!("bb{}", block.index())
|
||||
fn node(def_id: DefId, block: BasicBlock) -> String {
|
||||
format!("bb{}__{}", block.index(), graphviz_safe_def_name(def_id))
|
||||
}
|
||||
|
||||
fn escape<T: Debug>(t: &T) -> String {
|
||||
|
Loading…
x
Reference in New Issue
Block a user