Skip to content

Commit 08e0270

Browse files
committed
add last_instr field to InstrEncoder
1 parent 7b9a514 commit 08e0270

File tree

1 file changed

+11
-3
lines changed
  • crates/wasmi/src/engine/translator/func2

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct InstrEncoder {
1717
///
1818
/// This is `Some` if fuel metering is enabled, otherwise `None`.
1919
fuel_costs: Option<FuelCostsProvider>,
20+
/// The last pushed non-parameter [`Instruction`].
21+
last_instr: Option<Instr>,
2022
}
2123

2224
impl ReusableAllocations for InstrEncoder {
@@ -53,6 +55,7 @@ impl InstrEncoder {
5355
Self {
5456
instrs: alloc.instrs,
5557
fuel_costs,
58+
last_instr: None,
5659
}
5760
}
5861

@@ -75,12 +78,11 @@ impl InstrEncoder {
7578
let Ok(base_costs) = u32::try_from(base_costs) else {
7679
panic!("out of bounds base fuel costs: {base_costs}");
7780
};
78-
let instr = self.next_instr();
79-
self.instrs.push(Instruction::consume_fuel(base_costs));
81+
let instr = self.push_instr_impl(Instruction::consume_fuel(base_costs))?;
8082
Ok(Some(instr))
8183
}
8284

83-
/// Pushes an [`Instruction`] to the [`InstrEncoder`].
85+
/// Pushes a non-parameter [`Instruction`] to the [`InstrEncoder`].
8486
///
8587
/// Returns an [`Instr`] that refers to the pushed [`Instruction`].
8688
pub fn push_instr(
@@ -90,8 +92,14 @@ impl InstrEncoder {
9092
f: impl FnOnce(&FuelCostsProvider) -> u64,
9193
) -> Result<Instr, Error> {
9294
self.bump_fuel_consumption(consume_fuel, f)?;
95+
self.push_instr_impl(instruction)
96+
}
97+
98+
/// Pushes a non-parameter [`Instruction`] to the [`InstrEncoder`].
99+
fn push_instr_impl(&mut self, instruction: Instruction) -> Result<Instr, Error> {
93100
let instr = self.next_instr();
94101
self.instrs.push(instruction);
102+
self.last_instr = Some(instr);
95103
Ok(instr)
96104
}
97105

0 commit comments

Comments
 (0)