[−][src]Trait cranelift_module::Backend
A Backend
implements the functionality needed to support a Module
.
Three notable implementations of this trait are:
SimpleJITBackend
, defined in cranelift-simplejit, which JITs the contents of aModule
to memory which can be directly executed.ObjectBackend
, defined in cranelift-object, which writes the contents of aModule
out as a native object file.FaerieBackend
, defined in cranelift-faerie, which writes the contents of aModule
out as a native object file.
Associated Types
type Builder
A builder for constructing Backend
instances.
type CompiledFunction
The results of compiling a function.
type CompiledData
The results of "compiling" a data object.
type FinalizedFunction
The completed output artifact for a function, if this is meaningful for
the Backend
.
type FinalizedData
The completed output artifact for a data object, if this is meaningful for
the Backend
.
type Product
This is an object returned by Module
's
finish
function,
if the Backend
has a purpose for this.
Required methods
fn new(_: Self::Builder) -> Self
Create a new Backend
instance.
fn isa(&self) -> &dyn TargetIsa
Return the TargetIsa
to compile for.
fn declare_function(&mut self, id: FuncId, name: &str, linkage: Linkage)
Declare a function.
fn declare_data(
&mut self,
id: DataId,
name: &str,
linkage: Linkage,
writable: bool,
align: Option<u8>
)
&mut self,
id: DataId,
name: &str,
linkage: Linkage,
writable: bool,
align: Option<u8>
)
Declare a data object.
fn define_function(
&mut self,
id: FuncId,
name: &str,
ctx: &Context,
namespace: &ModuleNamespace<Self>,
code_size: u32
) -> ModuleResult<Self::CompiledFunction>
&mut self,
id: FuncId,
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.
fn define_data(
&mut self,
id: DataId,
name: &str,
writable: bool,
align: Option<u8>,
data_ctx: &DataContext,
namespace: &ModuleNamespace<Self>
) -> ModuleResult<Self::CompiledData>
&mut self,
id: DataId,
name: &str,
writable: bool,
align: Option<u8>,
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.
fn write_data_funcaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: FuncRef
)
&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.
fn write_data_dataaddr(
&mut self,
data: &mut Self::CompiledData,
offset: usize,
what: GlobalValue,
addend: Addend
)
&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.
fn finalize_function(
&mut self,
id: FuncId,
func: &Self::CompiledFunction,
namespace: &ModuleNamespace<Self>
) -> Self::FinalizedFunction
&mut self,
id: FuncId,
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.
fn get_finalized_function(
&self,
func: &Self::CompiledFunction
) -> Self::FinalizedFunction
&self,
func: &Self::CompiledFunction
) -> Self::FinalizedFunction
Return the finalized artifact from the backend, if relevant.
fn finalize_data(
&mut self,
id: DataId,
data: &Self::CompiledData,
namespace: &ModuleNamespace<Self>
) -> Self::FinalizedData
&mut self,
id: DataId,
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.
fn get_finalized_data(&self, data: &Self::CompiledData) -> Self::FinalizedData
Return the finalized artifact from the backend, if relevant.
fn publish(&mut self)
"Publish" all finalized functions and data objects to their ultimate destinations.
fn finish(self) -> Self::Product
Consume this Backend
and return a result. Some implementations may
provide additional functionality through this result.