pulsar_backend/calyx/builder/
macros.rs

1// calyx `build_assignments!` but for `CalyxCell`s.
2#[macro_export(local_inner_macros)]
3macro_rules! build_assignments_2_aux {
4    // Unguarded assignment.
5    (@base $builder:expr;
6     $dst_node:ident[$dst_port:expr] = ? $src_node:ident[$src_port:expr]) => {
7        $builder.build_assignment(
8            $dst_node.value.borrow().get($dst_port),
9            $src_node.value.borrow().get($src_port),
10            calyx_ir::Guard::True)
11    };
12
13    // Guarded assignment.
14    (@base $builder:expr;
15     $dst_node:ident[$dst_port:expr] =
16        $guard:ident ?
17        $src_node:ident[$src_port:expr]) => {
18        $builder.build_assignment(
19            $dst_node.value.borrow().get($dst_port),
20            $src_node.value.borrow().get($src_port),
21            $guard.clone())
22    };
23
24    ($builder:expr;
25     $($dst_node:ident[$dst_port:expr] =
26         $($guard:ident)? ?
27         $src_node:ident[$src_port:expr];)*)  => {
28        [$(
29            build_assignments_2_aux!(@base $builder;
30                $dst_node[$dst_port] = $($guard)? ? $src_node[$src_port])
31        ),*]
32
33    };
34}
35
36/// Behaves like [`calyx_ir::build_assignments!`] but takes in a
37/// [`CalyxComponent`] instead of a [`calyx_ir::Builder`] and uses
38/// [`CalyxCell`]s instead of `RRC<calyx_ir::Cell>`s.
39#[macro_export(local_inner_macros)]
40macro_rules! build_assignments_2 {
41    ($component:expr; $($args:tt)*) => {
42        $component.with_calyx_builder(|builder| {
43            build_assignments_2_aux!(builder; $($args)*)
44        })
45    }
46}