cranelift-wasm hooks to instrument wasm operators (#861)

* cranelift-wasm hooks to instrument wasm operators
This commit is contained in:
Andy Wortman
2019-07-25 09:36:17 -07:00
committed by GitHub
parent feecd23967
commit b7a9d65458
4 changed files with 84 additions and 54 deletions

View File

@@ -14,9 +14,11 @@ use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::ir::immediates::Offset32;
use cranelift_codegen::ir::{self, InstBuilder};
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use failure_derive::Fail;
use std::boxed::Box;
use wasmparser::BinaryReaderError;
use wasmparser::Operator;
/// The value of a WebAssembly global variable.
#[derive(Clone, Copy)]
@@ -253,6 +255,26 @@ pub trait FuncEnvironment {
// By default, don't emit anything.
Ok(())
}
/// Optional callback for the `FunctionEnvironment` performing this translation to maintain
/// internal state or prepare custom state for the operator to translate
fn before_translate_operator(
&mut self,
_op: &Operator,
_builder: &mut FunctionBuilder,
) -> WasmResult<()> {
Ok(())
}
/// Optional callback for the `FunctionEnvironment` performing this translation to maintain
/// internal state or finalize custom state for the operator that was translated
fn after_translate_operator(
&mut self,
_op: &Operator,
_builder: &mut FunctionBuilder,
) -> WasmResult<()> {
Ok(())
}
}
/// An object satisfying the `ModuleEnvironment` trait can be passed as argument to the