Skip to content

Commit 9c8ca36

Browse files
committed
rename OpEncoder::last_instr -> last
1 parent 5eabbfb commit 9c8ca36

File tree

1 file changed

+12
-9
lines changed
  • crates/wasmi/src/engine/translator/func

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ pub struct OpEncoder {
2828
///
2929
/// This is `Some` if fuel metering is enabled, otherwise `None`.
3030
fuel_costs: Option<FuelCostsProvider>,
31-
/// The last pushed non-parameter [`Op`].
32-
last_instr: Option<Instr>,
31+
/// The last pushed [`Op`].
32+
///
33+
/// This is special in that it allows being peeked and manipulated.
34+
/// This is useful to perform op-code fusion or adjusting the result slot.
35+
last: Option<Instr>,
3336
}
3437

3538
impl ReusableAllocations for OpEncoder {
@@ -66,7 +69,7 @@ impl OpEncoder {
6669
Self {
6770
instrs: alloc.instrs,
6871
fuel_costs,
69-
last_instr: None,
72+
last: None,
7073
}
7174
}
7275

@@ -107,7 +110,7 @@ impl OpEncoder {
107110
fn push_instr_impl(&mut self, instruction: Op) -> Result<Instr, Error> {
108111
let instr = self.next_instr();
109112
self.instrs.push(instruction);
110-
self.last_instr = Some(instr);
113+
self.last = Some(instr);
111114
Ok(instr)
112115
}
113116

@@ -120,7 +123,7 @@ impl OpEncoder {
120123
///
121124
/// If `instr` or `new_instr` are [`Op`] parameters.
122125
pub fn try_replace_instr(&mut self, instr: Instr, new_instr: Op) -> Result<bool, Error> {
123-
let Some(last_instr) = self.last_instr else {
126+
let Some(last_instr) = self.last else {
124127
return Ok(false);
125128
};
126129
let replace = self.get_mut(instr);
@@ -150,7 +153,7 @@ impl OpEncoder {
150153
// Case: cannot replace result if `new_result` isn't a local.
151154
return Ok(false);
152155
}
153-
let Some(last_instr) = self.last_instr else {
156+
let Some(last_instr) = self.last else {
154157
// Case: cannot replace result without last instruction.
155158
return Ok(false);
156159
};
@@ -179,7 +182,7 @@ impl OpEncoder {
179182
true_val: Slot,
180183
false_val: Slot,
181184
) -> Result<bool, Error> {
182-
let Some(last_instr) = self.last_instr else {
185+
let Some(last_instr) = self.last else {
183186
// If there is no last instruction there is no comparison instruction to negate.
184187
return Ok(false);
185188
};
@@ -248,7 +251,7 @@ impl OpEncoder {
248251
/// needs to be reset to `None` to signal that no such optimization is
249252
/// valid across control flow boundaries.
250253
pub fn reset_last_instr(&mut self) {
251-
self.last_instr = None;
254+
self.last = None;
252255
}
253256

254257
/// Updates the branch offset of `instr` to `offset`.
@@ -304,7 +307,7 @@ impl OpEncoder {
304307

305308
/// Returns the last instruction of the [`OpEncoder`] if any.
306309
pub fn last_instr(&self) -> Option<Instr> {
307-
self.last_instr
310+
self.last
308311
}
309312
}
310313

0 commit comments

Comments
 (0)