Skip to content

Commit 5439ae6

Browse files
authored
Rename wasmi_ir::Reg types to Slot (#1653)
* wasmi_ir: rename Reg -> Slot (+all Reg* types) * wasmi: adjust after renaming Reg* -> Slot* * rename Executor::{get,set}_register -> {get,set}_stack_slot * rename reg -> slot in a few function signatures * rename len_registers -> len_stack_slots * rename forgotten snake case identifiers * rename many instances of reg[s] to slot[s]
1 parent 5bc0de6 commit 5439ae6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3370
-3347
lines changed

crates/ir/src/enum.rs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -106,103 +106,107 @@ impl Clone for Op {
106106
}
107107

108108
impl Op {
109-
/// Creates a new [`Op::ReturnReg2`] for the given [`Reg`] indices.
110-
pub fn return_reg2_ext(reg0: impl Into<Reg>, reg1: impl Into<Reg>) -> Self {
109+
/// Creates a new [`Op::ReturnSlot2`] for the given [`Slot`] indices.
110+
pub fn return_reg2_ext(reg0: impl Into<Slot>, reg1: impl Into<Slot>) -> Self {
111111
Self::return_reg2([reg0.into(), reg1.into()])
112112
}
113113

114-
/// Creates a new [`Op::ReturnReg3`] for the given [`Reg`] indices.
114+
/// Creates a new [`Op::ReturnSlot3`] for the given [`Slot`] indices.
115115
pub fn return_reg3_ext(
116-
reg0: impl Into<Reg>,
117-
reg1: impl Into<Reg>,
118-
reg2: impl Into<Reg>,
116+
reg0: impl Into<Slot>,
117+
reg1: impl Into<Slot>,
118+
reg2: impl Into<Slot>,
119119
) -> Self {
120120
Self::return_reg3([reg0.into(), reg1.into(), reg2.into()])
121121
}
122122

123-
/// Creates a new [`Op::ReturnMany`] for the given [`Reg`] indices.
123+
/// Creates a new [`Op::ReturnMany`] for the given [`Slot`] indices.
124124
pub fn return_many_ext(
125-
reg0: impl Into<Reg>,
126-
reg1: impl Into<Reg>,
127-
reg2: impl Into<Reg>,
125+
reg0: impl Into<Slot>,
126+
reg1: impl Into<Slot>,
127+
reg2: impl Into<Slot>,
128128
) -> Self {
129129
Self::return_many([reg0.into(), reg1.into(), reg2.into()])
130130
}
131131

132132
/// Creates a new [`Op::Copy2`].
133-
pub fn copy2_ext(results: RegSpan, value0: impl Into<Reg>, value1: impl Into<Reg>) -> Self {
134-
let span = FixedRegSpan::new(results).unwrap_or_else(|_| {
135-
panic!("encountered invalid `results` `RegSpan` for `Copy2`: {results:?}")
133+
pub fn copy2_ext(results: SlotSpan, value0: impl Into<Slot>, value1: impl Into<Slot>) -> Self {
134+
let span = FixedSlotSpan::new(results).unwrap_or_else(|_| {
135+
panic!("encountered invalid `results` `SlotSpan` for `Copy2`: {results:?}")
136136
});
137137
Self::copy2(span, [value0.into(), value1.into()])
138138
}
139139

140140
/// Creates a new [`Op::CopyMany`].
141-
pub fn copy_many_ext(results: RegSpan, head0: impl Into<Reg>, head1: impl Into<Reg>) -> Self {
141+
pub fn copy_many_ext(
142+
results: SlotSpan,
143+
head0: impl Into<Slot>,
144+
head1: impl Into<Slot>,
145+
) -> Self {
142146
Self::copy_many(results, [head0.into(), head1.into()])
143147
}
144148

145-
/// Creates a new [`Op::Register2`] instruction parameter.
146-
pub fn register2_ext(reg0: impl Into<Reg>, reg1: impl Into<Reg>) -> Self {
147-
Self::register2([reg0.into(), reg1.into()])
149+
/// Creates a new [`Op::Slot2`] instruction parameter.
150+
pub fn slot2_ext(reg0: impl Into<Slot>, reg1: impl Into<Slot>) -> Self {
151+
Self::slot2([reg0.into(), reg1.into()])
148152
}
149153

150-
/// Creates a new [`Op::Register3`] instruction parameter.
151-
pub fn register3_ext(reg0: impl Into<Reg>, reg1: impl Into<Reg>, reg2: impl Into<Reg>) -> Self {
152-
Self::register3([reg0.into(), reg1.into(), reg2.into()])
154+
/// Creates a new [`Op::Slot3`] instruction parameter.
155+
pub fn slot3_ext(reg0: impl Into<Slot>, reg1: impl Into<Slot>, reg2: impl Into<Slot>) -> Self {
156+
Self::slot3([reg0.into(), reg1.into(), reg2.into()])
153157
}
154158

155-
/// Creates a new [`Op::RegisterList`] instruction parameter.
156-
pub fn register_list_ext(
157-
reg0: impl Into<Reg>,
158-
reg1: impl Into<Reg>,
159-
reg2: impl Into<Reg>,
159+
/// Creates a new [`Op::SlotList`] instruction parameter.
160+
pub fn slot_list_ext(
161+
reg0: impl Into<Slot>,
162+
reg1: impl Into<Slot>,
163+
reg2: impl Into<Slot>,
160164
) -> Self {
161-
Self::register_list([reg0.into(), reg1.into(), reg2.into()])
165+
Self::slot_list([reg0.into(), reg1.into(), reg2.into()])
162166
}
163167

164-
/// Creates a new [`Op::RegisterAndImm32`] from the given `reg` and `offset_hi`.
165-
pub fn register_and_offset_hi(reg: impl Into<Reg>, offset_hi: Offset64Hi) -> Self {
166-
Self::register_and_imm32(reg, offset_hi.0)
168+
/// Creates a new [`Op::SlotAndImm32`] from the given `reg` and `offset_hi`.
169+
pub fn slot_and_offset_hi(slot: impl Into<Slot>, offset_hi: Offset64Hi) -> Self {
170+
Self::slot_and_imm32(slot, offset_hi.0)
167171
}
168172

169-
/// Returns `Some` [`Reg`] and [`Offset64Hi`] if encoded properly.
173+
/// Returns `Some` [`Slot`] and [`Offset64Hi`] if encoded properly.
170174
///
171175
/// # Errors
172176
///
173177
/// Returns back `self` if it was an incorrect [`Op`].
174178
/// This allows for a better error message to inform the user.
175-
pub fn filter_register_and_offset_hi(self) -> Result<(Reg, Offset64Hi), Self> {
176-
if let Op::RegisterAndImm32 { reg, imm } = self {
177-
return Ok((reg, Offset64Hi(u32::from(imm))));
179+
pub fn filter_register_and_offset_hi(self) -> Result<(Slot, Offset64Hi), Self> {
180+
if let Op::SlotAndImm32 { slot, imm } = self {
181+
return Ok((slot, Offset64Hi(u32::from(imm))));
178182
}
179183
Err(self)
180184
}
181185

182-
/// Creates a new [`Op::RegisterAndImm32`] from the given `reg` and `offset_hi`.
183-
pub fn register_and_lane<LaneType>(reg: impl Into<Reg>, lane: LaneType) -> Self
186+
/// Creates a new [`Op::SlotAndImm32`] from the given `reg` and `offset_hi`.
187+
pub fn slot_and_lane<LaneType>(slot: impl Into<Slot>, lane: LaneType) -> Self
184188
where
185189
LaneType: Into<u8>,
186190
{
187-
Self::register_and_imm32(reg, u32::from(lane.into()))
191+
Self::slot_and_imm32(slot, u32::from(lane.into()))
188192
}
189193

190-
/// Returns `Some` [`Reg`] and a `lane` index if encoded properly.
194+
/// Returns `Some` [`Slot`] and a `lane` index if encoded properly.
191195
///
192196
/// # Errors
193197
///
194198
/// Returns back `self` if it was an incorrect [`Op`].
195199
/// This allows for a better error message to inform the user.
196-
pub fn filter_register_and_lane<LaneType>(self) -> Result<(Reg, LaneType), Self>
200+
pub fn filter_register_and_lane<LaneType>(self) -> Result<(Slot, LaneType), Self>
197201
where
198202
LaneType: TryFrom<u8>,
199203
{
200-
if let Op::RegisterAndImm32 { reg, imm } = self {
204+
if let Op::SlotAndImm32 { slot, imm } = self {
201205
let lane_index = u32::from(imm) as u8;
202206
let Ok(lane) = LaneType::try_from(lane_index) else {
203207
panic!("encountered out of bounds lane index: {}", lane_index)
204208
};
205-
return Ok((reg, lane));
209+
return Ok((slot, lane));
206210
}
207211
Err(self)
208212
}
@@ -212,7 +216,7 @@ impl Op {
212216
Self::imm16_and_imm32(value, offset_hi.0)
213217
}
214218

215-
/// Returns `Some` [`Reg`] and [`Offset64Hi`] if encoded properly.
219+
/// Returns `Some` [`Slot`] and [`Offset64Hi`] if encoded properly.
216220
///
217221
/// # Errors
218222
///

crates/ir/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use core::fmt;
33
/// An error that may be occurred when operating with some Wasmi IR primitives.
44
#[derive(Debug)]
55
pub enum Error {
6-
/// Encountered when trying to create a [`Reg`](crate::Reg) from an out of bounds integer.
7-
RegisterOutOfBounds,
6+
/// Encountered when trying to create a [`Slot`](crate::Slot) from an out of bounds integer.
7+
StackSlotOutOfBounds,
88
/// Encountered when trying to create a [`BranchOffset`](crate::BranchOffset) from an out of bounds integer.
99
BranchOffsetOutOfBounds,
1010
/// Encountered when trying to create a [`Comparator`](crate::Comparator) from an out of bounds integer.
@@ -16,7 +16,7 @@ pub enum Error {
1616
impl fmt::Display for Error {
1717
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1818
match self {
19-
Self::RegisterOutOfBounds => write!(f, "register out of bounds"),
19+
Self::StackSlotOutOfBounds => write!(f, "stack slot index out of bounds"),
2020
Self::BranchOffsetOutOfBounds => write!(f, "branch offset out of bounds"),
2121
Self::ComparatorOutOfBounds => write!(f, "comparator out of bounds"),
2222
Self::BlockFuelOutOfBounds => write!(f, "block fuel out of bounds"),

0 commit comments

Comments
 (0)