Coverage Report

Created: 2024-07-01 11:05

/home/runner/actions-runner/_work/fuel-vm/fuel-vm/fuel-asm/src/op.rs
Line
Count
Source (jump to first uncovered line)
1
//! Definitions and implementations for each unique instruction type, one for each
2
//! unique `Opcode` variant.
3
4
use super::{
5
    wideint::{
6
        CompareArgs,
7
        DivArgs,
8
        MathArgs,
9
        MulArgs,
10
    },
11
    CheckRegId,
12
    GMArgs,
13
    GTFArgs,
14
    Imm12,
15
    Imm18,
16
    Instruction,
17
    RegId,
18
};
19
20
// Here we re-export the generated instruction types and constructors, but extend them
21
// with `gm_args` and `gtf_args` short-hand constructors below to take their `GMArgs` and
22
// `GTFArgs` values respectively.
23
#[doc(inline)]
24
pub use super::_op::*;
25
26
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
27
impl GM {
28
    /// Construct a `GM` instruction from its arguments.
29
17
    pub fn from_args(ra: RegId, args: GMArgs) -> Self {
30
17
        Self::new(ra, Imm18::new(args as _))
31
17
    }
32
}
33
34
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
35
impl GTF {
36
    /// Construct a `GTF` instruction from its arguments.
37
299
    pub fn from_args(ra: RegId, rb: RegId, args: GTFArgs) -> Self {
38
299
        Self::new(ra, rb, Imm12::new(args as _))
39
299
    }
40
}
41
42
/// Construct a `GM` instruction from its arguments.
43
17
pub fn gm_args<A: CheckRegId>(ra: A, args: GMArgs) -> Instruction {
44
17
    Instruction::GM(GM::from_args(ra.check(), args))
45
17
}
46
47
#[cfg(feature = "typescript")]
48
const _: () = {
49
    use super::*;
50
51
0
    #[wasm_bindgen::prelude::wasm_bindgen]
52
    /// Construct a `GM` instruction from its arguments.
53
0
    pub fn gm_args(ra: u8, args: GMArgs) -> typescript::Instruction {
54
0
        Instruction::GM(GM::from_args(ra.check(), args)).into()
55
0
    }
56
};
57
58
/// Construct a `GM` instruction from its arguments.
59
299
pub fn gtf_args<A: CheckRegId, B: CheckRegId>(
60
299
    ra: A,
61
299
    rb: B,
62
299
    args: GTFArgs,
63
299
) -> Instruction {
64
299
    Instruction::GTF(GTF::from_args(ra.check(), rb.check(), args))
65
299
}
66
67
#[cfg(feature = "typescript")]
68
const _: () = {
69
    use super::*;
70
71
0
    #[wasm_bindgen::prelude::wasm_bindgen]
72
    /// Construct a `GM` instruction from its arguments.
73
0
    pub fn gtf_args(ra: u8, rb: u8, args: GTFArgs) -> typescript::Instruction {
74
0
        Instruction::GTF(GTF::from_args(ra.check(), rb.check(), args)).into()
75
0
    }
76
};
77
78
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
79
impl WDCM {
80
    /// Construct a `WDCM` instruction from its arguments.
81
252
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: CompareArgs) -> Self {
82
252
        Self::new(ra, rb, rc, args.to_imm())
83
252
    }
84
}
85
86
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
87
impl WQCM {
88
    /// Construct a `WQCM` instruction from its arguments.
89
252
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: CompareArgs) -> Self {
90
252
        Self::new(ra, rb, rc, args.to_imm())
91
252
    }
92
}
93
94
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
95
impl WDOP {
96
    /// Construct a `WDOP` instruction from its arguments.
97
10
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MathArgs) -> Self {
98
10
        Self::new(ra, rb, rc, args.to_imm())
99
10
    }
100
}
101
102
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
103
impl WQOP {
104
    /// Construct a `WQOP` instruction from its arguments.
105
6
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MathArgs) -> Self {
106
6
        Self::new(ra, rb, rc, args.to_imm())
107
6
    }
108
}
109
110
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
111
impl WDML {
112
    /// Construct a `WDML` instruction from its arguments.
113
79
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MulArgs) -> Self {
114
79
        Self::new(ra, rb, rc, args.to_imm())
115
79
    }
116
}
117
118
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
119
impl WQML {
120
    /// Construct a `WQML` instruction from its arguments.
121
97
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MulArgs) -> Self {
122
97
        Self::new(ra, rb, rc, args.to_imm())
123
97
    }
124
}
125
126
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
127
impl WDDV {
128
    /// Construct a `WDDV` instruction from its arguments.
129
14
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: DivArgs) -> Self {
130
14
        Self::new(ra, rb, rc, args.to_imm())
131
14
    }
132
}
133
134
0
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
135
impl WQDV {
136
    /// Construct a `WQDV` instruction from its arguments.
137
14
    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: DivArgs) -> Self {
138
14
        Self::new(ra, rb, rc, args.to_imm())
139
14
    }
140
}
141
142
/// Construct a `WDCM` instruction from its arguments.
143
252
pub fn wdcm_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
144
252
    ra: A,
145
252
    rb: B,
146
252
    rc: C,
147
252
    args: CompareArgs,
148
252
) -> Instruction {
149
252
    Instruction::WDCM(WDCM::from_args(ra.check(), rb.check(), rc.check(), args))
150
252
}
151
152
#[cfg(feature = "typescript")]
153
const _: () = {
154
    use super::*;
155
156
0
    #[wasm_bindgen::prelude::wasm_bindgen]
157
    /// Construct a `WDCM` instruction from its arguments.
158
0
    pub fn wdcm_args(
159
0
        ra: u8,
160
0
        rb: u8,
161
0
        rc: u8,
162
0
        args: CompareArgs,
163
0
    ) -> typescript::Instruction {
164
0
        crate::op::wdcm_args(ra, rb, rc, args).into()
165
0
    }
166
};
167
168
/// Construct a `WQCM` instruction from its arguments.
169
252
pub fn wqcm_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
170
252
    ra: A,
171
252
    rb: B,
172
252
    rc: C,
173
252
    args: CompareArgs,
174
252
) -> Instruction {
175
252
    Instruction::WQCM(WQCM::from_args(ra.check(), rb.check(), rc.check(), args))
176
252
}
177
178
#[cfg(feature = "typescript")]
179
const _: () = {
180
    use super::*;
181
182
0
    #[wasm_bindgen::prelude::wasm_bindgen]
183
    /// Construct a `WQCM` instruction from its arguments.
184
0
    pub fn wqcm_args(
185
0
        ra: u8,
186
0
        rb: u8,
187
0
        rc: u8,
188
0
        args: CompareArgs,
189
0
    ) -> typescript::Instruction {
190
0
        crate::op::wqcm_args(ra, rb, rc, args).into()
191
0
    }
192
};
193
194
/// Construct a `WDOP` instruction from its arguments.
195
10
pub fn wdop_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
196
10
    ra: A,
197
10
    rb: B,
198
10
    rc: C,
199
10
    args: MathArgs,
200
10
) -> Instruction {
201
10
    Instruction::WDOP(WDOP::from_args(ra.check(), rb.check(), rc.check(), args))
202
10
}
203
204
#[cfg(feature = "typescript")]
205
const _: () = {
206
    use super::*;
207
208
0
    #[wasm_bindgen::prelude::wasm_bindgen]
209
    /// Construct a `WDOP` instruction from its arguments.
210
0
    pub fn wdop_args(ra: u8, rb: u8, rc: u8, args: MathArgs) -> typescript::Instruction {
211
0
        crate::op::wdop_args(ra, rb, rc, args).into()
212
0
    }
213
};
214
215
/// Construct a `WQOP` instruction from its arguments.
216
6
pub fn wqop_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
217
6
    ra: A,
218
6
    rb: B,
219
6
    rc: C,
220
6
    args: MathArgs,
221
6
) -> Instruction {
222
6
    Instruction::WQOP(WQOP::from_args(ra.check(), rb.check(), rc.check(), args))
223
6
}
224
225
#[cfg(feature = "typescript")]
226
const _: () = {
227
    use super::*;
228
229
0
    #[wasm_bindgen::prelude::wasm_bindgen]
230
    /// Construct a `WQOP` instruction from its arguments.
231
0
    pub fn wqop_args(ra: u8, rb: u8, rc: u8, args: MathArgs) -> typescript::Instruction {
232
0
        crate::op::wqop_args(ra, rb, rc, args).into()
233
0
    }
234
};
235
236
/// Construct a `WDML` instruction from its arguments.
237
79
pub fn wdml_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
238
79
    ra: A,
239
79
    rb: B,
240
79
    rc: C,
241
79
    args: MulArgs,
242
79
) -> Instruction {
243
79
    Instruction::WDML(WDML::from_args(ra.check(), rb.check(), rc.check(), args))
244
79
}
245
246
#[cfg(feature = "typescript")]
247
const _: () = {
248
    use super::*;
249
250
0
    #[wasm_bindgen::prelude::wasm_bindgen]
251
    /// Construct a `WDML` instruction from its arguments.
252
0
    pub fn wdml_args(ra: u8, rb: u8, rc: u8, args: MulArgs) -> typescript::Instruction {
253
0
        crate::op::wdml_args(ra, rb, rc, args).into()
254
0
    }
255
};
256
257
/// Construct a `WQML` instruction from its arguments.
258
97
pub fn wqml_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
259
97
    ra: A,
260
97
    rb: B,
261
97
    rc: C,
262
97
    args: MulArgs,
263
97
) -> Instruction {
264
97
    Instruction::WQML(WQML::from_args(ra.check(), rb.check(), rc.check(), args))
265
97
}
266
267
#[cfg(feature = "typescript")]
268
const _: () = {
269
    use super::*;
270
271
0
    #[wasm_bindgen::prelude::wasm_bindgen]
272
    /// Construct a `WQML` instruction from its arguments.
273
0
    pub fn wqml_args(ra: u8, rb: u8, rc: u8, args: MulArgs) -> typescript::Instruction {
274
0
        crate::op::wqml_args(ra, rb, rc, args).into()
275
0
    }
276
};
277
278
/// Construct a `WDDV` instruction from its arguments.
279
14
pub fn wddv_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
280
14
    ra: A,
281
14
    rb: B,
282
14
    rc: C,
283
14
    args: DivArgs,
284
14
) -> Instruction {
285
14
    Instruction::WDDV(WDDV::from_args(ra.check(), rb.check(), rc.check(), args))
286
14
}
287
288
#[cfg(feature = "typescript")]
289
const _: () = {
290
    use super::*;
291
292
0
    #[wasm_bindgen::prelude::wasm_bindgen]
293
    /// Construct a `WDDV` instruction from its arguments.
294
0
    pub fn wddv_args(ra: u8, rb: u8, rc: u8, args: DivArgs) -> typescript::Instruction {
295
0
        crate::op::wddv_args(ra, rb, rc, args).into()
296
0
    }
297
};
298
299
/// Construct a `WQDV` instruction from its arguments.
300
14
pub fn wqdv_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
301
14
    ra: A,
302
14
    rb: B,
303
14
    rc: C,
304
14
    args: DivArgs,
305
14
) -> Instruction {
306
14
    Instruction::WQDV(WQDV::from_args(ra.check(), rb.check(), rc.check(), args))
307
14
}
308
309
#[cfg(feature = "typescript")]
310
const _: () = {
311
    use super::*;
312
313
0
    #[wasm_bindgen::prelude::wasm_bindgen]
314
    /// Construct a `WQDV` instruction from its arguments.
315
0
    pub fn wqdv_args(ra: u8, rb: u8, rc: u8, args: DivArgs) -> typescript::Instruction {
316
0
        crate::op::wqdv_args(ra, rb, rc, args).into()
317
0
    }
318
};