Browse Source

feat: allow WitnessCalculator construction from wasmer::Module (#24)

* Allow construction from Module

* Update src/witness/witness_calculator.rs

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
pull/3/head
Remco Bloemen 2 years ago
committed by GitHub
parent
commit
a93c8b03d4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions
  1. +18
    -9
      src/witness/witness_calculator.rs

+ 18
- 9
src/witness/witness_calculator.rs

@ -54,25 +54,34 @@ fn to_array32(s: &BigInt, size: usize) -> Vec {
impl WitnessCalculator { impl WitnessCalculator {
pub fn new(path: impl AsRef<std::path::Path>) -> Result<Self> { pub fn new(path: impl AsRef<std::path::Path>) -> Result<Self> {
Self::from_file(path)
}
pub fn from_file(path: impl AsRef<std::path::Path>) -> Result<Self> {
let store = Store::default(); let store = Store::default();
let module = Module::from_file(&store, path)?; let module = Module::from_file(&store, path)?;
Self::from_module(module)
}
pub fn from_module(module: Module) -> Result<Self> {
let store = module.store();
// Set up the memory // Set up the memory
let memory = Memory::new(&store, MemoryType::new(2000, None, false)).unwrap();
let memory = Memory::new(store, MemoryType::new(2000, None, false)).unwrap();
let import_object = imports! { let import_object = imports! {
"env" => { "env" => {
"memory" => memory.clone(), "memory" => memory.clone(),
}, },
// Host function callbacks from the WASM // Host function callbacks from the WASM
"runtime" => { "runtime" => {
"error" => runtime::error(&store),
"logSetSignal" => runtime::log_signal(&store),
"logGetSignal" => runtime::log_signal(&store),
"logFinishComponent" => runtime::log_component(&store),
"logStartComponent" => runtime::log_component(&store),
"log" => runtime::log_component(&store),
"exceptionHandler" => runtime::exception_handler(&store),
"showSharedRWMemory" => runtime::show_memory(&store),
"error" => runtime::error(store),
"logSetSignal" => runtime::log_signal(store),
"logGetSignal" => runtime::log_signal(store),
"logFinishComponent" => runtime::log_component(store),
"logStartComponent" => runtime::log_component(store),
"log" => runtime::log_component(store),
"exceptionHandler" => runtime::exception_handler(store),
"showSharedRWMemory" => runtime::show_memory(store),
} }
}; };
let instance = Wasm::new(Instance::new(&module, &import_object)?); let instance = Wasm::new(Instance::new(&module, &import_object)?);

Loading…
Cancel
Save