use crate::loader::decode::chunks::LambdaEntry;
use cranelift_jit::JITModule;
use std::error::Error;
use std::fmt;
use std::sync::atomic::AtomicU64;
use std::sync::{Arc, Mutex};
mod dispatch;
mod dispatch_call;
mod dispatch_core;
mod dispatch_data;
mod dispatch_helpers;
mod ir_helpers;
mod ir_typed;
#[derive(Clone, Copy)]
pub struct ModuleCompileMetadata<'a> {
pub lambdas: &'a [LambdaEntry],
pub generation: u64,
}
impl<'a> ModuleCompileMetadata<'a> {
const EMPTY: Self = Self {
lambdas: &[],
generation: 0,
};
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum JitError {
UnsupportedOpcode { opcode: String },
UnsupportedOperand { operand: String },
UnknownLabel { label: u32 },
CraneliftError(String),
EmptyFunction,
}
impl fmt::Display for JitError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnsupportedOpcode { opcode } => {
write!(formatter, "unsupported JIT opcode: {opcode}")
}
Self::UnsupportedOperand { operand } => {
write!(formatter, "unsupported JIT operand: {operand}")
}
Self::UnknownLabel { label } => write!(formatter, "unknown JIT label: {label}"),
Self::CraneliftError(error) => write!(formatter, "Cranelift JIT error: {error}"),
Self::EmptyFunction => {
write!(formatter, "cannot JIT compile an empty instruction slice")
}
}
}
}
impl Error for JitError {}
#[derive(Clone, Debug, Default)]
pub struct JitSettings;
pub struct JitCompiler {
module: Arc<Mutex<JITModule>>,
next_function_id: AtomicU64,
}
#[cfg(test)]
mod compiler_tests;