1use hugr_core::{ops::OpType, HugrView, Node};
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 pub fn node(&self) -> FatNode<'hugr, OT, H> {
22 self.node
23 }
24}
25
26impl<'c, 'hugr, H: HugrView<Node = Node>> EmitOpArgs<'c, 'hugr, OpType, H> {
27 pub fn try_into_ot<OT>(self) -> Result<EmitOpArgs<'c, 'hugr, OT, H>, Self>
29 where
30 for<'a> &'a OpType: TryInto<&'a OT>,
31 {
32 let EmitOpArgs {
33 node,
34 inputs,
35 outputs,
36 } = self;
37 match node.try_into_ot() {
38 Some(new_node) => Ok(EmitOpArgs {
39 node: new_node,
40 inputs,
41 outputs,
42 }),
43 None => Err(EmitOpArgs {
44 node,
45 inputs,
46 outputs,
47 }),
48 }
49 }
50
51 pub fn into_ot<OTInto: PartialEq + 'c>(self, ot: &OTInto) -> EmitOpArgs<'c, 'hugr, OTInto, H>
56 where
57 for<'a> &'a OpType: TryInto<&'a OTInto>,
58 {
59 let EmitOpArgs {
60 node,
61 inputs,
62 outputs,
63 } = self;
64 EmitOpArgs {
65 node: node.into_ot(ot),
66 inputs,
67 outputs,
68 }
69 }
70}