Skip to content

Commit 90c0633

Browse files
committed
start implementation of FuncTranslator::visit_if
1 parent ba5c994 commit 90c0633

File tree

1 file changed

+34
-1
lines changed
  • crates/wasmi/src/engine/translator/func2

1 file changed

+34
-1
lines changed

crates/wasmi/src/engine/translator/func2/visit.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use super::{ControlFrame, FuncTranslator, LocalIdx, UnreachableControlFrame};
2-
use crate::{core::wasm, engine::BlockType, ir::Instruction, Error};
2+
use crate::{
3+
core::wasm,
4+
engine::{
5+
translator::func2::{stack::IfReachability, Operand},
6+
BlockType,
7+
},
8+
ir::Instruction,
9+
Error,
10+
};
311
use wasmparser::VisitOperator;
412

513
macro_rules! impl_visit_operator {
@@ -102,6 +110,31 @@ impl<'a> VisitOperator<'a> for FuncTranslator {
102110
}
103111

104112
fn visit_if(&mut self, _block_ty: wasmparser::BlockType) -> Self::Output {
113+
if !self.reachable {
114+
self.stack.push_unreachable(UnreachableControlFrame::If)?;
115+
return Ok(());
116+
}
117+
let end_label = self.labels.new_label();
118+
let condition = self.stack.pop();
119+
let (reachability, consume_fuel_instr) = match condition {
120+
Operand::Immediate(operand) => {
121+
let condition = i32::from(operand.val());
122+
let reachability = match condition {
123+
0 => {
124+
self.reachable = false;
125+
IfReachability::OnlyElse
126+
}
127+
_ => IfReachability::OnlyThen,
128+
};
129+
let consume_fuel_instr = self.stack.consume_fuel_instr();
130+
(reachability, consume_fuel_instr)
131+
}
132+
operand => {
133+
let else_label = self.labels.new_label();
134+
let reachability = IfReachability::Both { else_label };
135+
todo!()
136+
}
137+
};
105138
todo!()
106139
}
107140

0 commit comments

Comments
 (0)