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

@@ -130,8 +130,13 @@ impl ControlStackFrame {
/// - The depth of the two unreachable control blocks stacks, that are manipulated when translating
/// unreachable code;
pub struct TranslationState {
/// A stack of values corresponding to the active values in the input wasm function at this
/// point.
pub stack: Vec<Value>,
/// A stack of active control flow operations at this point in the input wasm function.
pub control_stack: Vec<ControlStackFrame>,
/// Is the current translation state still reachable? This is false when translating operators
/// like End, Return, or Unreachable.
pub reachable: bool,
// Map of global variables that have already been created by `FuncEnvironment::make_global`.
@@ -155,6 +160,7 @@ pub struct TranslationState {
}
impl TranslationState {
/// Construct a new, empty, `TranslationState`
pub fn new() -> Self {
Self {
stack: Vec::new(),
@@ -242,7 +248,7 @@ impl TranslationState {
&self.stack[self.stack.len() - n..]
}
// Push a block on the control stack.
/// Push a block on the control stack.
pub fn push_block(&mut self, following_code: Ebb, num_result_types: usize) {
self.control_stack.push(ControlStackFrame::Block {
destination: following_code,
@@ -252,7 +258,7 @@ impl TranslationState {
});
}
// Push a loop on the control stack.
/// Push a loop on the control stack.
pub fn push_loop(&mut self, header: Ebb, following_code: Ebb, num_result_types: usize) {
self.control_stack.push(ControlStackFrame::Loop {
header,
@@ -262,7 +268,7 @@ impl TranslationState {
});
}
// Push an if on the control stack.
/// Push an if on the control stack.
pub fn push_if(&mut self, branch_inst: Inst, following_code: Ebb, num_result_types: usize) {
self.control_stack.push(ControlStackFrame::If {
branch_inst,