2017-05-10 17:04:09 +03:00
|
|
|
extern crate parity_wasm;
|
|
|
|
|
|
|
|
use std::env::args;
|
|
|
|
|
2017-05-30 17:24:22 +03:00
|
|
|
use parity_wasm::{interpreter, ModuleInstanceInterface};
|
2017-05-10 17:04:09 +03:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args: Vec<_> = args().collect();
|
2017-05-10 17:06:09 +03:00
|
|
|
if args.len() != 3 {
|
2017-05-10 17:04:09 +03:00
|
|
|
println!("Usage: {} <wasm file> <arg>", args[0]);
|
|
|
|
println!(" wasm file should contain exported `_call` function with single I32 argument");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-30 17:24:22 +03:00
|
|
|
let program = parity_wasm::ProgramInstance::with_env_params(
|
|
|
|
interpreter::EnvParams {
|
|
|
|
total_stack: 128*1024,
|
|
|
|
total_memory: 2*1024*1024,
|
|
|
|
allow_memory_growth: false,
|
|
|
|
}
|
|
|
|
).expect("Failed to load program");
|
2017-05-10 17:04:09 +03:00
|
|
|
let module = parity_wasm::deserialize_file(&args[1]).expect("Failed to load module");
|
|
|
|
let module = program.add_module("main", module).expect("Failed to initialize module");
|
2017-05-10 17:06:09 +03:00
|
|
|
let argument: i32 = args[2].parse().expect("Integer argument required");
|
2017-05-18 15:08:55 +03:00
|
|
|
println!("Result: {:?}", module.execute_export("_call", vec![parity_wasm::RuntimeValue::I32(argument)].into()));
|
2017-05-10 17:04:09 +03:00
|
|
|
}
|