Skip to content

Commit c7af4f7

Browse files
authored
Update wasmi_ir2 (#1659)
* update ReturnSpan field type * update BranchTable[Span] len_targets type * add TryFrom<u32> for Memory
1 parent 1a09555 commit c7af4f7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

crates/ir2/build/isa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fn add_control_ops(isa: &mut Isa) {
407407
)),
408408
Op::from(GenericOp::new(
409409
Ident::ReturnSpan,
410-
[Field::new(Ident::Values, FieldTy::SlotSpan)],
410+
[Field::new(Ident::Values, FieldTy::BoundedSlotSpan)],
411411
)),
412412
Op::from(GenericOp::new(
413413
Ident::Branch,
@@ -417,14 +417,14 @@ fn add_control_ops(isa: &mut Isa) {
417417
Ident::BranchTable,
418418
[
419419
Field::new(Ident::Index, FieldTy::Slot),
420-
Field::new(Ident::LenTargets, FieldTy::U16),
420+
Field::new(Ident::LenTargets, FieldTy::U32),
421421
],
422422
)),
423423
Op::from(GenericOp::new(
424424
Ident::BranchTableSpan,
425425
[
426426
Field::new(Ident::Index, FieldTy::Slot),
427-
Field::new(Ident::LenTargets, FieldTy::U16),
427+
Field::new(Ident::LenTargets, FieldTy::U32),
428428
Field::new(Ident::Values, FieldTy::SlotSpan),
429429
Field::new(Ident::LenValues, FieldTy::U16),
430430
],

crates/ir2/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ pub enum Error {
99
BranchOffsetOutOfBounds,
1010
/// Encountered when trying to create a [`BlockFuel`](crate::BlockFuel) from an out of bounds integer.
1111
BlockFuelOutOfBounds,
12+
/// Encountered when trying to create a [`Memory`] from an out of bounds integer.
13+
///
14+
/// [`Memory`]: crate::index::Memory
15+
MemoryIndexOutOfBounds,
1216
}
1317

1418
impl fmt::Display for Error {
@@ -17,6 +21,7 @@ impl fmt::Display for Error {
1721
Self::StackSlotOutOfBounds => "stack slot out of bounds",
1822
Self::BranchOffsetOutOfBounds => "branch offset out of bounds",
1923
Self::BlockFuelOutOfBounds => "block fuel out of bounds",
24+
Self::MemoryIndexOutOfBounds => "memory index out of bounds",
2025
};
2126
f.write_str(s)
2227
}

crates/ir2/src/index.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ macro_rules! define_index {
6262
}
6363
for_each_index!(define_index);
6464

65+
impl TryFrom<u32> for Memory {
66+
type Error = Error;
67+
68+
fn try_from(index: u32) -> Result<Self, Self::Error> {
69+
u16::try_from(index)
70+
.map_err(|_| Error::MemoryIndexOutOfBounds)
71+
.map(Self::from)
72+
}
73+
}
74+
6575
impl TryFrom<u32> for Slot {
6676
type Error = Error;
6777

0 commit comments

Comments
 (0)