Skip to content

Commit

Permalink
rm trace_pc and move logic to pc fn
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Jan 27, 2025
1 parent 6fadacc commit 4fde015
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
25 changes: 9 additions & 16 deletions crates/interpreter/src/interpreter/ext_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,19 @@ impl Jumps for ExtBytecode {
// SAFETY: `instruction_pointer` always point to bytecode.
unsafe { *self.instruction_pointer }
}

#[inline]
fn pc(&self) -> usize {
let bytecode = match &self.base {
Bytecode::LegacyAnalyzed(ref analyzed) => analyzed.bytecode(),
Bytecode::Eof(ref eof) => &eof.raw,
Bytecode::Eip7702(eip7702) => eip7702.raw(),
};
// SAFETY: `instruction_pointer` should be at an offset from the start of the bytecode.
// In practice this is always true unless a caller modifies the `instruction_pointer` field manually.
unsafe {
self.instruction_pointer
.offset_from(self.base.bytecode().as_ptr()) as usize
}
}
#[inline]
fn trace_pc(&self) -> usize {
match &self.base {
Bytecode::Eof(_) => unsafe {
// SAFETY: `instruction_pointer` should be at an offset from the start of the bytecode.
// In practice this is always true unless a caller modifies the `instruction_pointer` field manually.
self.instruction_pointer
.offset_from(self.base.eof().unwrap().raw.as_ptr()) as usize
},
_ => self.pc(),
}
//
// For EOF bytecode, code bytes should be part of the raw bytes.
unsafe { self.instruction_pointer.offset_from(bytecode.as_ptr()) as usize }
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/interpreter/src/interpreter_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pub trait Jumps {
fn is_valid_legacy_jump(&mut self, offset: usize) -> bool;
/// Returns current program counter.
fn pc(&self) -> usize;
/// Returns the pc offset for tracing
fn trace_pc(&self) -> usize;
/// Returns instruction opcode.
fn opcode(&self) -> u8;
}
Expand Down

0 comments on commit 4fde015

Please sign in to comment.