1
1
extern crate libchisel;
2
- extern crate parity_wasm;
3
2
#[ macro_use]
4
3
extern crate clap;
5
4
extern crate serde;
@@ -10,7 +9,7 @@ extern crate serde_yaml;
10
9
mod logger;
11
10
mod config;
12
11
13
- use std:: fs:: { read, read_to_string} ;
12
+ use std:: fs:: { read, read_to_string, write } ;
14
13
use std:: process;
15
14
16
15
use libchisel:: {
@@ -23,7 +22,6 @@ use libchisel::binaryenopt::*;
23
22
24
23
use clap:: { App , Arg , ArgMatches , SubCommand } ;
25
24
use libchisel:: * ;
26
- use parity_wasm:: elements:: { deserialize_buffer, serialize_to_file, Module } ;
27
25
use serde_yaml:: Value ;
28
26
29
27
// Error messages
@@ -311,7 +309,7 @@ fn execute_module(context: &ModuleContext, module: &mut Module) -> bool {
311
309
312
310
fn chisel_execute ( context : & ChiselContext ) -> Result < bool , & ' static str > {
313
311
if let Ok ( buffer) = read ( context. file ( ) ) {
314
- if let Ok ( module) = deserialize_buffer :: < Module > ( & buffer) {
312
+ if let Ok ( module) = module_from_bytes ( & buffer) {
315
313
// If we do not parse the NamesSection here, parity-wasm will drop it at serialisation
316
314
// It is useful to have this for a number of optimisation passes, including binaryenopt and snip
317
315
// TODO: better error handling
@@ -327,12 +325,13 @@ fn chisel_execute(context: &ChiselContext) -> Result<bool, &'static str> {
327
325
328
326
// If the module was mutated, serialize to file.
329
327
if original != module {
328
+ let serialized = module. to_bytes ( ) . unwrap ( ) ;
330
329
if let Some ( path) = context. outfile ( ) {
331
330
chisel_debug ! ( 1 , "Writing to file: {}" , path) ;
332
- serialize_to_file ( path, module ) . unwrap ( ) ;
331
+ write ( path, serialized ) . unwrap ( ) ;
333
332
} else {
334
333
chisel_debug ! ( 1 , "No output file specified; writing in place" ) ;
335
- serialize_to_file ( context. file ( ) , module ) . unwrap ( ) ;
334
+ write ( context. file ( ) , serialized ) . unwrap ( ) ;
336
335
}
337
336
}
338
337
Ok ( chisel_results)
0 commit comments