Move translation state initialization into a method.
This commit is contained in:
@@ -108,17 +108,11 @@ pub fn translate_function_body(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut state = TranslationState::new();
|
|
||||||
|
|
||||||
// We initialize the control stack with the implicit function block
|
// We initialize the control stack with the implicit function block
|
||||||
|
let mut state = TranslationState::new();
|
||||||
let end_ebb = builder.create_ebb();
|
let end_ebb = builder.create_ebb();
|
||||||
state.push_block(
|
state.initialize(sig, end_ebb);
|
||||||
end_ebb,
|
|
||||||
sig.return_types
|
|
||||||
.iter()
|
|
||||||
.map(|argty| argty.value_type)
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
// Now the main loop that reads every wasm instruction and translates it
|
// Now the main loop that reads every wasm instruction and translates it
|
||||||
loop {
|
loop {
|
||||||
let parser_state = parser.read();
|
let parser_state = parser.read();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! The `TranslationState` struct defined in this module is used to keep track of the WebAssembly
|
//! The `TranslationState` struct defined in this module is used to keep track of the WebAssembly
|
||||||
//! value and control stacks during the translation of a single function.
|
//! value and control stacks during the translation of a single function.
|
||||||
|
|
||||||
use cretonne::ir::{Ebb, Inst, Type, Value};
|
use cretonne::ir::{self, Ebb, Inst, Type, Value};
|
||||||
|
|
||||||
/// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following
|
/// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following
|
||||||
/// fields:
|
/// fields:
|
||||||
@@ -116,6 +116,29 @@ impl TranslationState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.stack.clear();
|
||||||
|
self.control_stack.clear();
|
||||||
|
self.phantom_unreachable_stack_depth = 0;
|
||||||
|
self.real_unreachable_stack_depth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize the state for compiling a function with the given signature.
|
||||||
|
///
|
||||||
|
/// This resets the state to containing only a single block representing the whole function.
|
||||||
|
/// The exit block is the last block in the function which will contain the return instruction.
|
||||||
|
pub fn initialize(&mut self, sig: &ir::Signature, exit_block: Ebb) {
|
||||||
|
self.clear();
|
||||||
|
self.push_block(
|
||||||
|
exit_block,
|
||||||
|
sig.return_types
|
||||||
|
.iter()
|
||||||
|
.filter(|arg| arg.purpose == ir::ArgumentPurpose::Normal)
|
||||||
|
.map(|argty| argty.value_type)
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Push a value.
|
/// Push a value.
|
||||||
pub fn push1(&mut self, val: Value) {
|
pub fn push1(&mut self, val: Value) {
|
||||||
self.stack.push(val);
|
self.stack.push(val);
|
||||||
|
|||||||
Reference in New Issue
Block a user