forked from libre-chip/fayalite
		
	make sim::Compiler not print things to stdout unless you ask for it
This commit is contained in:
		
							parent
							
								
									36bad52978
								
							
						
					
					
						commit
						9b06019bf5
					
				
					 1 changed files with 20 additions and 6 deletions
				
			
		|  | @ -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)] | ||||
| pub struct Compiler { | ||||
|     insns: Insns<InsnsBuilding>, | ||||
|  | @ -1622,6 +1630,7 @@ pub struct Compiler { | |||
|     registers: Vec<Register>, | ||||
|     traces: SimTraces<Vec<SimTrace<SimTraceKind, ()>>>, | ||||
|     memories: Vec<Memory>, | ||||
|     dump_assignments_dot: Option<DebugOpaque<Box<dyn Fn(&dyn fmt::Debug)>>>, | ||||
| } | ||||
| 
 | ||||
| impl Compiler { | ||||
|  | @ -1647,8 +1656,14 @@ impl Compiler { | |||
|             registers: Vec::new(), | ||||
|             traces: SimTraces(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 { | ||||
|         let id = TraceScalarId(self.traces.0.len()); | ||||
|         self.traces.0.push(SimTrace { | ||||
|  | @ -4650,12 +4665,11 @@ impl Compiler { | |||
|     fn process_assignments(&mut self) { | ||||
|         self.assignments | ||||
|             .finalize(self.insns.state_layout().ty.clone().into()); | ||||
|         println!( | ||||
|             "{:#?}", | ||||
|             petgraph::dot::Dot::new(&petgraph::graph::DiGraph::<_, _, usize>::from_elements( | ||||
|                 self.assignments.elements() | ||||
|             )) | ||||
|         ); | ||||
|         if let Some(DebugOpaque(dump_assignments_dot)) = &self.dump_assignments_dot { | ||||
|             let graph = | ||||
|                 petgraph::graph::DiGraph::<_, _, usize>::from_elements(self.assignments.elements()); | ||||
|             dump_assignments_dot(&petgraph::dot::Dot::new(&graph)); | ||||
|         } | ||||
|         let assignments_order: Vec<_> = match petgraph::algo::toposort(&self.assignments, None) { | ||||
|             Ok(nodes) => nodes | ||||
|                 .into_iter() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue