use crate::{CompilerError, program::InstructionArray, register::RegisterFile};
#[cfg(all(feature = "compiler", target_arch = "x86_64"))]
mod x86_64;
#[cfg(all(feature = "compiler", target_arch = "aarch64"))]
mod aarch64;
#[cfg(all(
feature = "compiler",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
mod util;
pub(crate) struct Executable {
#[cfg(all(
feature = "compiler",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
buffer: util::ExecutableBuffer,
}
#[cfg(any(
not(feature = "compiler"),
not(any(target_arch = "x86_64", target_arch = "aarch64"))
))]
impl Architecture for Executable {
fn compile(_program: &InstructionArray) -> Result<Self, CompilerError> {
Err(CompilerError::NotAvailable)
}
fn invoke(&self, _regs: &mut RegisterFile) {
unreachable!();
}
}
#[cfg(any(
not(feature = "compiler"),
not(any(target_arch = "x86_64", target_arch = "aarch64"))
))]
impl std::fmt::Debug for Executable {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
unreachable!()
}
}
pub(crate) trait Architecture
where
Self: Sized,
{
fn compile(program: &InstructionArray) -> Result<Self, CompilerError>;
fn invoke(&self, regs: &mut RegisterFile);
}