1
1
use wasmer:: wasmparser:: {
2
- Export , Import , MemoryType , Parser , TableType , ValidPayload , Validator , WasmFeatures ,
2
+ Export , Import , MemoryType , Parser , Payload , TableType , Type , ValidPayload , Validator ,
3
+ WasmFeatures ,
3
4
} ;
4
5
5
6
use crate :: VmResult ;
@@ -13,6 +14,10 @@ pub struct ParsedWasm<'a> {
13
14
pub imports : Vec < Import < ' a > > ,
14
15
pub tables : Vec < TableType > ,
15
16
pub memories : Vec < MemoryType > ,
17
+ pub function_count : usize ,
18
+ pub type_count : u32 ,
19
+ pub max_func_params : usize ,
20
+ pub max_func_results : usize ,
16
21
}
17
22
18
23
impl < ' a > ParsedWasm < ' a > {
@@ -34,6 +39,10 @@ impl<'a> ParsedWasm<'a> {
34
39
imports : vec ! [ ] ,
35
40
tables : vec ! [ ] ,
36
41
memories : vec ! [ ] ,
42
+ function_count : 0 ,
43
+ type_count : 0 ,
44
+ max_func_params : 0 ,
45
+ max_func_results : 0 ,
37
46
} ;
38
47
39
48
let mut fun_allocations = Default :: default ( ) ;
@@ -45,20 +54,36 @@ impl<'a> ParsedWasm<'a> {
45
54
let mut fun_validator = fv. into_validator ( fun_allocations) ;
46
55
fun_validator. validate ( & body) ?;
47
56
fun_allocations = fun_validator. into_allocations ( ) ;
57
+
58
+ this. function_count += 1 ;
48
59
}
49
60
50
61
match p {
51
- wasmer:: wasmparser:: Payload :: Version { num, .. } => this. version = num,
52
- wasmer:: wasmparser:: Payload :: ImportSection ( i) => {
62
+ Payload :: TypeSection ( t) => {
63
+ this. type_count = t. get_count ( ) ;
64
+ for t_res in t {
65
+ let ty: Type = t_res?;
66
+ match ty {
67
+ Type :: Func ( ft) => {
68
+ this. max_func_params =
69
+ core:: cmp:: max ( ft. params ( ) . len ( ) , this. max_func_params ) ;
70
+ this. max_func_results =
71
+ core:: cmp:: max ( ft. results ( ) . len ( ) , this. max_func_results ) ;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ Payload :: Version { num, .. } => this. version = num,
77
+ Payload :: ImportSection ( i) => {
53
78
this. imports = i. into_iter ( ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
54
79
}
55
- wasmer :: wasmparser :: Payload :: TableSection ( t) => {
80
+ Payload :: TableSection ( t) => {
56
81
this. tables = t. into_iter ( ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
57
82
}
58
- wasmer :: wasmparser :: Payload :: MemorySection ( m) => {
83
+ Payload :: MemorySection ( m) => {
59
84
this. memories = m. into_iter ( ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
60
85
}
61
- wasmer :: wasmparser :: Payload :: ExportSection ( e) => {
86
+ Payload :: ExportSection ( e) => {
62
87
this. exports = e. into_iter ( ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
63
88
}
64
89
_ => { } // ignore everything else
0 commit comments