runtime type injection implemented #10

This commit is contained in:
fro
2017-09-25 20:14:46 +03:00
parent a6b6d75be0
commit 9be2a5bf31
5 changed files with 67 additions and 2 deletions
+19 -1
View File
@@ -76,6 +76,14 @@ fn main() {
.arg(Arg::with_name("skip_alloc")
.help("Skip allocator externalizer step producing final wasm")
.long("skip-externalize"))
.arg(Arg::with_name("runtime_type")
.help("Injects RUNTIME_TYPE global export")
.takes_value(true)
.long("runtime-type"))
.arg(Arg::with_name("runtime_version")
.help("Injects RUNTIME_VERSION global export")
.takes_value(true)
.long("runtime-version"))
.get_matches();
let target_dir = matches.value_of("target").expect("is required; qed");
@@ -98,5 +106,15 @@ fn main() {
wasm_utils::optimize(&mut module, vec!["_call", "setTempRet0"]).expect("Optimizer to finish without errors");
}
if let Some(runtime_type) = matches.value_of("runtime_type") {
let runtime_type: &[u8] = runtime_type.as_bytes();
if runtime_type.len() != 4 {
panic!("--runtime-type should be equal to 4 bytes");
}
let runtime_version: u32 = matches.value_of("runtime_version").unwrap_or("1").parse()
.expect("--runtime-version should be a positive integer");
module = wasm_utils::inject_runtime_type(module, &runtime_type, runtime_version);
}
parity_wasm::serialize_to_file(&path, module).unwrap();
}
}