Trait cranelift_module::Module

source ·
pub trait Module {
Show 20 methods // Required methods fn isa(&self) -> &dyn TargetIsa; fn declarations(&self) -> &ModuleDeclarations; fn declare_function( &mut self, name: &str, linkage: Linkage, signature: &Signature ) -> ModuleResult<FuncId>; fn declare_anonymous_function( &mut self, signature: &Signature ) -> ModuleResult<FuncId>; fn declare_data( &mut self, name: &str, linkage: Linkage, writable: bool, tls: bool ) -> ModuleResult<DataId>; fn declare_anonymous_data( &mut self, writable: bool, tls: bool ) -> ModuleResult<DataId>; fn define_function_with_control_plane( &mut self, func: FuncId, ctx: &mut Context, ctrl_plane: &mut ControlPlane ) -> ModuleResult<()>; fn define_function_bytes( &mut self, func_id: FuncId, func: &Function, alignment: u64, bytes: &[u8], relocs: &[FinalizedMachReloc] ) -> ModuleResult<()>; fn define_data( &mut self, data_id: DataId, data: &DataDescription ) -> ModuleResult<()>; // Provided methods fn get_name(&self, name: &str) -> Option<FuncOrDataId> { ... } fn target_config(&self) -> TargetFrontendConfig { ... } fn make_context(&self) -> Context { ... } fn clear_context(&self, ctx: &mut Context) { ... } fn make_signature(&self) -> Signature { ... } fn clear_signature(&self, sig: &mut Signature) { ... } fn declare_func_in_func( &mut self, func_id: FuncId, func: &mut Function ) -> FuncRef { ... } fn declare_data_in_func( &self, data: DataId, func: &mut Function ) -> GlobalValue { ... } fn declare_func_in_data( &self, func_id: FuncId, data: &mut DataDescription ) -> FuncRef { ... } fn declare_data_in_data( &self, data_id: DataId, data: &mut DataDescription ) -> GlobalValue { ... } fn define_function( &mut self, func: FuncId, ctx: &mut Context ) -> ModuleResult<()> { ... }
}
Expand description

A Module is a utility for collecting functions and data objects, and linking them together.

Required Methods§

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, func: FuncId, ctx: &mut Context, ctrl_plane: &mut ControlPlane ) -> ModuleResult<()>

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

Returns the size of the function’s code and constant data.

Note: After calling this function the given Context will contain the compiled function.

source

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

Define a function, taking the function body from the given bytes.

This function is generally only useful if you need to precisely specify the emitted instructions for some reason; otherwise, you should use define_function.

Returns the size of the function’s code.

source

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

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

Provided Methods§

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.

This ensures that the Context is initialized with the default calling convention for the TargetIsa.

source

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

Clear the given Context and reset it for use with a new function.

This ensures that the Context is initialized with the default calling convention for the TargetIsa.

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.

This ensures that the Signature is initialized with the default calling convention for the TargetIsa.

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.

TODO: Coalesce redundant decls and signatures. TODO: Look into ways to reduce the risk of using a FuncRef in the wrong function.

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.

TODO: Same as above.

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 ) -> ModuleResult<()>

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

Returns the size of the function’s code and constant data.

Unlike define_function_with_control_plane this uses a default ControlPlane for convenience.

Note: After calling this function the given Context will contain the compiled function.

Implementations on Foreign Types§

source§

impl<M: Module> Module for &mut M

source§

fn isa(&self) -> &dyn TargetIsa

source§

fn declarations(&self) -> &ModuleDeclarations

source§

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

source§

fn target_config(&self) -> TargetFrontendConfig

source§

fn make_context(&self) -> Context

source§

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

source§

fn make_signature(&self) -> Signature

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

fn declare_data_in_func(&self, data: DataId, func: &mut Function) -> GlobalValue

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

Implementors§