argument parsing, mem ext stub

This commit is contained in:
NikVolf
2017-12-26 14:03:08 +03:00
parent 2fd7d50586
commit fceb0ce7f1
2 changed files with 37 additions and 1 deletions
+15 -1
View File
@@ -81,11 +81,25 @@ fn main() {
.help("Injects RUNTIME_VERSION global export")
.takes_value(true)
.long("runtime-version"))
.arg(Arg::with_name("source_target")
.help("Skip symbol optimization step producing final wasm")
.takes_value(true)
.long("target"))
.get_matches();
let target_dir = matches.value_of("target").expect("is required; qed");
let wasm_binary = matches.value_of("wasm").expect("is required; qed");
let source_input = source::SourceInput::new(target_dir, wasm_binary);
let mut source_input = source::SourceInput::new(target_dir, wasm_binary);
let source_target_val = matches.value_of("source_target").unwrap_or_else(|| "wasm32-unknown-emscripten");
if source_target_val == "wasm32-unknown-unknown" {
source_input = source_input.unknown()
} else if source_target_val == "wasm32-unknown-emscripten" {
source_input = source_input.emscripten()
} else {
println!("--target can be: 'wasm32-unknown-emscripten' or 'wasm32-unknown-unknown'");
::std::process::exit(1);
}
process_output(&source_input).expect("Failed to process cargo target directory");
+22
View File
@@ -18,6 +18,28 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, original_imports: usiz
}
}
pub fn memory_section<'a>(module: &'a mut elements::Module) -> Option<&'a mut elements::MemorySection> {
for section in module.sections_mut() {
match section {
&mut elements::Section::Memory(ref mut sect) => {
return Some(sect);
},
_ => { }
}
}
None
}
pub fn externalize_mem(mut module: elements::Module) -> elements::Module {
let entry = memory_section(&mut module)
.expect("Memory section to exist")
.entries_mut()
.pop()
.expect("Own memory entry to exist in memory section");
module
}
pub fn externalize(
module: elements::Module,
replaced_funcs: Vec<&str>,