From 9f55a12ab2efb1df00c68105a5a7f1520047b20a Mon Sep 17 00:00:00 2001 From: Griffin Berlstein Date: Thu, 16 May 2024 12:52:18 -0400 Subject: [PATCH] par stuff (#2043) --- .../src/flatten/structures/environment/env.rs | 32 ++++++++++++++++++- .../structures/environment/program_counter.rs | 16 +++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/interp/src/flatten/structures/environment/env.rs b/interp/src/flatten/structures/environment/env.rs index b0e5b82e97..22907eca5a 100644 --- a/interp/src/flatten/structures/environment/env.rs +++ b/interp/src/flatten/structures/environment/env.rs @@ -578,6 +578,9 @@ impl<'a> Simulator<'a> { // program counter as the size let mut leaf_nodes = vec![]; + let mut par_map = std::mem::take(self.env.pc.par_map_mut()); + let mut new_nodes = vec![]; + self.env.pc.vec_mut().retain_mut(|node| { // just considering a single node case for the moment match &self.env.ctx.primary[node.control_node_idx] { @@ -590,7 +593,29 @@ impl<'a> Simulator<'a> { node.mutate_into_next(self.env.ctx) } } - ControlNode::Par(_par) => todo!("not ready for par yet"), + ControlNode::Par(par) => { + if par_map.contains_key(node) { + let count = par_map.get_mut(node).unwrap(); + *count -= 1; + if *count == 0 { + par_map.remove(node); + node.mutate_into_next(self.env.ctx) + } else { + false + } + } else { + par_map.insert( + node.clone(), + par.stms().len().try_into().expect( + "More than (2^16 - 1 threads) in a par block. Are you sure this is a good idea?", + ), + ); + new_nodes.extend( + par.stms().iter().map(|x| node.new_retain_comp(*x)), + ); + false + } + } ControlNode::If(i) => { if i.cond_group().is_some() { todo!("if statement has a with clause") @@ -675,6 +700,11 @@ impl<'a> Simulator<'a> { } }); + // insert all the new nodes from the par into the program counter + self.env.pc.vec_mut().extend(new_nodes); + // return the par map to the program counter + *self.env.pc.par_map_mut() = par_map; + self.undef_all_ports(); for node in &leaf_nodes { diff --git a/interp/src/flatten/structures/environment/program_counter.rs b/interp/src/flatten/structures/environment/program_counter.rs index f93b01fbf9..c67c5d51e5 100644 --- a/interp/src/flatten/structures/environment/program_counter.rs +++ b/interp/src/flatten/structures/environment/program_counter.rs @@ -145,7 +145,7 @@ impl SearchPath { // par's child count should be decremented. The latter // seems more promising but I need to think on it more - todo!("need to deal with par") + return Some(*node); } ControlNode::If(_) => { // there is nothing to do when ascending to an if as it @@ -322,7 +322,7 @@ pub type ChildCount = u16; #[derive(Debug, Default)] pub(crate) struct ProgramCounter { vec: Vec, - _par_map: HashMap, + par_map: HashMap, } // we need a few things from the program counter @@ -349,7 +349,7 @@ impl ProgramCounter { Self { vec, - _par_map: HashMap::new(), + par_map: HashMap::new(), } } @@ -365,9 +365,17 @@ impl ProgramCounter { self.vec.iter_mut() } - pub(crate) fn vec_mut(&mut self) -> &mut Vec { + pub fn vec_mut(&mut self) -> &mut Vec { &mut self.vec } + + pub fn par_map_mut(&mut self) -> &mut HashMap { + &mut self.par_map + } + + pub fn _par_map(&self) -> &HashMap { + &self.par_map + } } impl<'a> IntoIterator for &'a ProgramCounter {