Improve graphviz rendering
This commit is contained in:
committed by
Nicolas B. Pierron
parent
3d42753535
commit
6042ee6f2d
@@ -1,10 +1,12 @@
|
|||||||
//! The `CFGPrinter` utility.
|
//! The `CFGPrinter` utility.
|
||||||
|
|
||||||
use core::fmt::{Display, Formatter, Result, Write};
|
use core::fmt::{Display, Formatter, Result, Write};
|
||||||
|
use std::vec::Vec;
|
||||||
|
|
||||||
|
use crate::entity::SecondaryMap;
|
||||||
use crate::flowgraph::{BasicBlock, ControlFlowGraph};
|
use crate::flowgraph::{BasicBlock, ControlFlowGraph};
|
||||||
use crate::ir::instructions::BranchInfo;
|
|
||||||
use crate::ir::Function;
|
use crate::ir::Function;
|
||||||
|
use crate::write::{FuncWriter, PlainWriter};
|
||||||
|
|
||||||
/// A utility for pretty-printing the CFG of a `Function`.
|
/// A utility for pretty-printing the CFG of a `Function`.
|
||||||
pub struct CFGPrinter<'a> {
|
pub struct CFGPrinter<'a> {
|
||||||
@@ -39,23 +41,21 @@ impl<'a> CFGPrinter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ebb_nodes(&self, w: &mut dyn Write) -> Result {
|
fn ebb_nodes(&self, w: &mut dyn Write) -> Result {
|
||||||
|
let mut aliases = SecondaryMap::<_, Vec<_>>::new();
|
||||||
|
for v in self.func.dfg.values() {
|
||||||
|
// VADFS returns the immediate target of an alias
|
||||||
|
if let Some(k) = self.func.dfg.value_alias_dest_for_serialization(v) {
|
||||||
|
aliases[k].push(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ebb in &self.func.layout {
|
for ebb in &self.func.layout {
|
||||||
write!(w, " {} [shape=record, label=\"{{{}", ebb, ebb)?;
|
write!(w, " {} [shape=record, label=\"{{", ebb)?;
|
||||||
|
crate::write::write_ebb_header(w, self.func, None, ebb, 4)?;
|
||||||
// Add all outgoing branch instructions to the label.
|
// Add all outgoing branch instructions to the label.
|
||||||
for inst in self.func.layout.ebb_insts(ebb) {
|
for inst in self.func.layout.ebb_insts(ebb) {
|
||||||
let idata = &self.func.dfg[inst];
|
write!(w, " | <{}>", inst)?;
|
||||||
match idata.analyze_branch(&self.func.dfg.value_lists) {
|
PlainWriter.write_instruction(w, self.func, &aliases, None, inst, 0)?;
|
||||||
BranchInfo::SingleDest(dest, _) => {
|
|
||||||
write!(w, " | <{}>{} {}", inst, idata.opcode(), dest)?
|
|
||||||
}
|
|
||||||
BranchInfo::Table(table, dest) => {
|
|
||||||
write!(w, " | <{}>{} {}", inst, idata.opcode(), table)?;
|
|
||||||
if let Some(dest) = dest {
|
|
||||||
write!(w, " {}", dest)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BranchInfo::NotABranch => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
writeln!(w, "}}\"]")?
|
writeln!(w, "}}\"]")?
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user