From 367514ae0799cd0fd2e14865c3e2a3a539c0a8c5 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 18 May 2018 16:37:49 +0400 Subject: [PATCH] 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"); +}