Skip to main content

Emitter

Struct Emitter 

Source
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: FunctionBuilderContext

Implementations§

Source§

impl<M: Module> Emitter<M>

Source

pub fn new(module: M) -> Self

Source

pub fn into_module(self) -> M

Source

pub(crate) fn module_mut(&mut self) -> &mut M

Source

pub fn pointer_type(&self) -> Type

Source

pub fn signature(&self, params: &[Type], returns: &[Type]) -> Signature

A signature in the system’s C calling convention.

Source

pub fn import_function( &mut self, name: &str, signature: &Signature, ) -> Result<FuncId, CodegenError>

A runtime function, called by name.

§Errors

When name was already declared with another signature.

Source

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.

Source

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.

Source

pub fn define_data( &mut self, id: DataId, blob: Blob, ) -> Result<(), CodegenError>

§Errors

When Cranelift can’t define it.

Source

pub fn data(&mut self, blob: Blob) -> Result<DataId, CodegenError>

Declares and defines read-only data private to this module.

§Errors

When Cranelift can’t define it.

Source

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.

Source

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.

Source

pub fn function( &mut self, signature: Signature, build: impl FnOnce(&mut FunctionBuilder<'_>, &mut M) -> Result<(), CodegenError>, ) -> Result<FuncId, CodegenError>

Declares and compiles a function private to this module.

§Errors

As Emitter::define_function.

Source

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.

Trait Implementations§

Source§

impl<M: Module> Debug for Emitter<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Emitter<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Emitter<M>
where M: RefUnwindSafe,

§

impl<M> Send for Emitter<M>
where M: Send,

§

impl<M> Sync for Emitter<M>
where M: Sync,

§

impl<M> Unpin for Emitter<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for Emitter<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for Emitter<M>
where M: UnwindSafe,

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> AutoreleaseSafe for T
where T: ?Sized,

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>,

Source§

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>,

Source§

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.