calyx_opt/passes/
add_guard.rs1use crate::traversal::{Action, Named, VisResult, Visitor};
2use calyx_ir as ir;
3
4#[derive(Default)]
5pub struct AddGuard;
6
7impl Named for AddGuard {
8 fn name() -> &'static str {
9 "add-guard"
10 }
11
12 fn description() -> &'static str {
13 "Add guard %[0: n] where n is latency of static component for each assignment in the static enable of static component."
14 }
15}
16
17impl Visitor for AddGuard {
18 fn start_static_control(
19 &mut self,
20 s: &mut ir::StaticControl,
21 comp: &mut ir::Component,
22 _sigs: &ir::LibrarySignatures,
23 _comps: &[ir::Component],
24 ) -> VisResult {
25 if comp.is_static() {
26 let latency = s.get_latency();
27 if let ir::StaticControl::Enable(sen) = s {
28 for assign in sen.group.borrow_mut().assignments.iter_mut() {
29 let g =
30 ir::Guard::Info(ir::StaticTiming::new((0, latency)));
31 let new_g = ir::Guard::And(
32 Box::new(g),
33 std::mem::replace(
34 &mut assign.guard,
35 Box::new(ir::Guard::True),
36 ),
37 );
38 assign.guard = Box::new(new_g);
39 }
40 }
41 }
42 Ok(Action::Continue)
43 }
44}