Skip to content

Commit

Permalink
Remove dependency on parity_wasm from chisel CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Sep 19, 2019
1 parent 4d3d98b commit c6b402c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2018"

[dependencies]
libchisel = { path = "../libchisel", version = "0.5.0" }
parity-wasm = "^0.40.2"
clap = "2.32.0"
serde = "1.0.80"
serde_derive = "1.0.80"
Expand Down
11 changes: 5 additions & 6 deletions chisel/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate libchisel;
extern crate parity_wasm;
#[macro_use]
extern crate clap;
extern crate serde;
Expand All @@ -10,7 +9,7 @@ extern crate serde_yaml;
mod logger;
mod config;

use std::fs::{read, read_to_string};
use std::fs::{read, read_to_string, write};
use std::process;

use libchisel::{
Expand All @@ -23,7 +22,6 @@ use libchisel::binaryenopt::*;

use clap::{App, Arg, ArgMatches, SubCommand};
use libchisel::*;
use parity_wasm::elements::{deserialize_buffer, serialize_to_file, Module};
use serde_yaml::Value;

// Error messages
Expand Down Expand Up @@ -311,7 +309,7 @@ fn execute_module(context: &ModuleContext, module: &mut Module) -> bool {

fn chisel_execute(context: &ChiselContext) -> Result<bool, &'static str> {
if let Ok(buffer) = read(context.file()) {
if let Ok(module) = deserialize_buffer::<Module>(&buffer) {
if let Ok(module) = module_from_bytes(&buffer) {
// If we do not parse the NamesSection here, parity-wasm will drop it at serialisation
// It is useful to have this for a number of optimisation passes, including binaryenopt and snip
// TODO: better error handling
Expand All @@ -327,12 +325,13 @@ fn chisel_execute(context: &ChiselContext) -> Result<bool, &'static str> {

// If the module was mutated, serialize to file.
if original != module {
let serialized = module.to_bytes().unwrap();
if let Some(path) = context.outfile() {
chisel_debug!(1, "Writing to file: {}", path);
serialize_to_file(path, module).unwrap();
write(path, serialized).unwrap();
} else {
chisel_debug!(1, "No output file specified; writing in place");
serialize_to_file(context.file(), module).unwrap();
write(context.file(), serialized).unwrap();
}
}
Ok(chisel_results)
Expand Down

0 comments on commit c6b402c

Please sign in to comment.