Skip to content

Commit 5bc0de6

Browse files
authored
Rename wasmi_ir::Instruction -> Op (#1652)
* rename Instruction -> Op * apply rustfmt * use Op directly in matchers instead of alias * fix broken doc links
1 parent f7c77a7 commit 5bc0de6

40 files changed

+3108
-3396
lines changed

crates/ir/src/enum.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ macro_rules! define_enum {
2828
/// A Wasmi instruction.
2929
///
3030
/// Wasmi instructions are composed of so-called instruction words.
31-
/// This type represents all such words and for simplicity we call the type [`Instruction`], still.
31+
/// This type represents all such words and for simplicity we call the type [`Op`], still.
3232
///
3333
/// Most instructions are composed of a single instruction word. An example of
34-
/// this is [`Instruction::I32Add`]. However, some instructions, like the `select` instructions
34+
/// this is [`Op::I32Add`]. However, some instructions, like the `select` instructions
3535
/// are composed of two or more instruction words.
3636
///
3737
/// The Wasmi bytecode translation makes sure that instructions always appear in valid sequences.
3838
/// The Wasmi executor relies on the guarantees that the Wasmi translator provides.
3939
///
40-
/// The documentation of each [`Instruction`] describes its encoding in the
40+
/// The documentation of each [`Op`] describes its encoding in the
4141
/// `#Encoding` section of its documentation if it requires more than a single
4242
/// instruction for its encoding.
4343
#[derive(Debug)]
4444
#[non_exhaustive]
4545
#[repr(u16)]
46-
pub enum Instruction {
46+
pub enum Op {
4747
$(
4848
$( #[doc = $doc] )*
4949
$name
@@ -62,9 +62,9 @@ macro_rules! define_enum {
6262
),*
6363
}
6464

65-
impl Instruction {
65+
impl Op {
6666
$(
67-
#[doc = concat!("Creates a new [`Instruction::", stringify!($name), "`].")]
67+
#[doc = concat!("Creates a new [`Op::", stringify!($name), "`].")]
6868
pub fn $snake_name(
6969
$(
7070
$( $result_name: impl Into<$result_ty>, )?
@@ -81,11 +81,11 @@ macro_rules! define_enum {
8181
)*
8282
}
8383

84-
impl<'a> $crate::visit_results::ResultsVisitor for &'a mut Instruction {
84+
impl<'a> $crate::visit_results::ResultsVisitor for &'a mut Op {
8585
fn host_visitor<V: VisitResults>(self, visitor: &mut V) {
8686
match self {
8787
$(
88-
Instruction::$name { $( $( $result_name, )? .. )? } => {
88+
Op::$name { $( $( $result_name, )? .. )? } => {
8989
$(
9090
$( $result_name.host_visitor(visitor); )?
9191
)?
@@ -98,20 +98,20 @@ macro_rules! define_enum {
9898
}
9999
for_each_op::for_each_op!(define_enum);
100100

101-
impl Copy for Instruction {}
102-
impl Clone for Instruction {
101+
impl Copy for Op {}
102+
impl Clone for Op {
103103
fn clone(&self) -> Self {
104104
*self
105105
}
106106
}
107107

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

114-
/// Creates a new [`Instruction::ReturnReg3`] for the given [`Reg`] indices.
114+
/// Creates a new [`Op::ReturnReg3`] for the given [`Reg`] indices.
115115
pub fn return_reg3_ext(
116116
reg0: impl Into<Reg>,
117117
reg1: impl Into<Reg>,
@@ -120,7 +120,7 @@ impl Instruction {
120120
Self::return_reg3([reg0.into(), reg1.into(), reg2.into()])
121121
}
122122

123-
/// Creates a new [`Instruction::ReturnMany`] for the given [`Reg`] indices.
123+
/// Creates a new [`Op::ReturnMany`] for the given [`Reg`] indices.
124124
pub fn return_many_ext(
125125
reg0: impl Into<Reg>,
126126
reg1: impl Into<Reg>,
@@ -129,30 +129,30 @@ impl Instruction {
129129
Self::return_many([reg0.into(), reg1.into(), reg2.into()])
130130
}
131131

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

140-
/// Creates a new [`Instruction::CopyMany`].
140+
/// Creates a new [`Op::CopyMany`].
141141
pub fn copy_many_ext(results: RegSpan, head0: impl Into<Reg>, head1: impl Into<Reg>) -> Self {
142142
Self::copy_many(results, [head0.into(), head1.into()])
143143
}
144144

145-
/// Creates a new [`Instruction::Register2`] instruction parameter.
145+
/// Creates a new [`Op::Register2`] instruction parameter.
146146
pub fn register2_ext(reg0: impl Into<Reg>, reg1: impl Into<Reg>) -> Self {
147147
Self::register2([reg0.into(), reg1.into()])
148148
}
149149

150-
/// Creates a new [`Instruction::Register3`] instruction parameter.
150+
/// Creates a new [`Op::Register3`] instruction parameter.
151151
pub fn register3_ext(reg0: impl Into<Reg>, reg1: impl Into<Reg>, reg2: impl Into<Reg>) -> Self {
152152
Self::register3([reg0.into(), reg1.into(), reg2.into()])
153153
}
154154

155-
/// Creates a new [`Instruction::RegisterList`] instruction parameter.
155+
/// Creates a new [`Op::RegisterList`] instruction parameter.
156156
pub fn register_list_ext(
157157
reg0: impl Into<Reg>,
158158
reg1: impl Into<Reg>,
@@ -161,7 +161,7 @@ impl Instruction {
161161
Self::register_list([reg0.into(), reg1.into(), reg2.into()])
162162
}
163163

164-
/// Creates a new [`Instruction::RegisterAndImm32`] from the given `reg` and `offset_hi`.
164+
/// Creates a new [`Op::RegisterAndImm32`] from the given `reg` and `offset_hi`.
165165
pub fn register_and_offset_hi(reg: impl Into<Reg>, offset_hi: Offset64Hi) -> Self {
166166
Self::register_and_imm32(reg, offset_hi.0)
167167
}
@@ -170,16 +170,16 @@ impl Instruction {
170170
///
171171
/// # Errors
172172
///
173-
/// Returns back `self` if it was an incorrect [`Instruction`].
173+
/// Returns back `self` if it was an incorrect [`Op`].
174174
/// This allows for a better error message to inform the user.
175175
pub fn filter_register_and_offset_hi(self) -> Result<(Reg, Offset64Hi), Self> {
176-
if let Instruction::RegisterAndImm32 { reg, imm } = self {
176+
if let Op::RegisterAndImm32 { reg, imm } = self {
177177
return Ok((reg, Offset64Hi(u32::from(imm))));
178178
}
179179
Err(self)
180180
}
181181

182-
/// Creates a new [`Instruction::RegisterAndImm32`] from the given `reg` and `offset_hi`.
182+
/// Creates a new [`Op::RegisterAndImm32`] from the given `reg` and `offset_hi`.
183183
pub fn register_and_lane<LaneType>(reg: impl Into<Reg>, lane: LaneType) -> Self
184184
where
185185
LaneType: Into<u8>,
@@ -191,13 +191,13 @@ impl Instruction {
191191
///
192192
/// # Errors
193193
///
194-
/// Returns back `self` if it was an incorrect [`Instruction`].
194+
/// Returns back `self` if it was an incorrect [`Op`].
195195
/// This allows for a better error message to inform the user.
196196
pub fn filter_register_and_lane<LaneType>(self) -> Result<(Reg, LaneType), Self>
197197
where
198198
LaneType: TryFrom<u8>,
199199
{
200-
if let Instruction::RegisterAndImm32 { reg, imm } = self {
200+
if let Op::RegisterAndImm32 { reg, imm } = self {
201201
let lane_index = u32::from(imm) as u8;
202202
let Ok(lane) = LaneType::try_from(lane_index) else {
203203
panic!("encountered out of bounds lane index: {}", lane_index)
@@ -207,7 +207,7 @@ impl Instruction {
207207
Err(self)
208208
}
209209

210-
/// Creates a new [`Instruction::Imm16AndImm32`] from the given `value` and `offset_hi`.
210+
/// Creates a new [`Op::Imm16AndImm32`] from the given `value` and `offset_hi`.
211211
pub fn imm16_and_offset_hi(value: impl Into<AnyConst16>, offset_hi: Offset64Hi) -> Self {
212212
Self::imm16_and_imm32(value, offset_hi.0)
213213
}
@@ -216,19 +216,19 @@ impl Instruction {
216216
///
217217
/// # Errors
218218
///
219-
/// Returns back `self` if it was an incorrect [`Instruction`].
219+
/// Returns back `self` if it was an incorrect [`Op`].
220220
/// This allows for a better error message to inform the user.
221221
pub fn filter_imm16_and_offset_hi<T>(self) -> Result<(T, Offset64Hi), Self>
222222
where
223223
T: From<AnyConst16>,
224224
{
225-
if let Instruction::Imm16AndImm32 { imm16, imm32 } = self {
225+
if let Op::Imm16AndImm32 { imm16, imm32 } = self {
226226
return Ok((T::from(imm16), Offset64Hi(u32::from(imm32))));
227227
}
228228
Err(self)
229229
}
230230

231-
/// Creates a new [`Instruction::Imm16AndImm32`] from the given `lane` and `memory` index.
231+
/// Creates a new [`Op::Imm16AndImm32`] from the given `lane` and `memory` index.
232232
pub fn lane_and_memory_index(value: impl Into<u8>, memory: Memory) -> Self {
233233
Self::imm16_and_imm32(u16::from(value.into()), u32::from(memory))
234234
}
@@ -237,13 +237,13 @@ impl Instruction {
237237
///
238238
/// # Errors
239239
///
240-
/// Returns back `self` if it was an incorrect [`Instruction`].
240+
/// Returns back `self` if it was an incorrect [`Op`].
241241
/// This allows for a better error message to inform the user.
242242
pub fn filter_lane_and_memory<LaneType>(self) -> Result<(LaneType, index::Memory), Self>
243243
where
244244
LaneType: TryFrom<u8>,
245245
{
246-
if let Instruction::Imm16AndImm32 { imm16, imm32 } = self {
246+
if let Op::Imm16AndImm32 { imm16, imm32 } = self {
247247
let Ok(lane) = LaneType::try_from(i16::from(imm16) as u16 as u8) else {
248248
return Err(self);
249249
};
@@ -263,6 +263,6 @@ fn size_of() {
263263
//
264264
// Until that bug is fixed we need to order the `enum` variant
265265
// fields in a precise order to end up with the correct `enum` size.
266-
assert_eq!(::core::mem::size_of::<Instruction>(), 8);
267-
assert_eq!(::core::mem::align_of::<Instruction>(), 4);
266+
assert_eq!(::core::mem::size_of::<Op>(), 8);
267+
assert_eq!(::core::mem::align_of::<Op>(), 4);
268268
}

0 commit comments

Comments
 (0)