1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use hugr::{
    builder::{BuildError, Dataflow},
    extension::simple_op::HasConcrete as _,
    std_extensions::arithmetic::int_ops::IntOpDef,
    types::TypeArg,
    Wire,
};

pub trait IntOpBuilder: Dataflow {
    fn add_iadd(
        &mut self,
        log_width: impl Into<TypeArg>,
        x1: Wire,
        x2: Wire,
    ) -> Result<Wire, BuildError> {
        // TODO Add an OpLoadError variant to BuildError
        let op = IntOpDef::iadd.instantiate(&[log_width.into()]).unwrap();
        Ok(self.add_dataflow_op(op, [x1, x2])?.out_wire(0))
    }

    fn add_ieq(
        &mut self,
        log_width: impl Into<TypeArg>,
        x1: Wire,
        x2: Wire,
    ) -> Result<Wire, BuildError> {
        // TODO Add an OpLoadError variant to BuildError
        let op = IntOpDef::ieq.instantiate(&[log_width.into()]).unwrap();
        Ok(self.add_dataflow_op(op, [x1, x2])?.out_wire(0))
    }
}

impl<D: Dataflow> IntOpBuilder for D {}