Skip to main content

CodeBuffer

Struct CodeBuffer 

Source
pub struct CodeBuffer { /* private fields */ }
Expand description

A buffer of output to be produced, fixed up, and then emitted to a CodeSink in bulk.

This struct uses SmallVecs to support small-ish function bodies without any heap allocation. As such, it will be several kilobytes large. This is likely fine as long as it is stack-allocated for function emission then thrown away; but beware if many buffer objects are retained persistently.

Implementations§

Source§

impl CodeBuffer

Source

pub fn new() -> Self

Source

pub fn with_env(env: Environment) -> Self

Source

pub fn clear(&mut self)

Source

pub fn env(&self) -> &Environment

Source

pub fn env_mut(&mut self) -> &mut Environment

Source

pub fn data(&self) -> &[u8]

Source

pub fn data_mut(&mut self) -> &mut [u8]

Source

pub fn relocs(&self) -> &[AsmReloc]

Source

pub fn put1(&mut self, value: u8)

Source

pub fn put2(&mut self, value: u16)

Source

pub fn put4(&mut self, value: u32)

Source

pub fn put8(&mut self, value: u64)

Source

pub fn write_u8(&mut self, value: u8)

Source

pub fn write_u16(&mut self, value: u16)

Source

pub fn write_u32(&mut self, value: u32)

Source

pub fn write_u64(&mut self, value: u64)

Source

pub fn add_symbol( &mut self, name: impl Into<ExternalName>, distance: RelocDistance, ) -> Sym

Source

pub fn symbol_distance(&self, sym: Sym) -> RelocDistance

Source

pub fn symbol_name(&self, sym: Sym) -> &ExternalName

Source

pub fn get_label(&mut self) -> Label

Source

pub fn get_label_for_constant(&mut self, constant: Constant) -> Label

Source

pub fn add_constant(&mut self, constant: impl Into<ConstantData>) -> Constant

Source

pub fn use_label_at_offset( &mut self, offset: CodeOffset, label: Label, kind: LabelUse, )

Source

pub fn align_to(&mut self, align_to: CodeOffset)

Align up to the given alignment.

Source

pub fn cur_offset(&self) -> CodeOffset

Source

pub fn bind_label(&mut self, label: Label)

Source

pub fn label_offset(&self, label: Label) -> u32

Source

pub fn add_reloc(&mut self, kind: Reloc, target: RelocTarget, addend: i64)

Source

pub fn add_reloc_at_offset( &mut self, offset: CodeOffset, kind: Reloc, target: RelocTarget, addend: i64, )

Source

pub fn reserve_patch_block( &mut self, size: CodeOffset, align: CodeOffset, ) -> Result<PatchBlockId, AsmError>

Source

pub fn record_patch_block( &mut self, offset: CodeOffset, size: CodeOffset, align: CodeOffset, ) -> PatchBlockId

Source

pub fn record_patch_site( &mut self, offset: CodeOffset, kind: LabelUse, target_offset: CodeOffset, ) -> PatchSiteId

Source

pub fn record_label_patch_site( &mut self, offset: CodeOffset, label: Label, kind: LabelUse, ) -> PatchSiteId

Source

pub fn emit_veneer(&mut self, label: Label, offset: CodeOffset, kind: LabelUse)

Emits a “veneer” the kind code at offset to jump to label.

This will generate extra machine code, using kind, to get a larger-jump-kind than kind allows. The code at offset is then patched to jump to our new code, and then the new code is enqueued for a fixup to get processed at some later time.

Source

pub fn get_appended_space(&mut self, len: usize) -> &mut [u8]

Reserve appended space and return a mutable slice referring to it.

Source

pub fn island_needed(&mut self, distance: CodeOffset) -> bool

Is an island needed within the next N bytes?

Source

pub fn emit_island(&mut self, distance: CodeOffset)

Emit all pending constants and required pending veneers.

Source

pub fn finish_patched(self) -> Result<CodeBufferFinalized, AsmError>

Source

pub fn finish(&mut self) -> CodeBufferFinalized

Trait Implementations§

Source§

impl Default for CodeBuffer

Source§

fn default() -> CodeBuffer

Returns the “default value” for a type. Read more

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 = 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.