use crate::types::Opcode;
#[derive(Debug, Copy, Clone, PartialEq)]
#[repr(transparent)]
pub struct InstructionPtr {
pub(crate) ptr: *const Opcode,
}
unsafe impl Send for InstructionPtr {}
impl InstructionPtr {
#[inline]
pub fn new(ptr: *const Opcode) -> Self {
Self { ptr }
}
#[inline(always)]
pub fn offset(&mut self, by: isize) {
self.ptr = unsafe { self.ptr.offset(by) };
}
#[inline(always)]
pub fn add(&mut self, delta: usize) {
self.ptr = unsafe { self.ptr.add(delta) };
}
#[inline(always)]
pub fn get(&self) -> Opcode {
unsafe { *self.ptr }
}
#[cfg(feature = "tracing")]
pub fn is_valid(self, max: u64) -> bool {
self.ptr as u64 <= max
}
}