Struct cranelift_jit::JITModule
source · [−]pub struct JITModule { /* private fields */ }
Expand description
A JITModule
implements Module
and emits code and data into memory where it can be
directly called and accessed.
See the JITBuilder
for a convenient way to construct JITModule
instances.
Implementations
sourceimpl JITModule
impl JITModule
sourcepub unsafe fn free_memory(self)
pub unsafe fn free_memory(self)
Free memory allocated for code and data segments of compiled functions.
Safety
Because this function invalidates any pointers retrived from the
corresponding module, it should only be used when none of the functions
from that module are currently executing and none of the fn
pointers
are called afterwards.
sourcepub fn read_got_entry(&self, func_id: FuncId) -> *const u8
pub fn read_got_entry(&self, func_id: FuncId) -> *const u8
Returns the given function’s entry in the Global Offset Table.
Panics if there’s no entry in the table for the given function.
sourcepub fn get_finalized_function(&self, func_id: FuncId) -> *const u8
pub fn get_finalized_function(&self, func_id: FuncId) -> *const u8
Returns the address of a finalized function.
The pointer remains valid until either JITModule::free_memory
is called or in the future
some way of deallocating this individual function is used.
sourcepub fn get_finalized_data(&self, data_id: DataId) -> (*const u8, usize)
pub fn get_finalized_data(&self, data_id: DataId) -> (*const u8, usize)
Returns the address and size of a finalized data object.
The pointer remains valid until either JITModule::free_memory
is called or in the future
some way of deallocating this individual data object is used.
sourcepub fn finalize_definitions(&mut self)
pub fn finalize_definitions(&mut self)
Finalize all functions and data objects that are defined but not yet finalized. All symbols referenced in their bodies that are declared as needing a definition must be defined by this point.
Use get_finalized_function
and get_finalized_data
to obtain the final
artifacts.
sourcepub fn new(builder: JITBuilder) -> Self
pub fn new(builder: JITBuilder) -> Self
Create a new JITModule
.
sourcepub fn prepare_for_function_redefine(
&mut self,
func_id: FuncId
) -> ModuleResult<()>
pub fn prepare_for_function_redefine(
&mut self,
func_id: FuncId
) -> ModuleResult<()>
Allow a single future define_function
on a previously defined function. This allows for
hot code swapping and lazy compilation of functions.
This requires hotswap support to be enabled first using JITBuilder::hotswap
.
Trait Implementations
sourceimpl Module for JITModule
impl Module for JITModule
sourcefn declare_func_in_func(&self, func: FuncId, in_func: &mut Function) -> FuncRef
fn declare_func_in_func(&self, func: FuncId, in_func: &mut Function) -> FuncRef
Use this when you’re building the IR of a function to reference a function.
TODO: Coalesce redundant decls and signatures. TODO: Look into ways to reduce the risk of using a FuncRef in the wrong function.
sourcefn declare_data_in_func(&self, data: DataId, func: &mut Function) -> GlobalValue
fn declare_data_in_func(&self, data: DataId, func: &mut Function) -> GlobalValue
Use this when you’re building the IR of a function to reference a data object.
TODO: Same as above.
sourcefn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> FuncRef
fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> FuncRef
TODO: Same as above.
sourcefn declare_data_in_data(
&self,
data: DataId,
ctx: &mut DataContext
) -> GlobalValue
fn declare_data_in_data(
&self,
data: DataId,
ctx: &mut DataContext
) -> GlobalValue
TODO: Same as above.
sourcefn declarations(&self) -> &ModuleDeclarations
fn declarations(&self) -> &ModuleDeclarations
Get all declarations in this module.
sourcefn declare_function(
&mut self,
name: &str,
linkage: Linkage,
signature: &Signature
) -> ModuleResult<FuncId>
fn declare_function(
&mut self,
name: &str,
linkage: Linkage,
signature: &Signature
) -> ModuleResult<FuncId>
Declare a function in this module.
sourcefn declare_anonymous_function(
&mut self,
signature: &Signature
) -> ModuleResult<FuncId>
fn declare_anonymous_function(
&mut self,
signature: &Signature
) -> ModuleResult<FuncId>
Declare an anonymous function in this module.
sourcefn declare_data(
&mut self,
name: &str,
linkage: Linkage,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
fn declare_data(
&mut self,
name: &str,
linkage: Linkage,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
Declare a data object in this module.
sourcefn declare_anonymous_data(
&mut self,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
fn declare_anonymous_data(
&mut self,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
Declare an anonymous data object in this module.
sourcefn define_function(
&mut self,
id: FuncId,
ctx: &mut Context
) -> ModuleResult<ModuleCompiledFunction>
fn define_function(
&mut self,
id: FuncId,
ctx: &mut Context
) -> ModuleResult<ModuleCompiledFunction>
Define a function, producing the function body from the given Context
. Read more
sourcefn define_function_bytes(
&mut self,
id: FuncId,
bytes: &[u8],
relocs: &[MachReloc]
) -> ModuleResult<ModuleCompiledFunction>
fn define_function_bytes(
&mut self,
id: FuncId,
bytes: &[u8],
relocs: &[MachReloc]
) -> ModuleResult<ModuleCompiledFunction>
Define a function, taking the function body from the given bytes
. Read more
sourcefn define_data(&mut self, id: DataId, data: &DataContext) -> ModuleResult<()>
fn define_data(&mut self, id: DataId, data: &DataContext) -> ModuleResult<()>
Define a data object, producing the data contents from the given DataContext
.
sourcefn get_name(&self, name: &str) -> Option<FuncOrDataId>
fn get_name(&self, name: &str) -> Option<FuncOrDataId>
Get the module identifier for a given name, if that name has been declared. Read more
sourcefn target_config(&self) -> TargetFrontendConfig
fn target_config(&self) -> TargetFrontendConfig
Return the target information needed by frontends to produce Cranelift IR for the current target. Read more
sourcefn make_context(&self) -> Context
fn make_context(&self) -> Context
Create a new Context
initialized for use with this Module
. Read more
sourcefn clear_context(&self, ctx: &mut Context)
fn clear_context(&self, ctx: &mut Context)
Clear the given Context
and reset it for use with a new function. Read more
sourcefn make_signature(&self) -> Signature
fn make_signature(&self) -> Signature
Create a new empty Signature
with the default calling convention for
the TargetIsa
, to which parameter and return types can be added for
declaring a function to be called by this Module
. Read more
sourcefn clear_signature(&self, sig: &mut Signature)
fn clear_signature(&self, sig: &mut Signature)
Clear the given Signature
and reset for use with a new function. Read more
Auto Trait Implementations
impl !RefUnwindSafe for JITModule
impl !Send for JITModule
impl !Sync for JITModule
impl Unpin for JITModule
impl !UnwindSafe for JITModule
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more