use cranelift_jit::JITModule;
use std::fmt;
use std::sync::{Arc, Mutex};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RootLocation {
Register(u16),
StackSlot(i32),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StackMapEntry {
pub offset_from_entry: u32,
pub live_roots: Vec<RootLocation>,
}
#[derive(Clone)]
pub struct NativeCode {
call_addr: usize,
stack_maps: Vec<StackMapEntry>,
_module_owner: Arc<Mutex<JITModule>>,
}
impl NativeCode {
pub(crate) fn new(
call_ptr: *const u8,
stack_maps: Vec<StackMapEntry>,
module_owner: Arc<Mutex<JITModule>>,
) -> Self {
Self {
call_addr: call_ptr as usize,
stack_maps,
_module_owner: module_owner,
}
}
#[must_use]
pub fn call_ptr(&self) -> *const u8 {
self.call_addr as *const u8
}
#[must_use]
pub fn stack_maps(&self) -> &[StackMapEntry] {
&self.stack_maps
}
}
impl fmt::Debug for NativeCode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("NativeCode")
.field("call_ptr", &self.call_ptr())
.field("stack_maps", &self.stack_maps)
.finish_non_exhaustive()
}
}