Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on parity_wasm from chisel CLI #159

Merged
merged 3 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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().expect("Failed to serialize Module");
if let Some(path) = context.outfile() {
chisel_debug!(1, "Writing to file: {}", path);
serialize_to_file(path, module).unwrap();
write(path, serialized).unwrap();
axic marked this conversation as resolved.
Show resolved Hide resolved
} 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
2 changes: 1 addition & 1 deletion libchisel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate binaryen;
extern crate parity_wasm;
extern crate rustc_hex;

use parity_wasm::elements::Module;
pub use parity_wasm::elements::Module;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed yet, but perhaps we could benefit from a prelude of sorts containing re-exports and the like.

axic marked this conversation as resolved.
Show resolved Hide resolved

use std::{error, fmt};

Expand Down