Skip to content

Commit

Permalink
wasmi_ir: remove InstrSequence type (#1323)
Browse files Browse the repository at this point in the history
* wasmi_ir: remove InstrSequence

* remove wasmi_ir::Instr type
  • Loading branch information
Robbepop authored Nov 29, 2024
1 parent e01bf62 commit 4cf45ad
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 275 deletions.
24 changes: 0 additions & 24 deletions crates/ir/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ use crate::Error;
macro_rules! for_each_index {
($mac:ident) => {
$mac! {
/// Used to query the [`Instruction`] of an [`InstrSequence`].
///
/// [`Instruction`]: crate::Instruction
/// [`InstrSequence`]: crate::InstrSequence
Instr(pub(crate) u32);
/// A Wasmi register.
Reg(pub(crate) i16);
/// A Wasm function index.
Expand Down Expand Up @@ -113,22 +108,3 @@ impl Reg {
self.0.is_negative()
}
}

impl Instr {
/// Creates an [`Instr`] from the given `usize` value.
///
/// # Panics
///
/// If the `value` exceeds limitations for [`Instr`].
pub fn from_usize(index: usize) -> Self {
let index = index.try_into().unwrap_or_else(|error| {
panic!("invalid index {index} for instruction reference: {error}")
});
Self(index)
}

/// Returns the index underlying to `self` as `usize`.
pub fn into_usize(self) -> usize {
self.0 as usize
}
}
3 changes: 0 additions & 3 deletions crates/ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod for_each_op;
mod immeditate;
pub mod index;
mod primitive;
mod sequence;
mod span;
mod visit_regs;

Expand All @@ -23,7 +22,6 @@ use wasmi_core as core;
pub use self::{
error::Error,
immeditate::{AnyConst16, AnyConst32, Const16, Const32},
index::Instr,
index::Reg,
primitive::{
BlockFuel,
Expand All @@ -36,7 +34,6 @@ pub use self::{
Sign,
},
r#enum::Instruction,
sequence::{InstrIter, InstrIterMut, InstrSequence},
span::{BoundedRegSpan, FixedRegSpan, RegSpan, RegSpanIter},
visit_regs::VisitRegs,
};
8 changes: 4 additions & 4 deletions crates/ir/src/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{core::UntypedVal, Const16, Error, Instr};
use crate::{core::UntypedVal, Const16, Error};
use core::marker::PhantomData;

/// The sign of a value.
Expand Down Expand Up @@ -152,9 +152,9 @@ impl BranchOffset {
/// # Errors
///
/// If the resulting [`BranchOffset`] is out of bounds.
pub fn from_src_to_dst(src: Instr, dst: Instr) -> Result<Self, Error> {
let src = i64::from(u32::from(src));
let dst = i64::from(u32::from(dst));
pub fn from_src_to_dst(src: u32, dst: u32) -> Result<Self, Error> {
let src = i64::from(src);
let dst = i64::from(dst);
let Some(offset) = dst.checked_sub(src) else {
// Note: This never needs to be called on backwards branches since they are immediated resolved.
unreachable!(
Expand Down
229 changes: 0 additions & 229 deletions crates/ir/src/sequence.rs

This file was deleted.

13 changes: 0 additions & 13 deletions crates/wasmi/src/engine/translator/instr_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
FuelCosts,
},
ir::{
self,
BoundedRegSpan,
BranchOffset,
BranchOffset16,
Expand All @@ -41,18 +40,6 @@ use core::mem;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Instr(u32);

impl From<ir::Instr> for Instr {
fn from(instr: ir::Instr) -> Self {
Self(u32::from(instr))
}
}

impl From<Instr> for ir::Instr {
fn from(instr: Instr) -> Self {
Self::from(instr.0)
}
}

impl Instr {
/// Creates an [`Instr`] from the given `usize` value.
///
Expand Down
7 changes: 5 additions & 2 deletions crates/wasmi/src/engine/translator/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ impl LabelRegistry {
user: Instr,
) -> Result<BranchOffset, Error> {
let offset = match *self.get_label(label) {
Label::Pinned(target) => BranchOffset::from_src_to_dst(user.into(), target.into())?,
Label::Pinned(target) => {
BranchOffset::from_src_to_dst(user.into_u32(), target.into_u32())?
}
Label::Unpinned => {
self.users.push(LabelUser::new(label, user));
BranchOffset::uninit()
Expand Down Expand Up @@ -205,7 +207,8 @@ impl Iterator for ResolvedUserIter<'_> {
.registry
.resolve_label(next.label)
.unwrap_or_else(|err| panic!("failed to resolve user: {err}"));
let offset = BranchOffset::from_src_to_dst(src.into(), dst.into()).map_err(Into::into);
let offset =
BranchOffset::from_src_to_dst(src.into_u32(), dst.into_u32()).map_err(Into::into);
Some((src, offset))
}
}

0 comments on commit 4cf45ad

Please sign in to comment.