1use crate::jeff_capnp;
4
5use super::ConstArray;
6
7#[derive(Clone, Copy, Debug)]
9#[non_exhaustive]
10pub enum IntOp {
11 Const1(bool),
13 Const8(u8),
15 Const16(u16),
17 Const32(u32),
19 Const64(u64),
21 Add,
23 Sub,
25 Mul,
27 DivS,
29 DivU,
31 Pow,
33 And,
35 Or,
37 Xor,
39 Not,
41 MinS,
43 MinU,
45 MaxS,
47 MaxU,
49 Eq,
51 LtS,
53 LteS,
55 LtU,
57 LteU,
59 Abs,
61 RemS,
63 RemU,
65 Shl,
67 Shr,
69}
70
71#[derive(Clone, Copy, Debug)]
73#[non_exhaustive]
74pub enum IntArrayOp<'a> {
75 ConstArray1(ConstArray<'a, bool>),
77 ConstArray8(ConstArray<'a, u8>),
79 ConstArray16(ConstArray<'a, u16>),
81 ConstArray32(ConstArray<'a, u32>),
83 ConstArray64(ConstArray<'a, u64>),
85 Zero {
87 bits: u8,
89 },
90 GetIndex,
92 SetIndex,
94 Length,
96 Create,
98}
99
100impl IntOp {
101 pub(crate) fn read_capnp(int_op: jeff_capnp::int_op::Reader<'_>) -> Self {
103 match int_op.which().expect("Integer operation should be present") {
104 jeff_capnp::int_op::Which::Const1(val) => Self::Const1(val),
105 jeff_capnp::int_op::Which::Const8(val) => Self::Const8(val),
106 jeff_capnp::int_op::Which::Const16(val) => Self::Const16(val),
107 jeff_capnp::int_op::Which::Const32(val) => Self::Const32(val),
108 jeff_capnp::int_op::Which::Const64(val) => Self::Const64(val),
109 jeff_capnp::int_op::Which::Add(()) => Self::Add,
110 jeff_capnp::int_op::Which::Sub(()) => Self::Sub,
111 jeff_capnp::int_op::Which::Mul(()) => Self::Mul,
112 jeff_capnp::int_op::Which::DivS(()) => Self::DivS,
113 jeff_capnp::int_op::Which::DivU(()) => Self::DivU,
114 jeff_capnp::int_op::Which::Pow(()) => Self::Pow,
115 jeff_capnp::int_op::Which::And(()) => Self::And,
116 jeff_capnp::int_op::Which::Or(()) => Self::Or,
117 jeff_capnp::int_op::Which::Xor(()) => Self::Xor,
118 jeff_capnp::int_op::Which::Not(()) => Self::Not,
119 jeff_capnp::int_op::Which::MinS(()) => Self::MinS,
120 jeff_capnp::int_op::Which::MinU(()) => Self::MinU,
121 jeff_capnp::int_op::Which::MaxS(()) => Self::MaxS,
122 jeff_capnp::int_op::Which::MaxU(()) => Self::MaxU,
123 jeff_capnp::int_op::Which::Eq(()) => Self::Eq,
124 jeff_capnp::int_op::Which::LtS(()) => Self::LtS,
125 jeff_capnp::int_op::Which::LteS(()) => Self::LteS,
126 jeff_capnp::int_op::Which::LtU(()) => Self::LtU,
127 jeff_capnp::int_op::Which::LteU(()) => Self::LteU,
128 jeff_capnp::int_op::Which::Abs(()) => Self::Abs,
129 jeff_capnp::int_op::Which::RemS(()) => Self::RemS,
130 jeff_capnp::int_op::Which::RemU(()) => Self::RemU,
131 jeff_capnp::int_op::Which::Shl(()) => Self::Shl,
132 jeff_capnp::int_op::Which::Shr(()) => Self::Shr,
133 }
134 }
135}
136
137impl<'a> IntArrayOp<'a> {
138 pub(crate) fn read_capnp(int_array_op: jeff_capnp::int_array_op::Reader<'a>) -> Self {
140 match int_array_op
141 .which()
142 .expect("Integer array operation should be present")
143 {
144 jeff_capnp::int_array_op::Which::Const1(val) => Self::ConstArray1(
145 ConstArray::read_capnp(val.expect("Const1 should be present")),
146 ),
147 jeff_capnp::int_array_op::Which::Const8(val) => Self::ConstArray8(
148 ConstArray::read_capnp(val.expect("Const8 should be present")),
149 ),
150 jeff_capnp::int_array_op::Which::Const16(val) => Self::ConstArray16(
151 ConstArray::read_capnp(val.expect("Const16 should be present")),
152 ),
153 jeff_capnp::int_array_op::Which::Const32(val) => Self::ConstArray32(
154 ConstArray::read_capnp(val.expect("Const32 should be present")),
155 ),
156 jeff_capnp::int_array_op::Which::Const64(val) => Self::ConstArray64(
157 ConstArray::read_capnp(val.expect("Const64 should be present")),
158 ),
159 jeff_capnp::int_array_op::Which::Zero(val) => Self::Zero { bits: val },
160 jeff_capnp::int_array_op::Which::GetIndex(()) => Self::GetIndex,
161 jeff_capnp::int_array_op::Which::SetIndex(()) => Self::SetIndex,
162 jeff_capnp::int_array_op::Which::Length(()) => Self::Length,
163 jeff_capnp::int_array_op::Which::Create(()) => Self::Create,
164 }
165 }
166}