11extern crate libchisel;
2- extern crate parity_wasm;
32#[ macro_use]
43extern crate clap;
54extern crate serde;
@@ -10,7 +9,7 @@ extern crate serde_yaml;
109mod logger;
1110mod config;
1211
13- use std:: fs:: { read, read_to_string} ;
12+ use std:: fs:: { read, read_to_string, write } ;
1413use std:: process;
1514
1615use libchisel:: {
@@ -23,7 +22,6 @@ use libchisel::binaryenopt::*;
2322
2423use clap:: { App , Arg , ArgMatches , SubCommand } ;
2524use libchisel:: * ;
26- use parity_wasm:: elements:: { deserialize_buffer, serialize_to_file, Module } ;
2725use serde_yaml:: Value ;
2826
2927// Error messages
@@ -311,7 +309,7 @@ fn execute_module(context: &ModuleContext, module: &mut Module) -> bool {
311309
312310fn chisel_execute ( context : & ChiselContext ) -> Result < bool , & ' static str > {
313311 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) {
315313 // If we do not parse the NamesSection here, parity-wasm will drop it at serialisation
316314 // It is useful to have this for a number of optimisation passes, including binaryenopt and snip
317315 // TODO: better error handling
@@ -327,12 +325,13 @@ fn chisel_execute(context: &ChiselContext) -> Result<bool, &'static str> {
327325
328326 // If the module was mutated, serialize to file.
329327 if original != module {
328+ let serialized = module. to_bytes ( ) . expect ( "Failed to serialize Module" ) ;
330329 if let Some ( path) = context. outfile ( ) {
331330 chisel_debug ! ( 1 , "Writing to file: {}" , path) ;
332- serialize_to_file ( path, module ) . unwrap ( ) ;
331+ write ( path, serialized ) . unwrap ( ) ;
333332 } else {
334333 chisel_debug ! ( 1 , "No output file specified; writing in place" ) ;
335- serialize_to_file ( context. file ( ) , module ) . unwrap ( ) ;
334+ write ( context. file ( ) , serialized ) . unwrap ( ) ;
336335 }
337336 }
338337 Ok ( chisel_results)
0 commit comments