@@ -71,6 +71,14 @@ macro_rules! define_primitive_operands {
7171 }
7272 ) *
7373 } ;
74+ ( $( $name: ident, $instr: expr, $ty: ty, $ty2: ty) ,* ) => {
75+ $(
76+ fn $name( & mut self , arg: $ty, arg2: $ty) -> Self :: Output {
77+ self . instructions. push( $instr( arg, arg2) ) ;
78+ Ok ( ( ) )
79+ }
80+ ) *
81+ } ;
7482}
7583
7684macro_rules! define_mem_operands {
@@ -88,34 +96,6 @@ macro_rules! define_mem_operands {
8896 } ;
8997}
9098
91- macro_rules! impl_visit_operator {
92- ( @mvp $( $rest: tt) * ) => {
93- impl_visit_operator!( @@skipped $( $rest) * ) ;
94- } ;
95- ( @sign_extension $( $rest: tt) * ) => {
96- impl_visit_operator!( @@skipped $( $rest) * ) ;
97- } ;
98- ( @saturating_float_to_int $( $rest: tt) * ) => {
99- impl_visit_operator!( @@skipped $( $rest) * ) ;
100- } ;
101- ( @bulk_memory $( $rest: tt) * ) => {
102- impl_visit_operator!( @@skipped $( $rest) * ) ;
103- } ;
104- ( @reference_types $( $rest: tt) * ) => {
105- impl_visit_operator!( @@skipped $( $rest) * ) ;
106- } ;
107- ( @@skipped $op: ident $( { $( $arg: ident: $argty: ty) ,* } ) ? => $visit: ident $( $rest: tt) * ) => {
108- impl_visit_operator!( $( $rest) * ) ;
109- } ;
110- ( @$proposal: ident $op: ident $( { $( $arg: ident: $argty: ty) ,* } ) ? => $visit: ident $( $rest: tt) * ) => {
111- fn $visit( & mut self $( $( , $arg: $argty) * ) ?) -> Self :: Output {
112- self . unsupported( stringify!( $op) )
113- }
114- impl_visit_operator!( $( $rest) * ) ;
115- } ;
116- ( ) => { } ;
117- }
118-
11999pub ( crate ) struct FunctionBuilder {
120100 instructions : Vec < Instruction > ,
121101 label_ptrs : Vec < usize > ,
@@ -141,6 +121,10 @@ impl FunctionBuilder {
141121impl < ' a > wasmparser:: VisitOperator < ' a > for FunctionBuilder {
142122 type Output = Result < ( ) > ;
143123
124+ fn visit_default ( & mut self , op : & str ) -> Self :: Output {
125+ self . unsupported ( op)
126+ }
127+
144128 define_primitive_operands ! {
145129 visit_br, Instruction :: Br , u32 ,
146130 visit_br_if, Instruction :: BrIf , u32 ,
@@ -329,7 +313,6 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
329313 match instruction {
330314 Instruction :: LocalGet ( a) => * instruction = Instruction :: LocalGet2 ( * a, idx) ,
331315 Instruction :: LocalGet2 ( a, b) => * instruction = Instruction :: LocalGet3 ( * a, * b, idx) ,
332- // Instruction::LocalGet3(a, b, c) => *instruction = Instruction::LocalGet4(*a, *b, *c, idx),
333316 Instruction :: LocalTee ( a) => * instruction = Instruction :: LocalTeeGet ( * a, idx) ,
334317 _ => return self . visit ( Instruction :: LocalGet ( idx) ) ,
335318 } ;
@@ -502,24 +485,14 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
502485
503486 // Bulk Memory Operations
504487
505- fn visit_memory_init ( & mut self , data_index : u32 , mem : u32 ) -> Self :: Output {
506- self . visit ( Instruction :: MemoryInit ( data_index, mem) )
507- }
508-
509- fn visit_data_drop ( & mut self , data_index : u32 ) -> Self :: Output {
510- self . visit ( Instruction :: DataDrop ( data_index) )
511- }
512-
513- fn visit_memory_copy ( & mut self , dst_mem : u32 , src_mem : u32 ) -> Self :: Output {
514- self . visit ( Instruction :: MemoryCopy ( dst_mem, src_mem) )
515- }
516-
517- fn visit_memory_fill ( & mut self , mem : u32 ) -> Self :: Output {
518- self . visit ( Instruction :: MemoryFill ( mem) )
488+ define_primitive_operands ! {
489+ visit_memory_init, Instruction :: MemoryInit , u32 , u32 ,
490+ visit_memory_copy, Instruction :: MemoryCopy , u32 , u32 ,
491+ visit_table_init, Instruction :: TableInit , u32 , u32
519492 }
520-
521- fn visit_table_init ( & mut self , elem_index : u32 , table : u32 ) -> Self :: Output {
522- self . visit ( Instruction :: TableInit ( elem_index , table ) )
493+ define_primitive_operands ! {
494+ visit_memory_fill , Instruction :: MemoryFill , u32 ,
495+ visit_data_drop , Instruction :: DataDrop , u32
523496 }
524497
525498 fn visit_elem_drop ( & mut self , _elem_index : u32 ) -> Self :: Output {
@@ -540,33 +513,16 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
540513 self . visit ( Instruction :: RefIsNull )
541514 }
542515
543- fn visit_ref_func ( & mut self , idx : u32 ) -> Self :: Output {
544- self . visit ( Instruction :: RefFunc ( idx) )
545- }
546-
547516 fn visit_typed_select ( & mut self , ty : wasmparser:: ValType ) -> Self :: Output {
548517 self . visit ( Instruction :: Select ( Some ( convert_valtype ( & ty) ) ) )
549518 }
550519
551- fn visit_table_fill ( & mut self , table : u32 ) -> Self :: Output {
552- self . visit ( Instruction :: TableFill ( table) )
553- }
554-
555- fn visit_table_get ( & mut self , table : u32 ) -> Self :: Output {
556- self . visit ( Instruction :: TableGet ( table) )
557- }
558-
559- fn visit_table_set ( & mut self , table : u32 ) -> Self :: Output {
560- self . visit ( Instruction :: TableSet ( table) )
561- }
562-
563- fn visit_table_grow ( & mut self , table : u32 ) -> Self :: Output {
564- self . visit ( Instruction :: TableGrow ( table) )
565- }
566-
567- fn visit_table_size ( & mut self , table : u32 ) -> Self :: Output {
568- self . visit ( Instruction :: TableSize ( table) )
520+ define_primitive_operands ! {
521+ visit_ref_func, Instruction :: RefFunc , u32 ,
522+ visit_table_fill, Instruction :: TableFill , u32 ,
523+ visit_table_get, Instruction :: TableGet , u32 ,
524+ visit_table_set, Instruction :: TableSet , u32 ,
525+ visit_table_grow, Instruction :: TableGrow , u32 ,
526+ visit_table_size, Instruction :: TableSize , u32
569527 }
570-
571- wasmparser:: for_each_operator!( impl_visit_operator) ;
572528}
0 commit comments