Skip to content

Commit b889953

Browse files
committed
implement FuncTranslator::register_locals
1 parent 7705d22 commit b889953

File tree

2 files changed

+23
-5
lines changed
  • crates/wasmi/src/engine/translator/translator2

2 files changed

+23
-5
lines changed

crates/wasmi/src/engine/translator/translator2/layout/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ mod consts;
22

33
use self::consts::ConstRegistry;
44
use super::{LocalIdx, OperandIdx, Reset};
5-
use crate::{core::UntypedVal, engine::TranslationError, ir::Reg, Error};
5+
use crate::{
6+
core::{UntypedVal, ValType},
7+
engine::TranslationError,
8+
ir::Reg,
9+
Error,
10+
};
611

712
#[cfg(doc)]
813
use super::Stack;
@@ -24,6 +29,16 @@ impl Reset for StackLayout {
2429
}
2530

2631
impl StackLayout {
32+
/// Register `amount` local variables of common type `ty`.
33+
///
34+
/// # Errors
35+
///
36+
/// If too many local variables are being registered.
37+
pub fn register_locals(&mut self, amount: u32, ty: ValType) -> Result<(), Error> {
38+
self.len_locals += amount as usize;
39+
Ok(())
40+
}
41+
2742
/// Returns the [`StackSpace`] of the [`Reg`].
2843
///
2944
/// Returns `None` if the [`Reg`] is unknown to the [`Stack`].

crates/wasmi/src/engine/translator/translator2/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use self::{
1515
use crate::{
1616
core::FuelCostsProvider,
1717
engine::{translator::WasmTranslator, CompiledFuncEntity},
18-
module::{FuncIdx, ModuleHeader},
18+
module::{FuncIdx, ModuleHeader, WasmiValueType},
1919
Engine,
2020
Error,
2121
};
@@ -79,10 +79,13 @@ impl WasmTranslator<'_> for FuncTranslator {
7979

8080
fn translate_locals(
8181
&mut self,
82-
_amount: u32,
83-
_value_type: wasmparser::ValType,
82+
amount: u32,
83+
value_type: wasmparser::ValType,
8484
) -> Result<(), Error> {
85-
todo!()
85+
let ty = WasmiValueType::from(value_type).into_inner();
86+
self.stack.register_locals(amount, ty)?;
87+
self.layout.register_locals(amount, ty)?;
88+
Ok(())
8689
}
8790

8891
fn finish_translate_locals(&mut self) -> Result<(), Error> {

0 commit comments

Comments
 (0)