use crate::DataContext;
use crate::Linkage;
use crate::ModuleNamespace;
use crate::ModuleResult;
use core::marker;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir};
pub trait Backend
where
Self: marker::Sized,
{
type Builder;
type CompiledFunction;
type CompiledData;
type FinalizedFunction;
type FinalizedData;
type Product;
fn new(_: Self::Builder) -> Self;
fn isa(&self) -> &TargetIsa;
fn declare_function(&mut self, name: &str, linkage: Linkage);
fn declare_data(&mut self, name: &str, linkage: Linkage, writable: bool);
fn define_function(
&mut self,
name: &str,
ctx: &Context,
namespace: &ModuleNamespace<Self>,
code_size: u32,
) -> ModuleResult<Self::CompiledFunction>;
fn define_data(
&mut self,
name: &str,
writable: bool,
data_ctx: &DataContext,
namespace: &ModuleNamespace<Self>,
) -> ModuleResult<Self::CompiledData>;
fn write_data_funcaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: ir::FuncRef,
);
fn write_data_dataaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: ir::GlobalValue,
addend: binemit::Addend,
);
fn finalize_function(
&mut self,
func: &Self::CompiledFunction,
namespace: &ModuleNamespace<Self>,
) -> Self::FinalizedFunction;
fn get_finalized_function(&self, func: &Self::CompiledFunction) -> Self::FinalizedFunction;
fn finalize_data(
&mut self,
data: &Self::CompiledData,
namespace: &ModuleNamespace<Self>,
) -> Self::FinalizedData;
fn get_finalized_data(&self, data: &Self::CompiledData) -> Self::FinalizedData;
fn publish(&mut self);
fn finish(self) -> Self::Product;
}