2022-02-09 07:08:40 -06:00
|
|
|
pub mod host_functions;
|
|
|
|
|
|
|
|
extern crate wasmi;
|
|
|
|
// extern crate wabt;
|
|
|
|
|
|
|
|
use genfs::{Fs, OpenOptions};
|
2022-02-12 03:25:02 -06:00
|
|
|
use wasmi::{ImportsBuilder, ModuleInstance};
|
2022-02-09 07:08:40 -06:00
|
|
|
|
|
|
|
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
|
|
|
|
|
|
|
|
pub fn interp() {
|
2022-02-26 07:35:36 -06:00
|
|
|
trace!("Interpreting...");
|
2022-02-09 07:08:40 -06:00
|
|
|
let fs = &*FILE_SYSTEM.lock();
|
2022-02-26 07:35:36 -06:00
|
|
|
trace!("Got filesystem");
|
2022-02-09 07:08:40 -06:00
|
|
|
let file = fs
|
2022-02-26 07:35:36 -06:00
|
|
|
.open(
|
|
|
|
b"/home/able/bins/aos_wasm_stress_test.wasm",
|
|
|
|
OpenOptions::new().read(true),
|
|
|
|
)
|
2022-02-09 07:08:40 -06:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut wasm_binary = Vec::new();
|
|
|
|
|
|
|
|
let ret = file.read_to_end(&mut wasm_binary).unwrap();
|
2022-02-26 07:35:36 -06:00
|
|
|
trace!("Binary size {}", ret);
|
2022-02-09 07:08:40 -06:00
|
|
|
// Load wasm binary and prepare it for instantiation.
|
|
|
|
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
|
|
|
|
|
|
|
|
let imports = ImportsBuilder::new().with_resolver("env", &host_functions::HostExternals {});
|
|
|
|
|
|
|
|
// Instantiate a module with empty imports and
|
|
|
|
// assert that there is no `start` function.
|
|
|
|
let instance = ModuleInstance::new(&module, &imports)
|
|
|
|
.expect("failed to instantiate wasm module")
|
|
|
|
.assert_no_start();
|
|
|
|
|
|
|
|
let ret = instance
|
|
|
|
.invoke_export("start", &[], &mut HostExternals {})
|
|
|
|
.expect("failed to execute export");
|
|
|
|
|
2022-02-12 03:25:02 -06:00
|
|
|
println!("collected wasm return value: {:?}", ret);
|
2022-02-09 07:08:40 -06:00
|
|
|
}
|