From a93c8b03d4376e197ceb36aa410a8903c283dab7 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Sat, 19 Mar 2022 11:21:03 -0700 Subject: [PATCH] feat: allow WitnessCalculator construction from wasmer::Module (#24) * Allow construction from Module * Update src/witness/witness_calculator.rs Co-authored-by: Georgios Konstantopoulos --- src/witness/witness_calculator.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/witness/witness_calculator.rs b/src/witness/witness_calculator.rs index 6af0961..c32c7ee 100644 --- a/src/witness/witness_calculator.rs +++ b/src/witness/witness_calculator.rs @@ -54,25 +54,34 @@ fn to_array32(s: &BigInt, size: usize) -> Vec { impl WitnessCalculator { pub fn new(path: impl AsRef) -> Result { + Self::from_file(path) + } + + pub fn from_file(path: impl AsRef) -> Result { let store = Store::default(); let module = Module::from_file(&store, path)?; + Self::from_module(module) + } + + pub fn from_module(module: Module) -> Result { + let store = module.store(); // 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! { "env" => { "memory" => memory.clone(), }, // Host function callbacks from the WASM "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)?);