@@ -4,10 +4,9 @@ use crate::program::Program;
4
4
use std:: collections:: HashMap ;
5
5
6
6
use parity_wasm:: elements:: { ImportCountType , Module } ;
7
- use wasmparser:: { Operator , Parser , ParserState , WasmDecoder } ;
8
7
9
- # [ allow ( unused ) ]
10
- pub ( crate ) fn read_program ( wasm : & [ u8 ] ) -> Program {
8
+ /// Reads wasm input and contruct a `Program` struct
9
+ pub fn read_program ( wasm : & [ u8 ] ) -> Program {
11
10
let mut functions = HashMap :: new ( ) ;
12
11
13
12
let module: Module = parity_wasm:: deserialize_buffer ( wasm) . unwrap ( ) ;
@@ -27,48 +26,3 @@ pub(crate) fn read_program(wasm: &[u8]) -> Program {
27
26
imported_count,
28
27
}
29
28
}
30
-
31
- #[ allow( unused) ]
32
- pub ( crate ) fn parse_program ( wasm : & [ u8 ] ) -> HashMap < FuncIndex , Vec < Operator > > {
33
- let mut parser = Parser :: new ( wasm) ;
34
- let mut function_readers = Vec :: new ( ) ;
35
-
36
- while !( parser. eof ( ) ) {
37
- match parser. read ( ) {
38
- ParserState :: BeginFunctionBody { .. } => {
39
- while !( parser. eof ( ) ) {
40
- let reader = parser. create_binary_reader ( ) ;
41
- function_readers. push ( reader) ;
42
- }
43
- }
44
- _ => continue ,
45
- }
46
- }
47
-
48
- for ( i, reader) in function_readers. iter_mut ( ) . enumerate ( ) {
49
- while let Ok ( ref op) = reader. read_operator ( ) {
50
- //
51
- }
52
- }
53
-
54
- panic ! ( )
55
-
56
- // let mut functions = HashMap::new();
57
- //
58
- // let module: Module = parity_wasm::deserialize_buffer(wasm).unwrap();
59
- //
60
- // let code_section = module.code_section().expect("no code section");
61
- // let imported_count = module.import_count(ImportCountType::Function) as u32;
62
- //
63
- // for (i, func_body) in code_section.bodies().iter().enumerate() {
64
- // let fn_idx = FuncIndex((i as u32) + imported_count);
65
- // let fn_body = FuncBody(func_body.code().clone());
66
- //
67
- // functions.insert(fn_idx, fn_body);
68
- // }
69
- //
70
- // Program {
71
- // functions,
72
- // imported_count,
73
- // }
74
- }
0 commit comments