Skip to content

Commit

Permalink
feat: allow state in HookSet
Browse files Browse the repository at this point in the history
This is quite useful for example when doing statement coverage. One
could store a MPSC tx end inside a BranchHookSet in order to send the
current program counter on every branching instruction. Stateless are
still possible and should be zero cost, they can be implemented by just
using an empty struct on which the HookSet trait is implemented.
  • Loading branch information
wucke13 committed Jul 10, 2024
1 parent 7f382f5 commit a035607
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::marker::PhantomData;

use alloc::vec::Vec;

use value_stack::Stack;
Expand Down Expand Up @@ -35,20 +33,20 @@ where
wasm_bytecode: &'b [u8],
types: Vec<FuncType>,
store: Store,
hook_set: PhantomData<H>,
pub hook_set: H,
}

impl<'b> RuntimeInstance<'b, EmptyHookSet> {
pub fn new(validation_info: &'_ ValidationInfo<'b>) -> Result<Self> {
Self::new_with_hooks(validation_info)
Self::new_with_hooks(validation_info, EmptyHookSet)
}
}

impl<'b, H> RuntimeInstance<'b, H>
where
H: HookSet,
{
pub fn new_with_hooks(validation_info: &'_ ValidationInfo<'b>) -> Result<Self> {
pub fn new_with_hooks(validation_info: &'_ ValidationInfo<'b>, hook_set: H) -> Result<Self> {
trace!("Starting instantiation of bytecode");

let store = Self::init_store(validation_info);
Expand All @@ -57,7 +55,7 @@ where
wasm_bytecode: validation_info.wasm,
types: validation_info.types.clone(),
store,
hook_set: PhantomData,
hook_set,
};

if let Some(start) = validation_info.start {
Expand Down

0 comments on commit a035607

Please sign in to comment.