Skip to main content

Module

Trait 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, alignment: u64, bytes: &[u8], relocs: &[ModuleReloc], ) -> 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, alignment: u64, bytes: &[u8], relocs: &[ModuleReloc], ) -> 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 DataDescription.

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<M: Module + ?Sized> 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, alignment: u64, bytes: &[u8], relocs: &[ModuleReloc], ) -> ModuleResult<()>

Source§

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

Source§

impl<M: Module + ?Sized> Module for Box<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, alignment: u64, bytes: &[u8], relocs: &[ModuleReloc], ) -> ModuleResult<()>

Source§

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

Implementors§