@@ -3,7 +3,7 @@ use crate::{conversion::convert_blocktype, Result};
3
3
use crate :: conversion:: { convert_heaptype, convert_memarg, convert_valtype} ;
4
4
use alloc:: string:: ToString ;
5
5
use alloc:: { boxed:: Box , format, vec:: Vec } ;
6
- use tinywasm_types:: { BlockArgsPacked , Instruction } ;
6
+ use tinywasm_types:: Instruction ;
7
7
use wasmparser:: { FuncValidator , FunctionBody , VisitOperator , WasmModuleResources } ;
8
8
9
9
struct ValidateThenVisit < ' a , T , U > ( T , & ' a mut U ) ;
@@ -65,16 +65,14 @@ macro_rules! define_primitive_operands {
65
65
( $( $name: ident, $instr: expr, $ty: ty) ,* ) => {
66
66
$(
67
67
fn $name( & mut self , arg: $ty) -> Self :: Output {
68
- self . instructions. push( $instr( arg) ) ;
69
- Ok ( ( ) )
68
+ Ok ( self . instructions. push( $instr( arg) ) )
70
69
}
71
70
) *
72
71
} ;
73
72
( $( $name: ident, $instr: expr, $ty: ty, $ty2: ty) ,* ) => {
74
73
$(
75
74
fn $name( & mut self , arg: $ty, arg2: $ty) -> Self :: Output {
76
- self . instructions. push( $instr( arg, arg2) ) ;
77
- Ok ( ( ) )
75
+ Ok ( self . instructions. push( $instr( arg, arg2) ) )
78
76
}
79
77
) *
80
78
} ;
@@ -112,8 +110,7 @@ impl FunctionBuilder {
112
110
113
111
#[ inline]
114
112
fn visit ( & mut self , op : Instruction ) -> Result < ( ) > {
115
- self . instructions . push ( op) ;
116
- Ok ( ( ) )
113
+ Ok ( self . instructions . push ( op) )
117
114
}
118
115
}
119
116
@@ -162,7 +159,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
162
159
visit_i64_load16_u, I64Load16U ,
163
160
visit_i64_load32_s, I64Load32S ,
164
161
visit_i64_load32_u, I64Load32U ,
165
- // visit_i32_store, I32Store,
162
+ // visit_i32_store, I32Store, custom implementation
166
163
visit_i64_store, I64Store ,
167
164
visit_f32_store, F32Store ,
168
165
visit_f64_store, F64Store ,
@@ -325,15 +322,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
325
322
let arg = convert_memarg ( memarg) ;
326
323
let i32store = Instruction :: I32Store { offset : arg. offset , mem_addr : arg. mem_addr } ;
327
324
328
- if self . instructions . len ( ) < 3 {
329
- return self . visit ( i32store) ;
330
- }
331
-
332
- #[ cold]
333
- fn cold ( ) { }
334
-
335
- if arg. mem_addr > 0xFF || arg. offset > 0xFFFF_FFFF {
336
- cold ( ) ;
325
+ if self . instructions . len ( ) < 3 || arg. mem_addr > 0xFF || arg. offset > 0xFFFF_FFFF {
337
326
return self . visit ( i32store) ;
338
327
}
339
328
@@ -353,31 +342,22 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
353
342
}
354
343
355
344
fn visit_local_get ( & mut self , idx : u32 ) -> Self :: Output {
356
- if let Some ( instruction) = self . instructions . last_mut ( ) {
357
- match instruction {
358
- Instruction :: LocalGet ( a) => * instruction = Instruction :: LocalGet2 ( * a, idx) ,
359
- Instruction :: LocalGet2 ( a, b) => * instruction = Instruction :: LocalGet3 ( * a, * b, idx) ,
360
- Instruction :: LocalTee ( a) => * instruction = Instruction :: LocalTeeGet ( * a, idx) ,
361
- _ => return self . visit ( Instruction :: LocalGet ( idx) ) ,
362
- } ;
363
- Ok ( ( ) )
364
- } else {
365
- self . visit ( Instruction :: LocalGet ( idx) )
366
- }
345
+ let Some ( instruction) = self . instructions . last_mut ( ) else {
346
+ return self . visit ( Instruction :: LocalGet ( idx) ) ;
347
+ } ;
348
+
349
+ match instruction {
350
+ Instruction :: LocalGet ( a) => * instruction = Instruction :: LocalGet2 ( * a, idx) ,
351
+ Instruction :: LocalGet2 ( a, b) => * instruction = Instruction :: LocalGet3 ( * a, * b, idx) ,
352
+ Instruction :: LocalTee ( a) => * instruction = Instruction :: LocalTeeGet ( * a, idx) ,
353
+ _ => return self . visit ( Instruction :: LocalGet ( idx) ) ,
354
+ } ;
355
+
356
+ Ok ( ( ) )
367
357
}
368
358
369
359
fn visit_local_set ( & mut self , idx : u32 ) -> Self :: Output {
370
360
self . visit ( Instruction :: LocalSet ( idx) )
371
- // if let Some(instruction) = self.instructions.last_mut() {
372
- // match instruction {
373
- // // Needs more testing, seems to make performance worse
374
- // // Instruction::LocalGet(a) => *instruction = Instruction::LocalGetSet(*a, idx),
375
- // _ => return self.visit(Instruction::LocalSet(idx)),
376
- // };
377
- // // Ok(())
378
- // } else {
379
- // self.visit(Instruction::LocalSet(idx))
380
- // }
381
361
}
382
362
383
363
fn visit_local_tee ( & mut self , idx : u32 ) -> Self :: Output {
@@ -426,7 +406,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
426
406
427
407
fn visit_if ( & mut self , ty : wasmparser:: BlockType ) -> Self :: Output {
428
408
self . label_ptrs . push ( self . instructions . len ( ) ) ;
429
- self . visit ( Instruction :: If ( BlockArgsPacked :: new ( convert_blocktype ( ty) ) , 0 , 0 ) )
409
+ self . visit ( Instruction :: If ( convert_blocktype ( ty) . into ( ) , 0 , 0 ) )
430
410
}
431
411
432
412
fn visit_else ( & mut self ) -> Self :: Output {
0 commit comments