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§

source§

impl JITModule

source

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.

source

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.

source

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.

source

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.

source

pub fn finalize_definitions(&mut self) -> ModuleResult<()>

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.

Returns ModuleError in case of allocation or syscall failure

source

pub fn new(builder: JITBuilder) -> Self

Create a new JITModule.

source

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§

source§

impl Module for JITModule

source§

fn isa(&self) -> &dyn TargetIsa

Return the TargetIsa to compile for.
source§

fn declarations(&self) -> &ModuleDeclarations

Get all declarations in this module.
source§

fn declare_function( &mut self, name: &str, linkage: Linkage, signature: &Signature ) -> ModuleResult<FuncId>

Declare a function in this module.
source§

fn declare_anonymous_function( &mut self, signature: &Signature ) -> ModuleResult<FuncId>

Declare an anonymous function in this module.
source§

fn declare_data( &mut self, name: &str, linkage: Linkage, writable: bool, tls: bool ) -> ModuleResult<DataId>

Declare a data object in this module.
source§

fn declare_anonymous_data( &mut self, writable: bool, tls: bool ) -> ModuleResult<DataId>

Declare an anonymous data object in this module.
source§

fn define_function_with_control_plane( &mut self, id: FuncId, ctx: &mut Context, ctrl_plane: &mut ControlPlane ) -> ModuleResult<()>

Define a function, producing the function body from the given Context. Read more
source§

fn define_function_bytes( &mut self, id: FuncId, func: &Function, alignment: u64, bytes: &[u8], relocs: &[FinalizedMachReloc] ) -> ModuleResult<()>

Define a function, taking the function body from the given bytes. Read more
source§

fn define_data( &mut self, id: DataId, data: &DataDescription ) -> ModuleResult<()>

Define a data object, producing the data contents from the given DataContext.
source§

fn get_name(&self, name: &str) -> Option<FuncOrDataId>

Get the module identifier for a given name, if that name has been declared.
source§

fn target_config(&self) -> TargetFrontendConfig

Return the target information needed by frontends to produce Cranelift IR for the current target.
source§

fn make_context(&self) -> Context

Create a new Context initialized for use with this Module. Read more
source§

fn clear_context(&self, ctx: &mut Context)

Clear the given Context and reset it for use with a new function. Read more
source§

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.
source§

fn clear_signature(&self, sig: &mut Signature)

Clear the given Signature and reset for use with a new function. Read more
source§

fn declare_func_in_func( &mut self, func_id: FuncId, func: &mut Function ) -> FuncRef

Use this when you’re building the IR of a function to reference a function. Read more
source§

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. Read more
source§

fn declare_func_in_data( &self, func_id: FuncId, data: &mut DataDescription ) -> FuncRef

TODO: Same as above.
source§

fn declare_data_in_data( &self, data_id: DataId, data: &mut DataDescription ) -> GlobalValue

TODO: Same as above.
source§

fn define_function( &mut self, func: FuncId, ctx: &mut Context ) -> Result<(), ModuleError>

Define a function, producing the function body from the given Context. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.