Run the filetests as part of "cargo test".
Refactor the filetests harness so that it can be run as part of `cargo test`. And begin reorganizing the test harness code in preparation for moving it out of the src directory. - Test subcommand files are now named `test_*.rs`. - cton-util subcommand files now just export their `run` and nothing else. - src/filetest/mod.rs now also just exports `run` and nothing else. - Tests are now run in release mode (with debug assertions enabled).
This commit is contained in:
76
lib/cretonne/src/cfg_printer.rs
Normal file
76
lib/cretonne/src/cfg_printer.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
//! The `CFGPrinter` utility.
|
||||
|
||||
use std::fmt::{Result, Write, Display, Formatter};
|
||||
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use ir::Function;
|
||||
use ir::instructions::BranchInfo;
|
||||
|
||||
/// A utility for pretty-printing the CFG of a `Function`.
|
||||
pub struct CFGPrinter<'a> {
|
||||
func: &'a Function,
|
||||
cfg: ControlFlowGraph,
|
||||
}
|
||||
|
||||
/// A utility for pretty-printing the CFG of a `Function`.
|
||||
impl<'a> CFGPrinter<'a> {
|
||||
/// Create a new CFGPrinter.
|
||||
pub fn new(func: &'a Function) -> CFGPrinter<'a> {
|
||||
CFGPrinter {
|
||||
func,
|
||||
cfg: ControlFlowGraph::with_function(func),
|
||||
}
|
||||
}
|
||||
|
||||
/// Write the CFG for this function to `w`.
|
||||
pub fn write(&self, w: &mut Write) -> Result {
|
||||
self.header(w)?;
|
||||
self.ebb_nodes(w)?;
|
||||
self.cfg_connections(w)?;
|
||||
writeln!(w, "}}")
|
||||
}
|
||||
|
||||
fn header(&self, w: &mut Write) -> Result {
|
||||
writeln!(w, "digraph \"{}\" {{", self.func.name)?;
|
||||
if let Some(entry) = self.func.layout.entry_block() {
|
||||
writeln!(w, " {{rank=min; {}}}", entry)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ebb_nodes(&self, w: &mut Write) -> Result {
|
||||
for ebb in &self.func.layout {
|
||||
write!(w, " {} [shape=record, label=\"{{{}", ebb, ebb)?;
|
||||
// Add all outgoing branch instructions to the label.
|
||||
for inst in self.func.layout.ebb_insts(ebb) {
|
||||
let idata = &self.func.dfg[inst];
|
||||
match idata.analyze_branch(&self.func.dfg.value_lists) {
|
||||
BranchInfo::SingleDest(dest, _) => {
|
||||
write!(w, " | <{}>{} {}", inst, idata.opcode(), dest)?
|
||||
}
|
||||
BranchInfo::Table(table) => {
|
||||
write!(w, " | <{}>{} {}", inst, idata.opcode(), table)?
|
||||
}
|
||||
BranchInfo::NotABranch => {}
|
||||
}
|
||||
}
|
||||
writeln!(w, "}}\"]")?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cfg_connections(&self, w: &mut Write) -> Result {
|
||||
for ebb in &self.func.layout {
|
||||
for (parent, inst) in self.cfg.pred_iter(ebb) {
|
||||
writeln!(w, " {}:{} -> {}", parent, inst, ebb)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for CFGPrinter<'a> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
self.write(f)
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ pub mod entity;
|
||||
|
||||
pub mod bforest;
|
||||
pub mod binemit;
|
||||
pub mod cfg_printer;
|
||||
pub mod cursor;
|
||||
pub mod dominator_tree;
|
||||
pub mod flowgraph;
|
||||
|
||||
Reference in New Issue
Block a user