Skip to content

Commit

Permalink
Calling import functions properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kthakore committed Jan 19, 2021
1 parent 0ad0593 commit a3224f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
3 changes: 3 additions & 0 deletions rune/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ pub fn run(container: &str, number_of_runs: i32) {
let vm = VM::init(container);
// Create a Provider
// Set up capabilities and use inputs from CLI params
for _ in 0..number_of_runs {
vm.call(vec![]);
}

}
43 changes: 35 additions & 8 deletions rune/src/run/vm.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use log;
use runic_types::*;
mod imports;
use imports::get_imports;

use wasmer_runtime::{instantiate, Func};
mod imports;

use tflite::ops::builtin::BuiltinOpResolver;
use tflite::{FlatBufferModel, InterpreterBuilder};
use wasmer_runtime::{instantiate, Func, Instance, Array, WasmPtr};


/// Rune Executor
/// Executes the Rune and provides the appropriate interfaces
pub struct VM {

instance: Instance
}

///
Expand All @@ -34,6 +30,37 @@ impl VM {

let manifest_size: u32 = manifest.call().expect("failed to call manifest");

return VM{};
return VM{ instance };
}

pub fn call(&self, input: Vec<u8>) -> Vec<u8> {
let instance = &self.instance;
let get_provider_response_buffer_pointer: Func<(), WasmPtr<u8, Array>> = instance
.exports
.get("provider_response_ptr")
.expect("provider_response_ptr");

let pr_ptr = get_provider_response_buffer_pointer.call().unwrap();

let wasm_instance_memory = instance.context().memory(0);
log::debug!("Trying to write provider response");
let len = input.len() as u32;
let memory_writer = pr_ptr.deref(wasm_instance_memory, 0, len).unwrap();

//Refactor THIS
let mut idx = 0;
for b in input.into_iter() {
memory_writer[idx].set(b);
idx = idx + 1;
}

let call_fn: Func<u32, i32> = instance.exports.get("_call").unwrap();

let feature_buff_size = call_fn.call(len).expect("failed to _call");
log::debug!("Guest::_call() returned {}", feature_buff_size);

let feature_data_buf: Vec<u8> = vec![];

return feature_data_buf;
}
}

0 comments on commit a3224f7

Please sign in to comment.