2017-09-15 22:01:12 +03:00
|
|
|
extern crate parity_wasm;
|
2018-03-13 15:58:18 +03:00
|
|
|
extern crate pwasm_utils as utils;
|
2017-09-15 22:01:12 +03:00
|
|
|
extern crate clap;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
|
|
|
|
fn main() {
|
2018-03-13 15:58:18 +03:00
|
|
|
utils::init_log();
|
2017-09-15 22:01:12 +03:00
|
|
|
|
|
|
|
let matches = App::new("wasm-opt")
|
|
|
|
.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"))
|
|
|
|
.arg(Arg::with_name("exports")
|
|
|
|
.long("exports")
|
|
|
|
.short("e")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("functions")
|
|
|
|
.help("Comma-separated list of exported functions to keep. Default: _call"))
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let exports = matches
|
|
|
|
.value_of("exports")
|
|
|
|
.unwrap_or("_call")
|
|
|
|
.split(',')
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let input = matches.value_of("input").expect("is required; qed");
|
|
|
|
let output = matches.value_of("output").expect("is required; qed");
|
|
|
|
|
|
|
|
let mut module = parity_wasm::deserialize_file(&input).unwrap();
|
|
|
|
|
|
|
|
// Invoke optimizer
|
|
|
|
// Contract is supposed to have only these functions as public api
|
|
|
|
// All other symbols not usable by this list is optimized away
|
2018-03-13 15:58:18 +03:00
|
|
|
utils::optimize(&mut module, exports).expect("Optimizer to finish without errors");
|
2017-09-15 22:01:12 +03:00
|
|
|
|
|
|
|
parity_wasm::serialize_to_file(&output, module).unwrap();
|
|
|
|
}
|