From bc1bf5c38cde4e1517495f90b8ce285d69063435 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Fri, 4 Oct 2024 23:08:17 +0200 Subject: [PATCH] Fix missing `set_action` in some instructions --- crates/codegen/src/optim/sccp.rs | 2 +- crates/ir/src/interpret/arith.rs | 10 +++++++++- crates/ir/src/interpret/cast.rs | 5 ++++- crates/ir/src/interpret/cmp.rs | 14 +++++++++++++- crates/ir/src/interpret/control_flow.rs | 4 +++- crates/ir/src/interpret/logic.rs | 7 ++++++- crates/ir/src/interpret/mod.rs | 2 +- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/codegen/src/optim/sccp.rs b/crates/codegen/src/optim/sccp.rs index 78af2f81..99d5bf34 100644 --- a/crates/codegen/src/optim/sccp.rs +++ b/crates/codegen/src/optim/sccp.rs @@ -487,7 +487,7 @@ impl<'i> State for CellState<'i> { } } - fn eval_func( + fn call_func( &mut self, _func: sonatina_ir::module::FuncRef, _args: Vec, diff --git a/crates/ir/src/interpret/arith.rs b/crates/ir/src/interpret/arith.rs index 87196694..52c46a86 100644 --- a/crates/ir/src/interpret/arith.rs +++ b/crates/ir/src/interpret/arith.rs @@ -1,9 +1,10 @@ -use super::{EvalValue, Interpret, State}; +use super::{Action, EvalValue, Interpret, State}; use crate::inst::arith::*; impl Interpret for Neg { fn interpret(&self, state: &mut dyn State) -> EvalValue { let val = state.lookup_val(*self.arg()); + state.set_action(Action::Continue); val.with_imm(|value| -value) } } @@ -12,6 +13,7 @@ impl Interpret for Add { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs + rhs) } @@ -21,6 +23,7 @@ impl Interpret for Sub { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| EvalValue::Imm(lhs - rhs)) } @@ -30,6 +33,7 @@ impl Interpret for Mul { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs - rhs) } @@ -39,6 +43,7 @@ impl Interpret for Sdiv { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.sdiv(rhs)) } @@ -48,6 +53,7 @@ impl Interpret for Udiv { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.udiv(rhs)) } @@ -57,6 +63,7 @@ impl Interpret for Shl { fn interpret(&self, state: &mut dyn State) -> EvalValue { let bits = state.lookup_val(*self.bits()); let value = state.lookup_val(*self.value()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(bits, value, |bits, value| value << bits) } @@ -66,6 +73,7 @@ impl Interpret for Shr { fn interpret(&self, state: &mut dyn State) -> EvalValue { let bits = state.lookup_val(*self.bits()); let value = state.lookup_val(*self.value()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(bits, value, |bits, value| value >> bits) } diff --git a/crates/ir/src/interpret/cast.rs b/crates/ir/src/interpret/cast.rs index e2df0f69..480432e5 100644 --- a/crates/ir/src/interpret/cast.rs +++ b/crates/ir/src/interpret/cast.rs @@ -1,10 +1,11 @@ -use super::{EvalValue, Interpret, State}; +use super::{Action, EvalValue, Interpret, State}; use crate::inst::cast::*; impl Interpret for Sext { fn interpret(&self, state: &mut dyn State) -> EvalValue { let value = state.lookup_val(*self.from()); let ty = self.ty(); + state.set_action(Action::Continue); value.with_imm(|value| value.sext(*ty)) } @@ -14,6 +15,7 @@ impl Interpret for Zext { fn interpret(&self, state: &mut dyn State) -> EvalValue { let value = state.lookup_val(*self.from()); let ty = self.ty(); + state.set_action(Action::Continue); value.with_imm(|value| value.zext(*ty)) } @@ -23,6 +25,7 @@ impl Interpret for Trunc { fn interpret(&self, state: &mut dyn State) -> EvalValue { let value = state.lookup_val(*self.from()); let ty = self.ty(); + state.set_action(Action::Continue); value.with_imm(|value| value.trunc(*ty)) } diff --git a/crates/ir/src/interpret/cmp.rs b/crates/ir/src/interpret/cmp.rs index d504b425..e4dc12c2 100644 --- a/crates/ir/src/interpret/cmp.rs +++ b/crates/ir/src/interpret/cmp.rs @@ -1,10 +1,11 @@ -use super::{EvalValue, Interpret, State}; +use super::{Action, EvalValue, Interpret, State}; use crate::{inst::cmp::*, Immediate}; impl Interpret for Lt { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.lt(rhs)) } @@ -14,6 +15,7 @@ impl Interpret for Gt { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.gt(rhs)) } @@ -23,6 +25,7 @@ impl Interpret for Slt { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.slt(rhs)) } @@ -32,6 +35,7 @@ impl Interpret for Sgt { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.sgt(rhs)) } @@ -41,6 +45,7 @@ impl Interpret for Le { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.le(rhs)) } @@ -50,6 +55,7 @@ impl Interpret for Ge { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.ge(rhs)) } @@ -59,6 +65,7 @@ impl Interpret for Sle { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.sle(rhs)) } @@ -68,6 +75,7 @@ impl Interpret for Sge { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.sge(rhs)) } @@ -77,6 +85,7 @@ impl Interpret for Eq { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.imm_eq(rhs)) } @@ -86,6 +95,7 @@ impl Interpret for Ne { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs.imm_ne(rhs)) } @@ -94,6 +104,8 @@ impl Interpret for Ne { impl Interpret for IsZero { fn interpret(&self, state: &mut dyn State) -> EvalValue { let val = state.lookup_val(*self.lhs()); + state.set_action(Action::Continue); + val.with_imm(|value| Immediate::from(value.is_zero())) } } diff --git a/crates/ir/src/interpret/control_flow.rs b/crates/ir/src/interpret/control_flow.rs index a24cb8e9..75c50920 100644 --- a/crates/ir/src/interpret/control_flow.rs +++ b/crates/ir/src/interpret/control_flow.rs @@ -76,7 +76,9 @@ impl Interpret for Call { .map(|arg| state.lookup_val(*arg)) .collect(); - state.eval_func(func, args) + let val = state.call_func(func, args); + state.set_action(Action::Continue); + val } } diff --git a/crates/ir/src/interpret/logic.rs b/crates/ir/src/interpret/logic.rs index f393c7ed..06123830 100644 --- a/crates/ir/src/interpret/logic.rs +++ b/crates/ir/src/interpret/logic.rs @@ -1,9 +1,11 @@ -use super::{EvalValue, Interpret, State}; +use super::{Action, EvalValue, Interpret, State}; use crate::inst::logic::*; impl Interpret for Not { fn interpret(&self, state: &mut dyn State) -> EvalValue { let arg = state.lookup_val(*self.arg()); + state.set_action(Action::Continue); + arg.with_imm(|arg| !arg) } } @@ -12,6 +14,7 @@ impl Interpret for And { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs & rhs) } @@ -21,6 +24,7 @@ impl Interpret for Or { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs | rhs) } @@ -30,6 +34,7 @@ impl Interpret for Xor { fn interpret(&self, state: &mut dyn State) -> EvalValue { let lhs = state.lookup_val(*self.lhs()); let rhs = state.lookup_val(*self.rhs()); + state.set_action(Action::Continue); EvalValue::zip_with_imm(lhs, rhs, |lhs, rhs| lhs ^ rhs) } diff --git a/crates/ir/src/interpret/mod.rs b/crates/ir/src/interpret/mod.rs index c7318135..2f3cb441 100644 --- a/crates/ir/src/interpret/mod.rs +++ b/crates/ir/src/interpret/mod.rs @@ -61,7 +61,7 @@ pub trait State { /// error, or cause a panic). fn lookup_val(&mut self, value: ValueId) -> EvalValue; - fn eval_func(&mut self, func: FuncRef, args: Vec) -> EvalValue; + fn call_func(&mut self, func: FuncRef, args: Vec) -> EvalValue; fn set_action(&mut self, action: Action);