Skip to content

Commit

Permalink
add extension trait for Instruction::update_branch_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Sep 17, 2024
1 parent 9093e90 commit 1c80fcb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/wasmi/src/engine/translator/instr_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,14 +1379,23 @@ impl InstrEncoder {
}
}

impl Instruction {
/// Extension trait to update the branch offset of an [`Instruction`].
trait UpdateBranchOffset {
/// Updates the [`BranchOffset`] for the branch [`Instruction].
///
/// # Panics
///
/// If `self` is not a branch [`Instruction`].
fn update_branch_offset(
&mut self,
stack: &mut ValueStack,
new_offset: BranchOffset,
) -> Result<(), Error>;
}

impl UpdateBranchOffset for Instruction {
#[rustfmt::skip]
pub fn update_branch_offset(&mut self, stack: &mut ValueStack, new_offset: BranchOffset) -> Result<(), Error> {
fn update_branch_offset(&mut self, stack: &mut ValueStack, new_offset: BranchOffset) -> Result<(), Error> {
/// Initializes the 16-bit offset of `instr` if possible.
///
/// If `new_offset` cannot be encoded as 16-bit offset `self` is replaced with a fallback instruction.
Expand Down

0 comments on commit 1c80fcb

Please sign in to comment.