Skip to main content

Emitter

Struct Emitter 

Source
pub struct Emitter { /* private fields */ }

Implementations§

Source§

impl Emitter

Source

pub fn new(dialect: AsmDialect) -> Emitter

Source

pub fn with_span<R>( &mut self, span: &Span, f: impl FnOnce(&mut Emitter) -> R, ) -> R

Source

pub fn without_span<R>(&mut self, f: impl FnOnce(&mut Emitter) -> R) -> R

Source

pub fn ins(&mut self, text: &str)

One instruction or directive line.

Source

pub fn ins_cmt(&mut self, text: &str, comment: &str)

Instruction with a trailing // comment (source snippets, slot names).

Source

pub fn comment(&mut self, comment: &str)

Standalone comment line.

Source

pub fn label(&mut self, name: &str)

Source

pub fn label_cmt(&mut self, name: &str, comment: &str)

Source

pub fn new_label(&mut self) -> String

Source

pub fn new_function_label(&mut self) -> String

Source

pub fn intern_string(&mut self, bytes: &[u8]) -> (String, u64)

Interns a string literal into .rodata, deduplicated; returns (label, byte length).

Source

pub fn load_imm64(&mut self, reg: &str, value: u64, comment: &str)

Materializes any 64-bit constant: one movz plus up to three movk, skipping zero halfwords (design §6). Never assumes mov reg, #imm encodes.

Source

pub fn load_label_address(&mut self, reg: &str, label: &str, comment: &str)

reg = address of label via adrp plus the low-12-bits add, spelled :lo12: on ELF and @PAGE/@PAGEOFF on Mach-O (design §6, §9).

Source

pub fn call_runtime(&mut self, name: &str, comment: &str)

bl to an rt_* entry point by its C name; the dialect supplies the Mach-O _ prefix (bl rt_add vs bl _rt_add). Every runtime call must go through here so no bl hardcodes a platform spelling.

Source

pub fn push_acc(&mut self, comment: &str)

Pushes the accumulator, one value per 16-byte slot (design §6).

Source

pub fn pop(&mut self, reg: &str, comment: &str)

Source

pub fn sp_sub(&mut self, bytes: u64)

Grows the stack by bytes (16-aligned by contract), splitting or materializing when the immediate does not encode (design §6).

Source

pub fn sp_add(&mut self, bytes: u64)

Source

pub fn frame_store(&mut self, reg: &str, offset: u64, comment: &str)

Stores reg at [x29, #-offset], going through x8 when the unscaled immediate cannot encode the slot (design §6). reg must not be x8.

Source

pub fn frame_load(&mut self, reg: &str, offset: u64, comment: &str)

Source

pub fn sp_store(&mut self, reg: &str, offset: u64, comment: &str)

Stores reg at [sp, #offset] (call/scratch area fill); offsets beyond the scaled immediate go through x8. reg must not be x8.

Source

pub fn sp_address(&mut self, reg: &str, offset: u64, comment: &str)

reg = sp + offset (argv base and friends).

Source

pub fn global_load(&mut self, reg: &str, index: usize, comment: &str)

Reads global slot index from the single g_globals array (design §5.2); clobbers x8/x9.

Source

pub fn global_store(&mut self, reg: &str, index: usize, comment: &str)

Source

pub fn begin_function(&mut self)

Opens a fresh function body buffer; instructions emitted until the matching end_function go to it (design §6.1).

Source

pub fn end_function(&mut self, frame: FunctionFrame)

Closes the current function body: computes the frame from the final symbol count, splices prologue (fp/lr save, frame, spills, null initialization) and the shared epilogue, and appends the finished function (design §6, §6.1).

Source

pub fn finish( self, globals_count: usize, main_epilogue_label: &str, observe: bool, ) -> Assembly

Assembles the final module: main (with observer/globals init and the fixed mov w0, #0 exit), then every finished function, .rodata, and the g_globals .bss array (design §6, §6.1).

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.