make sim::Compiler not print things to stdout unless you ask for it
This commit is contained in:
parent
36bad52978
commit
9b06019bf5
|
@ -1601,6 +1601,14 @@ impl MakeTraceDeclTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DebugOpaque<T>(T);
|
||||||
|
|
||||||
|
impl<T> fmt::Debug for DebugOpaque<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str("<...>")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Compiler {
|
pub struct Compiler {
|
||||||
insns: Insns<InsnsBuilding>,
|
insns: Insns<InsnsBuilding>,
|
||||||
|
@ -1622,6 +1630,7 @@ pub struct Compiler {
|
||||||
registers: Vec<Register>,
|
registers: Vec<Register>,
|
||||||
traces: SimTraces<Vec<SimTrace<SimTraceKind, ()>>>,
|
traces: SimTraces<Vec<SimTrace<SimTraceKind, ()>>>,
|
||||||
memories: Vec<Memory>,
|
memories: Vec<Memory>,
|
||||||
|
dump_assignments_dot: Option<DebugOpaque<Box<dyn Fn(&dyn fmt::Debug)>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Compiler {
|
impl Compiler {
|
||||||
|
@ -1647,8 +1656,14 @@ impl Compiler {
|
||||||
registers: Vec::new(),
|
registers: Vec::new(),
|
||||||
traces: SimTraces(Vec::new()),
|
traces: SimTraces(Vec::new()),
|
||||||
memories: Vec::new(),
|
memories: Vec::new(),
|
||||||
|
dump_assignments_dot: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// This is explicitly unstable and may be changed/removed at any time
|
||||||
|
pub fn dump_assignments_dot(&mut self, callback: Box<dyn Fn(&dyn fmt::Debug)>) {
|
||||||
|
self.dump_assignments_dot = Some(DebugOpaque(callback));
|
||||||
|
}
|
||||||
fn new_sim_trace(&mut self, kind: SimTraceKind) -> TraceScalarId {
|
fn new_sim_trace(&mut self, kind: SimTraceKind) -> TraceScalarId {
|
||||||
let id = TraceScalarId(self.traces.0.len());
|
let id = TraceScalarId(self.traces.0.len());
|
||||||
self.traces.0.push(SimTrace {
|
self.traces.0.push(SimTrace {
|
||||||
|
@ -4650,12 +4665,11 @@ impl Compiler {
|
||||||
fn process_assignments(&mut self) {
|
fn process_assignments(&mut self) {
|
||||||
self.assignments
|
self.assignments
|
||||||
.finalize(self.insns.state_layout().ty.clone().into());
|
.finalize(self.insns.state_layout().ty.clone().into());
|
||||||
println!(
|
if let Some(DebugOpaque(dump_assignments_dot)) = &self.dump_assignments_dot {
|
||||||
"{:#?}",
|
let graph =
|
||||||
petgraph::dot::Dot::new(&petgraph::graph::DiGraph::<_, _, usize>::from_elements(
|
petgraph::graph::DiGraph::<_, _, usize>::from_elements(self.assignments.elements());
|
||||||
self.assignments.elements()
|
dump_assignments_dot(&petgraph::dot::Dot::new(&graph));
|
||||||
))
|
}
|
||||||
);
|
|
||||||
let assignments_order: Vec<_> = match petgraph::algo::toposort(&self.assignments, None) {
|
let assignments_order: Vec<_> = match petgraph::algo::toposort(&self.assignments, None) {
|
||||||
Ok(nodes) => nodes
|
Ok(nodes) => nodes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
Loading…
Reference in a new issue