pub struct Emitter<M: Module> {
module: M,
context: Context,
builder_context: FunctionBuilderContext,
}Expand description
A module being written, with the contexts Cranelift reuses between functions.
Fields§
§module: M§context: Context§builder_context: FunctionBuilderContextImplementations§
Source§impl<M: Module> Emitter<M>
impl<M: Module> Emitter<M>
pub fn new(module: M) -> Self
pub fn into_module(self) -> M
pub(crate) fn module_mut(&mut self) -> &mut M
pub fn pointer_type(&self) -> Type
Sourcepub fn signature(&self, params: &[Type], returns: &[Type]) -> Signature
pub fn signature(&self, params: &[Type], returns: &[Type]) -> Signature
A signature in the system’s C calling convention.
Sourcepub fn import_function(
&mut self,
name: &str,
signature: &Signature,
) -> Result<FuncId, CodegenError>
pub fn import_function( &mut self, name: &str, signature: &Signature, ) -> Result<FuncId, CodegenError>
Sourcepub fn import_data(&mut self, name: &str) -> Result<DataId, CodegenError>
pub fn import_data(&mut self, name: &str) -> Result<DataId, CodegenError>
Runtime data, such as a built-in type, referred to by name.
§Errors
When name was already declared as something else.
Sourcepub fn declare_data(&mut self) -> Result<DataId, CodegenError>
pub fn declare_data(&mut self) -> Result<DataId, CodegenError>
Read-only data private to this module, defined later with Emitter::define_data,
so other data can point at it first.
§Errors
When Cranelift can’t declare it.
Sourcepub fn define_data(
&mut self,
id: DataId,
blob: Blob,
) -> Result<(), CodegenError>
pub fn define_data( &mut self, id: DataId, blob: Blob, ) -> Result<(), CodegenError>
§Errors
When Cranelift can’t define it.
Sourcepub fn data(&mut self, blob: Blob) -> Result<DataId, CodegenError>
pub fn data(&mut self, blob: Blob) -> Result<DataId, CodegenError>
Sourcepub fn declare_function(
&mut self,
signature: &Signature,
) -> Result<FuncId, CodegenError>
pub fn declare_function( &mut self, signature: &Signature, ) -> Result<FuncId, CodegenError>
A function private to this module, compiled later with
Emitter::define_function, so code can call it first.
§Errors
When Cranelift can’t declare it.
Sourcepub fn define_function(
&mut self,
id: FuncId,
signature: Signature,
build: impl FnOnce(&mut FunctionBuilder<'_>, &mut M) -> Result<(), CodegenError>,
) -> Result<(), CodegenError>
pub fn define_function( &mut self, id: FuncId, signature: Signature, build: impl FnOnce(&mut FunctionBuilder<'_>, &mut M) -> Result<(), CodegenError>, ) -> Result<(), CodegenError>
Compiles id, whose body build emits from its entry block, which has the
signature’s parameters and is current when build starts. build also gets the
module, to refer to other functions and data.
§Errors
The error build returns, or Cranelift’s when it can’t compile the body.
Sourcepub fn function(
&mut self,
signature: Signature,
build: impl FnOnce(&mut FunctionBuilder<'_>, &mut M) -> Result<(), CodegenError>,
) -> Result<FuncId, CodegenError>
pub fn function( &mut self, signature: Signature, build: impl FnOnce(&mut FunctionBuilder<'_>, &mut M) -> Result<(), CodegenError>, ) -> Result<FuncId, CodegenError>
Sourcepub fn define_main(&mut self, program: DataId) -> Result<(), CodegenError>
pub fn define_main(&mut self, program: DataId) -> Result<(), CodegenError>
Emits main, which hands program, a nifty_rt::ProgramDesc, to the runtime and
returns the exit status it gives back.
§Errors
When Cranelift can’t compile it.