1use hugr_core::{HugrView, Node, ops::OpType};
2use inkwell::values::BasicValueEnum;
3
4use crate::utils::fat::FatNode;
5
6use super::func::RowPromise;
7
8pub struct EmitOpArgs<'c, 'hugr, OT, H> {
11 pub node: FatNode<'hugr, OT, H>,
13 pub inputs: Vec<BasicValueEnum<'c>>,
15 pub outputs: RowPromise<'c>,
17}
18
19impl<'hugr, OT, H> EmitOpArgs<'_, 'hugr, OT, H> {
20 #[must_use]
22 pub fn node(&self) -> FatNode<'hugr, OT, H> {
23 self.node
24 }
25}
26
27impl<'c, 'hugr, H: HugrView<Node = Node>> EmitOpArgs<'c, 'hugr, OpType, H> {
28 pub fn try_into_ot<OT>(self) -> Result<EmitOpArgs<'c, 'hugr, OT, H>, Self>
30 where
31 for<'a> &'a OpType: TryInto<&'a OT>,
32 {
33 let EmitOpArgs {
34 node,
35 inputs,
36 outputs,
37 } = self;
38 match node.try_into_ot() {
39 Some(new_node) => Ok(EmitOpArgs {
40 node: new_node,
41 inputs,
42 outputs,
43 }),
44 None => Err(EmitOpArgs {
45 node,
46 inputs,
47 outputs,
48 }),
49 }
50 }
51
52 pub fn into_ot<OTInto: PartialEq + 'c>(self, ot: &OTInto) -> EmitOpArgs<'c, 'hugr, OTInto, H>
57 where
58 for<'a> &'a OpType: TryInto<&'a OTInto>,
59 {
60 let EmitOpArgs {
61 node,
62 inputs,
63 outputs,
64 } = self;
65 EmitOpArgs {
66 node: node.into_ot(ot),
67 inputs,
68 outputs,
69 }
70 }
71}