Trait cranelift_module::Backend
source · pub trait Backendwhere
Self: Sized,{
type Builder;
type CompiledFunction;
type CompiledData;
type FinalizedFunction;
type FinalizedData;
type Product;
Show 14 methods
fn new(_: Self::Builder) -> Self;
fn isa(&self) -> &dyn 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: FuncRef
);
fn write_data_dataaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: GlobalValue,
addend: 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;
}Expand description
A Backend implements the functionality needed to support a Module.
Two notable implementations of this trait are:
SimpleJITBackend, defined in cranelift-simplejit, which JITs the contents of aModuleto memory which can be directly executed.FaerieBackend, defined in cranelift-faerie, which writes the contents of aModuleout as a native object file.
Required Associated Types
sourcetype CompiledFunction
type CompiledFunction
The results of compiling a function.
sourcetype CompiledData
type CompiledData
The results of “compiling” a data object.
sourcetype FinalizedFunction
type FinalizedFunction
The completed output artifact for a function, if this is meaningful for
the Backend.
sourcetype FinalizedData
type FinalizedData
The completed output artifact for a data object, if this is meaningful for
the Backend.
Required Methods
sourcefn declare_function(&mut self, name: &str, linkage: Linkage)
fn declare_function(&mut self, name: &str, linkage: Linkage)
Declare a function.
sourcefn declare_data(&mut self, name: &str, linkage: Linkage, writable: bool)
fn declare_data(&mut self, name: &str, linkage: Linkage, writable: bool)
Declare a data object.
sourcefn define_function(
&mut self,
name: &str,
ctx: &Context,
namespace: &ModuleNamespace<'_, Self>,
code_size: u32
) -> ModuleResult<Self::CompiledFunction>
fn define_function(
&mut self,
name: &str,
ctx: &Context,
namespace: &ModuleNamespace<'_, Self>,
code_size: u32
) -> ModuleResult<Self::CompiledFunction>
Define a function, producing the function body from the given Context.
Functions must be declared before being defined.
sourcefn define_data(
&mut self,
name: &str,
writable: bool,
data_ctx: &DataContext,
namespace: &ModuleNamespace<'_, Self>
) -> ModuleResult<Self::CompiledData>
fn define_data(
&mut self,
name: &str,
writable: bool,
data_ctx: &DataContext,
namespace: &ModuleNamespace<'_, Self>
) -> ModuleResult<Self::CompiledData>
Define a zero-initialized data object of the given size.
Data objects must be declared before being defined.
sourcefn write_data_funcaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: FuncRef
)
fn write_data_funcaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: FuncRef
)
Write the address of what into the data for data at offset. data must refer to a
defined data object.
sourcefn write_data_dataaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: GlobalValue,
addend: Addend
)
fn write_data_dataaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: GlobalValue,
addend: Addend
)
Write the address of what plus addend into the data for data at offset. data must
refer to a defined data object.
sourcefn finalize_function(
&mut self,
func: &Self::CompiledFunction,
namespace: &ModuleNamespace<'_, Self>
) -> Self::FinalizedFunction
fn finalize_function(
&mut self,
func: &Self::CompiledFunction,
namespace: &ModuleNamespace<'_, Self>
) -> Self::FinalizedFunction
Perform all outstanding relocations on the given function. This requires all Local
and Export entities referenced to be defined.
sourcefn get_finalized_function(
&self,
func: &Self::CompiledFunction
) -> Self::FinalizedFunction
fn get_finalized_function(
&self,
func: &Self::CompiledFunction
) -> Self::FinalizedFunction
Return the finalized artifact from the backend, if relevant.
sourcefn finalize_data(
&mut self,
data: &Self::CompiledData,
namespace: &ModuleNamespace<'_, Self>
) -> Self::FinalizedData
fn finalize_data(
&mut self,
data: &Self::CompiledData,
namespace: &ModuleNamespace<'_, Self>
) -> Self::FinalizedData
Perform all outstanding relocations on the given data object. This requires all
Local and Export entities referenced to be defined.
sourcefn get_finalized_data(&self, data: &Self::CompiledData) -> Self::FinalizedData
fn get_finalized_data(&self, data: &Self::CompiledData) -> Self::FinalizedData
Return the finalized artifact from the backend, if relevant.