From 04ac17c3d52eb58469a69b0e2be6aa7ea50c6f13 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 18 May 2018 16:21:25 +0400 Subject: [PATCH 1/3] additional binary --- cli/Cargo.toml | 4 ++++ cli/pack/main.rs | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 cli/pack/main.rs diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 0634e10..81b9201 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -29,6 +29,10 @@ path = "build/main.rs" name = "wasm-stack-height" path = "stack_height/main.rs" +[[bin]] +name = "wasm-pack" +path = "pack/main.rs" + [dependencies] parity-wasm = "0.30" pwasm-utils = { path = "..", version = "0.2" } diff --git a/cli/pack/main.rs b/cli/pack/main.rs new file mode 100644 index 0000000..8a55e80 --- /dev/null +++ b/cli/pack/main.rs @@ -0,0 +1,3 @@ +fn main() { + +} \ No newline at end of file From 367514ae0799cd0fd2e14865c3e2a3a539c0a8c5 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 18 May 2018 16:37:49 +0400 Subject: [PATCH 2/3] actual implementation of packer --- cli/pack/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/cli/pack/main.rs b/cli/pack/main.rs index 8a55e80..efed359 100644 --- a/cli/pack/main.rs +++ b/cli/pack/main.rs @@ -1,3 +1,35 @@ +extern crate parity_wasm; +extern crate pwasm_utils as utils; +extern crate pwasm_utils_cli as logger; +extern crate clap; + +use clap::{App, Arg}; + fn main() { - -} \ No newline at end of file + logger::init_log(); + + let matches = App::new("wasm-pack") + .arg(Arg::with_name("input") + .index(1) + .required(true) + .help("Input WASM file")) + .arg(Arg::with_name("output") + .index(2) + .required(true) + .help("Output WASM file")) + .get_matches(); + + let input = matches.value_of("input").expect("is required; qed"); + let output = matches.value_of("output").expect("is required; qed"); + + let module = parity_wasm::deserialize_file(&input).unwrap(); + let ctor_module = module.clone(); + let raw_module = parity_wasm::serialize(module).expect("Serialization failed"); + + // Invoke packer + let mut result_module = utils::pack_instance(raw_module, ctor_module).expect("Packing failed"); + // Optimize constructor, since it does not need everything + utils::optimize(&mut result_module, vec![utils::CALL_SYMBOL]).expect("Optimization failed"); + + parity_wasm::serialize_to_file(&output, result_module).expect("Serialization failed"); +} From 5609a08e9954ac102ca3ecba68a9a527ca74d103 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 18 May 2018 16:47:06 +0400 Subject: [PATCH 3/3] change to expect --- cli/pack/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/pack/main.rs b/cli/pack/main.rs index efed359..7206241 100644 --- a/cli/pack/main.rs +++ b/cli/pack/main.rs @@ -22,7 +22,7 @@ fn main() { let input = matches.value_of("input").expect("is required; qed"); let output = matches.value_of("output").expect("is required; qed"); - let module = parity_wasm::deserialize_file(&input).unwrap(); + let module = parity_wasm::deserialize_file(&input).expect("Input module deserialization failed"); let ctor_module = module.clone(); let raw_module = parity_wasm::serialize(module).expect("Serialization failed");