1use crate::ir::id::{DataSegmentID, ElementID, FieldID, FunctionID, GlobalID, LocalID, TypeID};
8use crate::ir::module::module_types::HeapType;
9use crate::ir::types::{BlockType, FuncInstrMode, InstrumentationMode};
10use crate::Location;
11use wasmparser::MemArg;
12use wasmparser::Operator;
13
14pub trait Instrumenter<'a> {
16 fn finish_instr(&mut self);
18 fn curr_instrument_mode(&self) -> &Option<InstrumentationMode>;
20
21 fn set_instrument_mode_at(&mut self, mode: InstrumentationMode, loc: Location);
23
24 fn curr_func_instrument_mode(&self) -> &Option<FuncInstrMode>;
26
27 fn set_func_instrument_mode(&mut self, mode: FuncInstrMode);
29
30 fn func_entry(&mut self) -> &mut Self {
34 self.set_func_instrument_mode(FuncInstrMode::Entry);
35 self
36 }
37
38 fn func_exit(&mut self) -> &mut Self {
40 self.set_func_instrument_mode(FuncInstrMode::Exit);
41 self
42 }
43
44 fn clear_instr_at(&mut self, loc: Location, mode: InstrumentationMode);
47
48 fn add_instr_at(&mut self, loc: Location, instr: Operator<'a>);
50
51 fn before_at(&mut self, loc: Location) -> &mut Self {
53 self.set_instrument_mode_at(InstrumentationMode::Before, loc);
54 self
55 }
56
57 fn after_at(&mut self, loc: Location) -> &mut Self {
59 self.set_instrument_mode_at(InstrumentationMode::After, loc);
60 self
61 }
62
63 fn alternate_at(&mut self, loc: Location) -> &mut Self {
65 self.set_instrument_mode_at(InstrumentationMode::Alternate, loc);
66 self
67 }
68
69 fn empty_alternate_at(&mut self, loc: Location) -> &mut Self;
71
72 fn semantic_after_at(&mut self, loc: Location) -> &mut Self {
74 self.set_instrument_mode_at(InstrumentationMode::SemanticAfter, loc);
75 self
76 }
77
78 fn block_entry_at(&mut self, loc: Location) -> &mut Self {
80 self.set_instrument_mode_at(InstrumentationMode::BlockEntry, loc);
81 self
82 }
83
84 fn block_exit_at(&mut self, loc: Location) -> &mut Self {
86 self.set_instrument_mode_at(InstrumentationMode::BlockExit, loc);
87 self
88 }
89
90 fn block_alt_at(&mut self, loc: Location) -> &mut Self {
92 self.set_instrument_mode_at(InstrumentationMode::BlockAlt, loc);
93 self
94 }
95
96 fn empty_block_alt_at(&mut self, loc: Location) -> &mut Self;
98
99 fn get_injected_val(&self, idx: usize) -> &Operator;
101}
102
103pub trait Inject<'a> {
105 fn inject(&mut self, instr: Operator<'a>);
107
108 fn inject_all(&mut self, instrs: &[Operator<'a>]) -> &mut Self {
110 instrs.iter().for_each(|instr| {
111 self.inject(instr.to_owned());
112 });
113 self
114 }
115}
116
117pub trait InjectAt<'a> {
119 fn inject_at(&mut self, idx: usize, mode: InstrumentationMode, instr: Operator<'a>);
121}
122
123#[allow(dead_code)]
124pub trait Opcode<'a>: Inject<'a> {
129 fn call(&mut self, idx: FunctionID) -> &mut Self {
132 self.inject(Operator::Call {
133 function_index: *idx,
134 });
135 self
136 }
137
138 fn return_stmt(&mut self) -> &mut Self {
140 self.inject(Operator::Return);
141 self
142 }
143
144 fn nop(&mut self) -> &mut Self {
146 self.inject(Operator::Nop);
147 self
148 }
149
150 fn unreachable(&mut self) -> &mut Self {
152 self.inject(Operator::Unreachable);
153 self
154 }
155
156 fn if_stmt(&mut self, block_type: BlockType) -> &mut Self {
158 self.inject(Operator::If {
159 blockty: wasmparser::BlockType::from(block_type),
160 });
161 self
162 }
163
164 fn else_stmt(&mut self) -> &mut Self {
166 self.inject(Operator::Else);
167 self
168 }
169
170 fn end(&mut self) -> &mut Self {
172 self.inject(Operator::End);
173 self
174 }
175
176 fn block(&mut self, block_type: BlockType) -> &mut Self {
178 self.inject(Operator::Block {
179 blockty: wasmparser::BlockType::from(block_type),
180 });
181 self
182 }
183
184 fn loop_stmt(&mut self, block_type: BlockType) -> &mut Self {
186 self.inject(Operator::Loop {
187 blockty: wasmparser::BlockType::from(block_type),
188 });
189 self
190 }
191
192 fn br(&mut self, relative_depth: u32) -> &mut Self {
194 self.inject(Operator::Br { relative_depth });
195 self
196 }
197
198 fn br_if(&mut self, relative_depth: u32) -> &mut Self {
200 self.inject(Operator::BrIf { relative_depth });
201 self
202 }
203
204 fn local_get(&mut self, idx: LocalID) -> &mut Self {
207 self.inject(Operator::LocalGet { local_index: *idx });
208 self
209 }
210
211 fn local_set(&mut self, idx: LocalID) -> &mut Self {
213 self.inject(Operator::LocalSet { local_index: *idx });
214 self
215 }
216
217 fn local_tee(&mut self, idx: LocalID) -> &mut Self {
218 self.inject(Operator::LocalTee { local_index: *idx });
219 self
220 }
221
222 fn i32_const(&mut self, value: i32) -> &mut Self {
225 self.inject(Operator::I32Const { value });
226 self
227 }
228
229 fn i32_add(&mut self) -> &mut Self {
231 self.inject(Operator::I32Add);
232 self
233 }
234
235 fn i32_sub(&mut self) -> &mut Self {
237 self.inject(Operator::I32Sub);
238 self
239 }
240
241 fn i32_mul(&mut self) -> &mut Self {
243 self.inject(Operator::I32Mul);
244 self
245 }
246
247 fn i32_div_signed(&mut self) -> &mut Self {
249 self.inject(Operator::I32DivS);
250 self
251 }
252
253 fn i32_div_unsigned(&mut self) -> &mut Self {
255 self.inject(Operator::I32DivU);
256 self
257 }
258
259 fn i32_rem_unsigned(&mut self) -> &mut Self {
261 self.inject(Operator::I32RemU);
262 self
263 }
264
265 fn i32_rem_signed(&mut self) -> &mut Self {
267 self.inject(Operator::I32RemS);
268 self
269 }
270
271 fn i32_and(&mut self) -> &mut Self {
273 self.inject(Operator::I32And);
274 self
275 }
276
277 fn i32_or(&mut self) -> &mut Self {
279 self.inject(Operator::I32Or);
280 self
281 }
282
283 fn i32_xor(&mut self) -> &mut Self {
285 self.inject(Operator::I32Xor);
286 self
287 }
288
289 fn i32_shl(&mut self) -> &mut Self {
291 self.inject(Operator::I32Shl);
292 self
293 }
294
295 fn i32_shr_signed(&mut self) -> &mut Self {
297 self.inject(Operator::I32ShrS);
298 self
299 }
300
301 fn i32_shr_unsigned(&mut self) -> &mut Self {
303 self.inject(Operator::I32ShrU);
304 self
305 }
306
307 fn i32_rotl(&mut self) -> &mut Self {
309 self.inject(Operator::I32Rotl);
310 self
311 }
312
313 fn i32_rotr(&mut self) -> &mut Self {
315 self.inject(Operator::I32Rotr);
316 self
317 }
318
319 fn i32_eq(&mut self) -> &mut Self {
321 self.inject(Operator::I32Eq);
322 self
323 }
324
325 fn i32_eqz(&mut self) -> &mut Self {
327 self.inject(Operator::I32Eqz);
328 self
329 }
330
331 fn i32_ne(&mut self) -> &mut Self {
333 self.inject(Operator::I32Ne);
334 self
335 }
336
337 fn i32_lt_unsigned(&mut self) -> &mut Self {
339 self.inject(Operator::I32LtU);
340 self
341 }
342
343 fn i32_lt_signed(&mut self) -> &mut Self {
345 self.inject(Operator::I32LtS);
346 self
347 }
348
349 fn i32_gt_unsigned(&mut self) -> &mut Self {
351 self.inject(Operator::I32GtU);
352 self
353 }
354
355 fn i32_gt_signed(&mut self) -> &mut Self {
357 self.inject(Operator::I32GtS);
358 self
359 }
360
361 fn i32_lte_unsigned(&mut self) -> &mut Self {
363 self.inject(Operator::I32LeU);
364 self
365 }
366
367 fn i32_lte_signed(&mut self) -> &mut Self {
369 self.inject(Operator::I32LeS);
370 self
371 }
372
373 fn i32_gte_unsigned(&mut self) -> &mut Self {
375 self.inject(Operator::I32GeU);
376 self
377 }
378
379 fn i32_gte_signed(&mut self) -> &mut Self {
381 self.inject(Operator::I32GeS);
382 self
383 }
384
385 fn i32_wrap_i64(&mut self) -> &mut Self {
386 self.inject(Operator::I32WrapI64);
387 self
388 }
389
390 fn i32_extend_8s(&mut self) -> &mut Self {
392 self.inject(Operator::I32Extend8S);
393 self
394 }
395
396 fn i32_extend_16s(&mut self) -> &mut Self {
398 self.inject(Operator::I32Extend16S);
399 self
400 }
401
402 fn i32_trunc_f32s(&mut self) -> &mut Self {
404 self.inject(Operator::I32TruncF32S);
405 self
406 }
407
408 fn i32_trunc_f32u(&mut self) -> &mut Self {
410 self.inject(Operator::I32TruncF32U);
411 self
412 }
413
414 fn i32_trunc_f64s(&mut self) -> &mut Self {
416 self.inject(Operator::I32TruncF64S);
417 self
418 }
419
420 fn i32_trunc_f64u(&mut self) -> &mut Self {
422 self.inject(Operator::I32TruncF64U);
423 self
424 }
425
426 fn i32_reinterpret_f32(&mut self) -> &mut Self {
428 self.inject(Operator::I32ReinterpretF32);
429 self
430 }
431
432 fn i64_const(&mut self, value: i64) -> &mut Self {
434 self.inject(Operator::I64Const { value });
435 self
436 }
437
438 fn i64_add(&mut self) -> &mut Self {
440 self.inject(Operator::I64Add);
441 self
442 }
443
444 fn i64_sub(&mut self) -> &mut Self {
446 self.inject(Operator::I64Sub);
447 self
448 }
449
450 fn i64_mul(&mut self) -> &mut Self {
452 self.inject(Operator::I64Mul);
453 self
454 }
455
456 fn i64_div_signed(&mut self) -> &mut Self {
458 self.inject(Operator::I64DivS);
459 self
460 }
461
462 fn i64_div_unsigned(&mut self) -> &mut Self {
464 self.inject(Operator::I64DivU);
465 self
466 }
467
468 fn i64_rem_unsigned(&mut self) -> &mut Self {
470 self.inject(Operator::I64RemU);
471 self
472 }
473
474 fn i64_rem_signed(&mut self) -> &mut Self {
476 self.inject(Operator::I64RemS);
477 self
478 }
479
480 fn i64_and(&mut self) -> &mut Self {
482 self.inject(Operator::I64And);
483 self
484 }
485
486 fn i64_or(&mut self) -> &mut Self {
488 self.inject(Operator::I64Or);
489 self
490 }
491
492 fn i64_xor(&mut self) -> &mut Self {
494 self.inject(Operator::I64Xor);
495 self
496 }
497
498 fn i64_shl(&mut self) -> &mut Self {
500 self.inject(Operator::I64Shl);
501 self
502 }
503
504 fn i64_shr_signed(&mut self) -> &mut Self {
506 self.inject(Operator::I64ShrS);
507 self
508 }
509
510 fn i64_shr_unsigned(&mut self) -> &mut Self {
512 self.inject(Operator::I64ShrU);
513 self
514 }
515
516 fn i64_rotl(&mut self) -> &mut Self {
518 self.inject(Operator::I64Rotl);
519 self
520 }
521
522 fn i64_rotr(&mut self) -> &mut Self {
524 self.inject(Operator::I64Rotr);
525 self
526 }
527
528 fn i64_eq(&mut self) -> &mut Self {
530 self.inject(Operator::I64Eq);
531 self
532 }
533
534 fn i64_eqz(&mut self) -> &mut Self {
536 self.inject(Operator::I64Eqz);
537 self
538 }
539
540 fn i64_ne(&mut self) -> &mut Self {
542 self.inject(Operator::I64Ne);
543 self
544 }
545
546 fn i64_lt_unsigned(&mut self) -> &mut Self {
548 self.inject(Operator::I64LtU);
549 self
550 }
551
552 fn i64_lt_signed(&mut self) -> &mut Self {
554 self.inject(Operator::I64LtS);
555 self
556 }
557
558 fn i64_gt_unsigned(&mut self) -> &mut Self {
560 self.inject(Operator::I64GtU);
561 self
562 }
563
564 fn i64_gt_signed(&mut self) -> &mut Self {
566 self.inject(Operator::I64GtS);
567 self
568 }
569
570 fn i64_lte_unsigned(&mut self) -> &mut Self {
572 self.inject(Operator::I64LeU);
573 self
574 }
575
576 fn i64_lte_signed(&mut self) -> &mut Self {
578 self.inject(Operator::I64LeS);
579 self
580 }
581
582 fn i64_gte_unsigned(&mut self) -> &mut Self {
584 self.inject(Operator::I64GeU);
585 self
586 }
587
588 fn i64_gte_signed(&mut self) -> &mut Self {
590 self.inject(Operator::I64GeS);
591 self
592 }
593
594 fn i64_extend_i32u(&mut self) -> &mut Self {
596 self.inject(Operator::I64ExtendI32U);
597 self
598 }
599
600 fn i64_extend_i32s(&mut self) -> &mut Self {
602 self.inject(Operator::I64ExtendI32S);
603 self
604 }
605
606 fn i64_trunc_f32s(&mut self) -> &mut Self {
608 self.inject(Operator::I64TruncF32S);
609 self
610 }
611
612 fn i64_trunc_f32u(&mut self) -> &mut Self {
614 self.inject(Operator::I64TruncF32U);
615 self
616 }
617
618 fn i64_trunc_f64s(&mut self) -> &mut Self {
620 self.inject(Operator::I64TruncF64S);
621 self
622 }
623
624 fn i64_trunc_f64u(&mut self) -> &mut Self {
626 self.inject(Operator::I64TruncF64U);
627 self
628 }
629
630 fn i64_reinterpret_f64(&mut self) -> &mut Self {
632 self.inject(Operator::I64ReinterpretF64);
633 self
634 }
635
636 fn f32_const(&mut self, val: f32) -> &mut Self {
639 self.inject(Operator::F32Const {
640 value: wasmparser::Ieee32::from(val),
641 });
642 self
643 }
644
645 fn f32_abs(&mut self) -> &mut Self {
647 self.inject(Operator::F32Abs);
648 self
649 }
650
651 fn f32_ceil(&mut self) -> &mut Self {
653 self.inject(Operator::F32Ceil);
654 self
655 }
656
657 fn f32_floor(&mut self) -> &mut Self {
659 self.inject(Operator::F32Floor);
660 self
661 }
662
663 fn f32_trunc(&mut self) -> &mut Self {
665 self.inject(Operator::F32Trunc);
666 self
667 }
668
669 fn f32_sqrt(&mut self) -> &mut Self {
671 self.inject(Operator::F32Sqrt);
672 self
673 }
674
675 fn f32_add(&mut self) -> &mut Self {
677 self.inject(Operator::F32Add);
678 self
679 }
680
681 fn f32_sub(&mut self) -> &mut Self {
683 self.inject(Operator::F32Sub);
684 self
685 }
686
687 fn f32_mul(&mut self) -> &mut Self {
689 self.inject(Operator::F32Mul);
690 self
691 }
692
693 fn f32_div(&mut self) -> &mut Self {
695 self.inject(Operator::F32Div);
696 self
697 }
698
699 fn f32_min(&mut self) -> &mut Self {
701 self.inject(Operator::F32Min);
702 self
703 }
704
705 fn f32_max(&mut self) -> &mut Self {
707 self.inject(Operator::F32Max);
708 self
709 }
710
711 fn f32_eq(&mut self) -> &mut Self {
713 self.inject(Operator::F32Eq);
714 self
715 }
716
717 fn f32_ne(&mut self) -> &mut Self {
719 self.inject(Operator::F32Ne);
720 self
721 }
722
723 fn f32_gt(&mut self) -> &mut Self {
725 self.inject(Operator::F32Gt);
726 self
727 }
728
729 fn f32_ge(&mut self) -> &mut Self {
731 self.inject(Operator::F32Ge);
732 self
733 }
734
735 fn f32_lt(&mut self) -> &mut Self {
737 self.inject(Operator::F32Lt);
738 self
739 }
740
741 fn f32_le(&mut self) -> &mut Self {
743 self.inject(Operator::F32Le);
744 self
745 }
746
747 fn f32_convert_i32s(&mut self) -> &mut Self {
749 self.inject(Operator::F32ConvertI32S);
750 self
751 }
752
753 fn f32_convert_i32u(&mut self) -> &mut Self {
755 self.inject(Operator::F32ConvertI32U);
756 self
757 }
758
759 fn f32_convert_i64s(&mut self) -> &mut Self {
761 self.inject(Operator::F32ConvertI64S);
762 self
763 }
764
765 fn f32_convert_i64u(&mut self) -> &mut Self {
767 self.inject(Operator::F32ConvertI64U);
768 self
769 }
770
771 fn f32_demote_f64(&mut self) -> &mut Self {
773 self.inject(Operator::F32DemoteF64);
774 self
775 }
776
777 fn f32_reinterpret_i32(&mut self) -> &mut Self {
779 self.inject(Operator::F32ReinterpretI32);
780 self
781 }
782
783 fn f32_copysign(&mut self) -> &mut Self {
785 self.inject(Operator::F32Copysign);
786 self
787 }
788
789 fn f64_const(&mut self, val: f64) -> &mut Self {
791 self.inject(Operator::F64Const {
792 value: wasmparser::Ieee64::from(val),
793 });
794 self
795 }
796
797 fn f64_abs(&mut self) -> &mut Self {
799 self.inject(Operator::F64Abs);
800 self
801 }
802
803 fn f64_ceil(&mut self) -> &mut Self {
805 self.inject(Operator::F64Ceil);
806 self
807 }
808
809 fn f64_floor(&mut self) -> &mut Self {
811 self.inject(Operator::F64Floor);
812 self
813 }
814
815 fn f64_trunc(&mut self) -> &mut Self {
817 self.inject(Operator::F64Trunc);
818 self
819 }
820
821 fn f64_sqrt(&mut self) -> &mut Self {
823 self.inject(Operator::F64Sqrt);
824 self
825 }
826
827 fn f64_add(&mut self) -> &mut Self {
829 self.inject(Operator::F64Add);
830 self
831 }
832
833 fn f64_sub(&mut self) -> &mut Self {
835 self.inject(Operator::F64Sub);
836 self
837 }
838
839 fn f64_mul(&mut self) -> &mut Self {
841 self.inject(Operator::F64Mul);
842 self
843 }
844
845 fn f64_div(&mut self) -> &mut Self {
847 self.inject(Operator::F64Div);
848 self
849 }
850
851 fn f64_min(&mut self) -> &mut Self {
853 self.inject(Operator::F64Min);
854 self
855 }
856
857 fn f64_max(&mut self) -> &mut Self {
859 self.inject(Operator::F64Max);
860 self
861 }
862
863 fn f64_eq(&mut self) -> &mut Self {
865 self.inject(Operator::F64Eq);
866 self
867 }
868
869 fn f64_ne(&mut self) -> &mut Self {
871 self.inject(Operator::F64Ne);
872 self
873 }
874
875 fn f64_gt(&mut self) -> &mut Self {
877 self.inject(Operator::F64Gt);
878 self
879 }
880
881 fn f64_ge(&mut self) -> &mut Self {
883 self.inject(Operator::F64Ge);
884 self
885 }
886
887 fn f64_lt(&mut self) -> &mut Self {
889 self.inject(Operator::F64Lt);
890 self
891 }
892
893 fn f64_le(&mut self) -> &mut Self {
895 self.inject(Operator::F64Le);
896 self
897 }
898
899 fn f64_reinterpret_i64(&mut self) -> &mut Self {
901 self.inject(Operator::F64ReinterpretI64);
902 self
903 }
904
905 fn f64_promote_f32(&mut self) -> &mut Self {
907 self.inject(Operator::F64PromoteF32);
908 self
909 }
910
911 fn f64_convert_i32s(&mut self) -> &mut Self {
913 self.inject(Operator::F64ConvertI32S);
914 self
915 }
916
917 fn f64_convert_i32u(&mut self) -> &mut Self {
919 self.inject(Operator::F64ConvertI32U);
920 self
921 }
922
923 fn f64_convert_i64s(&mut self) -> &mut Self {
925 self.inject(Operator::F64ConvertI64S);
926 self
927 }
928
929 fn f64_convert_i64u(&mut self) -> &mut Self {
931 self.inject(Operator::F64ConvertI64U);
932 self
933 }
934
935 fn f64_copysign(&mut self) -> &mut Self {
937 self.inject(Operator::F64Copysign);
938 self
939 }
940
941 fn memory_init(&mut self, data_index: u32, mem: u32) -> &mut Self {
944 self.inject(Operator::MemoryInit { data_index, mem });
945 self
946 }
947
948 fn memory_size(&mut self, mem: u32) -> &mut Self {
950 self.inject(Operator::MemorySize { mem });
951 self
952 }
953
954 fn memory_grow(&mut self, mem: u32) -> &mut Self {
956 self.inject(Operator::MemoryGrow { mem });
957 self
958 }
959
960 fn memory_fill(&mut self, mem: u32) -> &mut Self {
962 self.inject(Operator::MemoryFill { mem });
963 self
964 }
965
966 fn memory_copy(&mut self, dst_mem: u32, src_mem: u32) -> &mut Self {
968 self.inject(Operator::MemoryCopy { dst_mem, src_mem });
969 self
970 }
971
972 fn memory_discard(&mut self, mem: u32) -> &mut Self {
974 self.inject(Operator::MemoryDiscard { mem });
975 self
976 }
977 fn data_drop(&mut self, data_index: u32) -> &mut Self {
979 self.inject(Operator::DataDrop { data_index });
980 self
981 }
982
983 fn drop(&mut self) -> &mut Self {
986 self.inject(Operator::Drop);
987 self
988 }
989
990 fn i32_load8_s(&mut self, memarg: MemArg) -> &mut Self {
995 self.inject(Operator::I32Load8S { memarg });
996 self
997 }
998
999 fn i32_load8_u(&mut self, memarg: MemArg) -> &mut Self {
1001 self.inject(Operator::I32Load8U { memarg });
1002 self
1003 }
1004
1005 fn i32_load16_s(&mut self, memarg: MemArg) -> &mut Self {
1007 self.inject(Operator::I32Load16S { memarg });
1008 self
1009 }
1010
1011 fn i32_load16_u(&mut self, memarg: MemArg) -> &mut Self {
1013 self.inject(Operator::I32Load16U { memarg });
1014 self
1015 }
1016
1017 fn i32_load(&mut self, memarg: MemArg) -> &mut Self {
1019 self.inject(Operator::I32Load { memarg });
1020 self
1021 }
1022
1023 fn i32_store(&mut self, memarg: MemArg) -> &mut Self {
1024 self.inject(Operator::I32Store { memarg });
1025 self
1026 }
1027 fn i32_store8(&mut self, memarg: MemArg) -> &mut Self {
1028 self.inject(Operator::I32Store8 { memarg });
1029 self
1030 }
1031 fn i32_store16(&mut self, memarg: MemArg) -> &mut Self {
1032 self.inject(Operator::I32Store16 { memarg });
1033 self
1034 }
1035
1036 fn i64_load8_s(&mut self, memarg: MemArg) -> &mut Self {
1038 self.inject(Operator::I64Load8S { memarg });
1039 self
1040 }
1041
1042 fn i64_load8_u(&mut self, memarg: MemArg) -> &mut Self {
1044 self.inject(Operator::I64Load8U { memarg });
1045 self
1046 }
1047
1048 fn i64_load16_s(&mut self, memarg: MemArg) -> &mut Self {
1050 self.inject(Operator::I64Load16S { memarg });
1051 self
1052 }
1053
1054 fn i64_load16_u(&mut self, memarg: MemArg) -> &mut Self {
1056 self.inject(Operator::I64Load16U { memarg });
1057 self
1058 }
1059
1060 fn i64_load32_s(&mut self, memarg: MemArg) -> &mut Self {
1062 self.inject(Operator::I64Load32S { memarg });
1063 self
1064 }
1065
1066 fn i64_load32_u(&mut self, memarg: MemArg) -> &mut Self {
1068 self.inject(Operator::I64Load32U { memarg });
1069 self
1070 }
1071
1072 fn i64_load(&mut self, memarg: MemArg) -> &mut Self {
1074 self.inject(Operator::I64Load { memarg });
1075 self
1076 }
1077
1078 fn i64_store(&mut self, memarg: MemArg) -> &mut Self {
1079 self.inject(Operator::I64Store { memarg });
1080 self
1081 }
1082
1083 fn f32_load(&mut self, memarg: MemArg) -> &mut Self {
1085 self.inject(Operator::F32Load { memarg });
1086 self
1087 }
1088
1089 fn f32_store(&mut self, memarg: MemArg) -> &mut Self {
1090 self.inject(Operator::F32Store { memarg });
1091 self
1092 }
1093
1094 fn f64_load(&mut self, memarg: MemArg) -> &mut Self {
1096 self.inject(Operator::F64Load { memarg });
1097 self
1098 }
1099
1100 fn f64_store(&mut self, memarg: MemArg) -> &mut Self {
1102 self.inject(Operator::F64Store { memarg });
1103 self
1104 }
1105
1106 fn global_get(&mut self, idx: GlobalID) -> &mut Self {
1108 self.inject(Operator::GlobalGet { global_index: *idx });
1109 self
1110 }
1111
1112 fn global_set(&mut self, idx: GlobalID) -> &mut Self {
1114 self.inject(Operator::GlobalSet { global_index: *idx });
1115 self
1116 }
1117
1118 fn ref_null(&mut self, heap_type: HeapType) -> &mut Self {
1120 self.inject(Operator::RefNull {
1121 hty: wasmparser::HeapType::from(heap_type),
1122 });
1123 self
1124 }
1125
1126 fn ref_is_null(&mut self) -> &mut Self {
1127 self.inject(Operator::RefIsNull);
1128 self
1129 }
1130
1131 fn ref_func(&mut self, function_index: u32) -> &mut Self {
1132 self.inject(Operator::RefFunc { function_index });
1133 self
1134 }
1135
1136 fn ref_eq(&mut self) -> &mut Self {
1137 self.inject(Operator::RefEq);
1138 self
1139 }
1140
1141 fn ref_as_non_null(&mut self) -> &mut Self {
1142 self.inject(Operator::RefAsNonNull);
1143 self
1144 }
1145
1146 fn struct_new(&mut self, struct_type_index: TypeID) -> &mut Self {
1147 self.inject(Operator::StructNew {
1148 struct_type_index: *struct_type_index,
1149 });
1150 self
1151 }
1152
1153 fn struct_new_default(&mut self, struct_type_index: TypeID) -> &mut Self {
1154 self.inject(Operator::StructNewDefault {
1155 struct_type_index: *struct_type_index,
1156 });
1157 self
1158 }
1159
1160 fn struct_get(&mut self, struct_type_index: TypeID, field_index: FieldID) -> &mut Self {
1161 self.inject(Operator::StructGet {
1162 struct_type_index: *struct_type_index,
1163 field_index: *field_index,
1164 });
1165 self
1166 }
1167
1168 fn struct_get_s(&mut self, struct_type_index: TypeID, field_index: FieldID) -> &mut Self {
1169 self.inject(Operator::StructGetS {
1170 struct_type_index: *struct_type_index,
1171 field_index: *field_index,
1172 });
1173 self
1174 }
1175
1176 fn struct_get_u(&mut self, struct_type_index: TypeID, field_index: FieldID) -> &mut Self {
1177 self.inject(Operator::StructGetU {
1178 struct_type_index: *struct_type_index,
1179 field_index: *field_index,
1180 });
1181 self
1182 }
1183
1184 fn struct_set(&mut self, struct_type_index: TypeID, field_index: FieldID) -> &mut Self {
1185 self.inject(Operator::StructSet {
1186 struct_type_index: *struct_type_index,
1187 field_index: *field_index,
1188 });
1189 self
1190 }
1191
1192 fn array_new(&mut self, array_type_index: TypeID) -> &mut Self {
1193 self.inject(Operator::ArrayNew {
1194 array_type_index: *array_type_index,
1195 });
1196 self
1197 }
1198
1199 fn array_new_default(&mut self, array_type_index: TypeID) -> &mut Self {
1200 self.inject(Operator::ArrayNewDefault {
1201 array_type_index: *array_type_index,
1202 });
1203 self
1204 }
1205
1206 fn array_new_fixed(&mut self, array_type_index: TypeID, array_size: u32) -> &mut Self {
1207 self.inject(Operator::ArrayNewFixed {
1208 array_type_index: *array_type_index,
1209 array_size,
1210 });
1211 self
1212 }
1213
1214 fn array_new_data(
1216 &mut self,
1217 array_type_index: TypeID,
1218 array_data_index: DataSegmentID,
1219 ) -> &mut Self {
1220 self.inject(Operator::ArrayNewData {
1221 array_type_index: *array_type_index,
1222 array_data_index: *array_data_index,
1223 });
1224 self
1225 }
1226
1227 fn array_new_elem(
1228 &mut self,
1229 array_type_index: TypeID,
1230 array_elem_index: ElementID,
1231 ) -> &mut Self {
1232 self.inject(Operator::ArrayNewElem {
1233 array_type_index: *array_type_index,
1234 array_elem_index: *array_elem_index,
1235 });
1236 self
1237 }
1238
1239 fn array_get(&mut self, array_type_index: TypeID) -> &mut Self {
1240 self.inject(Operator::ArrayGet {
1241 array_type_index: *array_type_index,
1242 });
1243 self
1244 }
1245
1246 fn array_get_s(&mut self, array_type_index: TypeID) -> &mut Self {
1247 self.inject(Operator::ArrayGetS {
1248 array_type_index: *array_type_index,
1249 });
1250 self
1251 }
1252
1253 fn array_get_u(&mut self, array_type_index: TypeID) -> &mut Self {
1254 self.inject(Operator::ArrayGetU {
1255 array_type_index: *array_type_index,
1256 });
1257 self
1258 }
1259
1260 fn array_set(&mut self, array_type_index: TypeID) -> &mut Self {
1261 self.inject(Operator::ArraySet {
1262 array_type_index: *array_type_index,
1263 });
1264 self
1265 }
1266
1267 fn array_len(&mut self) -> &mut Self {
1268 self.inject(Operator::ArrayLen);
1269 self
1270 }
1271
1272 fn array_fill(&mut self, array_type_index: TypeID) -> &mut Self {
1273 self.inject(Operator::ArrayFill {
1274 array_type_index: *array_type_index,
1275 });
1276 self
1277 }
1278
1279 fn array_copy(
1280 &mut self,
1281 array_type_index_dest: TypeID,
1282 array_type_index_src: TypeID,
1283 ) -> &mut Self {
1284 self.inject(Operator::ArrayCopy {
1285 array_type_index_dst: *array_type_index_dest,
1286 array_type_index_src: *array_type_index_src,
1287 });
1288 self
1289 }
1290
1291 fn array_init_data(
1292 &mut self,
1293 array_type_index: TypeID,
1294 array_data_index: DataSegmentID,
1295 ) -> &mut Self {
1296 self.inject(Operator::ArrayInitData {
1297 array_type_index: *array_type_index,
1298 array_data_index: *array_data_index,
1299 });
1300 self
1301 }
1302
1303 fn array_init_elem(
1304 &mut self,
1305 array_type_index: TypeID,
1306 array_elem_index: ElementID,
1307 ) -> &mut Self {
1308 self.inject(Operator::ArrayInitElem {
1309 array_type_index: *array_type_index,
1310 array_elem_index: *array_elem_index,
1311 });
1312 self
1313 }
1314
1315 fn ref_test(&mut self, heap_type: HeapType) -> &mut Self {
1316 self.inject(Operator::RefTestNonNull {
1317 hty: wasmparser::HeapType::from(heap_type),
1318 });
1319 self
1320 }
1321
1322 fn ref_test_null(&mut self, heap_type: HeapType) -> &mut Self {
1323 self.inject(Operator::RefTestNullable {
1324 hty: wasmparser::HeapType::from(heap_type),
1325 });
1326 self
1327 }
1328
1329 fn ref_cast(&mut self, heap_type: HeapType) -> &mut Self {
1330 self.inject(Operator::RefCastNonNull {
1331 hty: wasmparser::HeapType::from(heap_type),
1332 });
1333 self
1334 }
1335
1336 fn ref_cast_null(&mut self, heap_type: HeapType) -> &mut Self {
1337 self.inject(Operator::RefCastNullable {
1338 hty: wasmparser::HeapType::from(heap_type),
1339 });
1340 self
1341 }
1342
1343 fn any_convert_extern(&mut self) -> &mut Self {
1344 self.inject(Operator::AnyConvertExtern);
1345 self
1346 }
1347
1348 fn extern_convert_any(&mut self) -> &mut Self {
1349 self.inject(Operator::ExternConvertAny);
1350 self
1351 }
1352
1353 fn ref_i31(&mut self) -> &mut Self {
1354 self.inject(Operator::RefI31);
1355 self
1356 }
1357
1358 fn i31_get_s(&mut self) -> &mut Self {
1359 self.inject(Operator::I31GetS);
1360 self
1361 }
1362
1363 fn i31_get_u(&mut self) -> &mut Self {
1364 self.inject(Operator::I31GetU);
1365 self
1366 }
1367}
1368
1369#[allow(dead_code)]
1370pub trait MacroOpcode<'a>: Inject<'a> {
1375 fn u32_const(&mut self, value: u32) -> &mut Self {
1380 let i32_val = value as i32;
1381 self.inject(Operator::I32Const { value: i32_val });
1382 self
1383 }
1384 fn u64_const(&mut self, value: u64) -> &mut Self {
1389 let i64_val = value as i64;
1390 self.inject(Operator::I64Const { value: i64_val });
1391 self
1392 }
1393}