Skip to content

Commit c8d2a43

Browse files
committed
rename Instr -> OpPos
1 parent c6079ba commit c8d2a43

File tree

8 files changed

+92
-92
lines changed

8 files changed

+92
-92
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
},
1111
func::{Stack, StackLayout, StackSpace},
1212
relink_result::RelinkResult,
13-
utils::{BumpFuelConsumption as _, Instr},
13+
utils::{BumpFuelConsumption as _, OpPos},
1414
},
1515
ir::{BranchOffset, Op, Slot},
1616
Engine,
@@ -28,7 +28,7 @@ pub struct OpEncoder {
2828
///
2929
/// - This allows the last [`Op`] to be peeked and manipulated.
3030
/// - For example, this is useful to perform op-code fusion or adjusting the result slot.
31-
last: Option<Instr>,
31+
last: Option<OpPos>,
3232
/// The fuel costs of instructions.
3333
///
3434
/// This is `Some` if fuel metering is enabled, otherwise `None`.
@@ -75,18 +75,18 @@ impl OpEncoder {
7575
}
7676
}
7777

78-
/// Returns the next [`Instr`].
78+
/// Returns the next [`OpPos`].
7979
#[must_use]
80-
pub fn next_instr(&self) -> Instr {
81-
Instr::from_usize(self.ops.len())
80+
pub fn next_instr(&self) -> OpPos {
81+
OpPos::from_usize(self.ops.len())
8282
}
8383

8484
/// Pushes an [`Op::ConsumeFuel`] instruction to `self`.
8585
///
8686
/// # Note
8787
///
8888
/// The pushes [`Op::ConsumeFuel`] is initialized with base fuel costs.
89-
pub fn push_consume_fuel_instr(&mut self) -> Result<Option<Instr>, Error> {
89+
pub fn push_consume_fuel_instr(&mut self) -> Result<Option<OpPos>, Error> {
9090
let Some(fuel_costs) = &self.fuel_costs else {
9191
return Ok(None);
9292
};
@@ -97,19 +97,19 @@ impl OpEncoder {
9797

9898
/// Pushes a non-parameter [`Op`] to the [`OpEncoder`].
9999
///
100-
/// Returns an [`Instr`] that refers to the pushed [`Op`].
100+
/// Returns an [`OpPos`] that refers to the pushed [`Op`].
101101
pub fn push_instr(
102102
&mut self,
103103
instruction: Op,
104-
consume_fuel: Option<Instr>,
104+
consume_fuel: Option<OpPos>,
105105
f: impl FnOnce(&FuelCostsProvider) -> u64,
106-
) -> Result<Instr, Error> {
106+
) -> Result<OpPos, Error> {
107107
self.bump_fuel_consumption(consume_fuel, f)?;
108108
self.push_instr_impl(instruction)
109109
}
110110

111111
/// Pushes a non-parameter [`Op`] to the [`OpEncoder`].
112-
fn push_instr_impl(&mut self, instruction: Op) -> Result<Instr, Error> {
112+
fn push_instr_impl(&mut self, instruction: Op) -> Result<OpPos, Error> {
113113
let instr = self.next_instr();
114114
self.ops.push(instruction);
115115
self.last = Some(instr);
@@ -124,7 +124,7 @@ impl OpEncoder {
124124
/// # Panics (Debug)
125125
///
126126
/// If `instr` or `new_instr` are [`Op`] parameters.
127-
pub fn try_replace_instr(&mut self, instr: Instr, new_instr: Op) -> Result<bool, Error> {
127+
pub fn try_replace_instr(&mut self, instr: OpPos, new_instr: Op) -> Result<bool, Error> {
128128
let Some(last_instr) = self.last else {
129129
return Ok(false);
130130
};
@@ -224,25 +224,25 @@ impl OpEncoder {
224224
self.ops.push(instruction);
225225
}
226226

227-
/// Returns a shared reference to the [`Op`] associated to [`Instr`].
227+
/// Returns a shared reference to the [`Op`] associated to [`OpPos`].
228228
///
229229
/// # Panics
230230
///
231231
/// If `instr` is out of bounds for `self`.
232-
pub fn get(&self, instr: Instr) -> &Op {
232+
pub fn get(&self, instr: OpPos) -> &Op {
233233
&self.ops[instr.into_usize()]
234234
}
235235

236-
/// Returns an exclusive reference to the [`Op`] associated to [`Instr`].
236+
/// Returns an exclusive reference to the [`Op`] associated to [`OpPos`].
237237
///
238238
/// # Panics
239239
///
240240
/// If `instr` is out of bounds for `self`.
241-
fn get_mut(&mut self, instr: Instr) -> &mut Op {
241+
fn get_mut(&mut self, instr: OpPos) -> &mut Op {
242242
&mut self.ops[instr.into_usize()]
243243
}
244244

245-
/// Resets the [`Instr`] last created via [`OpEncoder::push_instr`].
245+
/// Resets the [`OpPos`] last created via [`OpEncoder::push_instr`].
246246
///
247247
/// # Note
248248
///
@@ -263,7 +263,7 @@ impl OpEncoder {
263263
/// If the branch offset could not be updated for `instr`.
264264
pub fn update_branch_offset(
265265
&mut self,
266-
instr: Instr,
266+
instr: OpPos,
267267
offset: BranchOffset,
268268
) -> Result<(), Error> {
269269
self.get_mut(instr).update_branch_offset(offset)?;
@@ -277,7 +277,7 @@ impl OpEncoder {
277277
/// If consumed fuel is out of bounds after this operation.
278278
pub fn bump_fuel_consumption(
279279
&mut self,
280-
consume_fuel: Option<Instr>,
280+
consume_fuel: Option<OpPos>,
281281
f: impl FnOnce(&FuelCostsProvider) -> u64,
282282
) -> Result<(), Error> {
283283
let (fuel_costs, consume_fuel) = match (&self.fuel_costs, consume_fuel) {
@@ -308,7 +308,7 @@ impl OpEncoder {
308308
}
309309

310310
/// Returns the last instruction of the [`OpEncoder`] if any.
311-
pub fn last_instr(&self) -> Option<Instr> {
311+
pub fn last_instr(&self) -> Option<OpPos> {
312312
self.last
313313
}
314314
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::{
4444
TryIntoCmpBranchInstr as _,
4545
},
4646
labels::{LabelRef, LabelRegistry},
47-
utils::{Instr, IntoShiftAmount, ToBits, WasmFloat, WasmInteger},
47+
utils::{OpPos, IntoShiftAmount, ToBits, WasmFloat, WasmInteger},
4848
WasmTranslator,
4949
},
5050
BlockType,
@@ -329,7 +329,7 @@ impl FuncTranslator {
329329
fn move_operands_to_temp(
330330
&mut self,
331331
len: usize,
332-
consume_fuel: Option<Instr>,
332+
consume_fuel: Option<OpPos>,
333333
) -> Result<SlotSpan, Error> {
334334
for n in 0..len {
335335
let operand = self.stack.operand_to_temp(n);
@@ -349,7 +349,7 @@ impl FuncTranslator {
349349
fn copy_branch_params(
350350
&mut self,
351351
target: &impl ControlFrameBase,
352-
consume_fuel_instr: Option<Instr>,
352+
consume_fuel_instr: Option<OpPos>,
353353
) -> Result<(), Error> {
354354
let len_branch_params = target.len_branch_params(&self.engine);
355355
let Some(branch_results) = self.frame_results(target)? else {
@@ -392,7 +392,7 @@ impl FuncTranslator {
392392
&mut self,
393393
results: SlotSpan,
394394
len_values: u16,
395-
consume_fuel_instr: Option<Instr>,
395+
consume_fuel_instr: Option<OpPos>,
396396
) -> Result<(), Error> {
397397
match len_values {
398398
0 => Ok(()),
@@ -415,8 +415,8 @@ impl FuncTranslator {
415415
&mut self,
416416
result: Slot,
417417
value: Operand,
418-
consume_fuel_instr: Option<Instr>,
419-
) -> Result<Option<Instr>, Error> {
418+
consume_fuel_instr: Option<OpPos>,
419+
) -> Result<Option<OpPos>, Error> {
420420
let Some(copy_instr) = Self::make_copy_instr(result, value, &mut self.layout)? else {
421421
// Case: no-op copy instruction
422422
return Ok(None);
@@ -490,7 +490,7 @@ impl FuncTranslator {
490490
results: SlotSpan,
491491
values: SlotSpan,
492492
len: u16,
493-
consume_fuel_instr: Option<Instr>,
493+
consume_fuel_instr: Option<OpPos>,
494494
) -> Result<(), Error> {
495495
if results == values {
496496
// Case: results and values are equal and therefore the copy is a no-op
@@ -516,7 +516,7 @@ impl FuncTranslator {
516516
&mut self,
517517
results: SlotSpan,
518518
len: u16,
519-
consume_fuel_instr: Option<Instr>,
519+
consume_fuel_instr: Option<OpPos>,
520520
) -> Result<(), Error> {
521521
self.peek_operands_into_buffer(usize::from(len));
522522
let values = &self.operands[..];
@@ -689,7 +689,7 @@ impl FuncTranslator {
689689
!can_avoid_copies
690690
}
691691

692-
/// Pins the `label` to the next [`Instr`].
692+
/// Pins the `label` to the next [`OpPos`].
693693
fn pin_label(&mut self, label: LabelRef) {
694694
self.labels
695695
.pin_label(label, self.instrs.next_instr())
@@ -704,7 +704,7 @@ impl FuncTranslator {
704704
fn copy_operand_to_temp(
705705
&mut self,
706706
operand: Operand,
707-
consume_fuel: Option<Instr>,
707+
consume_fuel: Option<OpPos>,
708708
) -> Result<Slot, Error> {
709709
let result = self.layout.temp_to_slot(operand.index())?;
710710
self.encode_copy(result, operand, consume_fuel)?;
@@ -758,7 +758,7 @@ impl FuncTranslator {
758758
&mut self,
759759
instr: Op,
760760
fuel_costs: impl FnOnce(&FuelCostsProvider) -> u64,
761-
) -> Result<Instr, Error> {
761+
) -> Result<OpPos, Error> {
762762
let consume_fuel = self.stack.consume_fuel_instr();
763763
let instr = self.instrs.push_instr(instr, consume_fuel, fuel_costs)?;
764764
Ok(instr)
@@ -885,7 +885,7 @@ impl FuncTranslator {
885885
}
886886

887887
/// Encodes a generic return instruction.
888-
fn encode_return(&mut self, consume_fuel: Option<Instr>) -> Result<Instr, Error> {
888+
fn encode_return(&mut self, consume_fuel: Option<OpPos>) -> Result<OpPos, Error> {
889889
let len_results = self.func_type_with(FuncType::len_results);
890890
let instr = match len_results {
891891
0 => Op::Return {},
@@ -982,7 +982,7 @@ impl FuncTranslator {
982982
fn try_form_regspan_or_move(
983983
&mut self,
984984
len: usize,
985-
consume_fuel_instr: Option<Instr>,
985+
consume_fuel_instr: Option<OpPos>,
986986
) -> Result<SlotSpan, Error> {
987987
if let Some(span) = self.try_form_regspan(len)? {
988988
return Ok(span);
@@ -1099,7 +1099,7 @@ impl FuncTranslator {
10991099
_ => true,
11001100
};
11011101
if end_of_else_reachable {
1102-
let consume_fuel_instr: Option<Instr> = frame.consume_fuel_instr();
1102+
let consume_fuel_instr: Option<OpPos> = frame.consume_fuel_instr();
11031103
self.copy_branch_params(&frame, consume_fuel_instr)?;
11041104
}
11051105
self.push_frame_results(&frame)?;
@@ -1229,7 +1229,7 @@ impl FuncTranslator {
12291229
}
12301230

12311231
/// Encodes an unconditional Wasm `branch` instruction.
1232-
fn encode_br(&mut self, label: LabelRef) -> Result<Instr, Error> {
1232+
fn encode_br(&mut self, label: LabelRef) -> Result<OpPos, Error> {
12331233
let instr = self.instrs.next_instr();
12341234
let offset = self.labels.try_resolve_label(label, instr)?;
12351235
let br_instr = self.push_instr(Op::branch(offset), FuelCostsProvider::base)?;
@@ -1333,7 +1333,7 @@ impl FuncTranslator {
13331333
/// - Returns `Ok(None)`, otherwise.
13341334
fn try_make_fused_branch_cmp_instr(
13351335
&mut self,
1336-
instr: Instr,
1336+
instr: OpPos,
13371337
condition: TempOperand,
13381338
label: LabelRef,
13391339
negate: bool,

0 commit comments

Comments
 (0)