From 1c0f525e57f1d1faeacbd0163c4f5d7f3cf0b976 Mon Sep 17 00:00:00 2001 From: Joe Fioti Date: Tue, 16 Jan 2024 09:03:41 -0600 Subject: [PATCH] Added looped compiler --- src/core/compiler_utils.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/core/compiler_utils.rs b/src/core/compiler_utils.rs index a0f1c8ec..6ebb3831 100644 --- a/src/core/compiler_utils.rs +++ b/src/core/compiler_utils.rs @@ -140,10 +140,34 @@ impl Compiler for () { fn compile(&self, _: &mut Graph, _: T) {} } +/// Wrap this around a compiler to rerun the compiler until it doesn't change the graph anymore +pub struct Looped(C); + +impl Compiler for Looped { + fn compile(&self, graph: &mut Graph, mut remap: T) { + graph.toposort(); + let mut linearized = graph.linearized_graph.clone(); + loop { + self.0.compile(graph, &mut remap); + graph.toposort(); + if linearized == graph.linearized_graph { + break; + } + linearized = graph.linearized_graph.clone(); + } + } +} + +impl Default for Looped { + fn default() -> Self { + Self(C::default()) + } +} + /// Wrap this around a compiler to measure the time it takes to compile -pub struct TimedCompiler(C); +pub struct Timed(C); -impl Compiler for TimedCompiler { +impl Compiler for Timed { fn compile(&self, graph: &mut Graph, remap: T) { let compiler_name = format!("{:?}", self.0).bold(); println!("Starting {compiler_name}"); @@ -167,7 +191,7 @@ impl Compiler for TimedCompiler { } } -impl Default for TimedCompiler { +impl Default for Timed { fn default() -> Self { Self(C::default()) }