Struct cranelift_codegen::binemit::MemoryCodeSink[][src]

pub struct MemoryCodeSink<'a> {
    pub info: CodeInfo,
    // some fields omitted
}
Expand description

A CodeSink that writes binary machine code directly into memory.

A MemoryCodeSink object should be used when emitting a Cranelift IR function into executable memory. It writes machine code directly to a raw pointer without any bounds checking, so make sure to allocate enough memory for the whole function. The number of bytes required is returned by the Context::compile() function.

Any relocations in the function are forwarded to the RelocSink trait object.

Note that MemoryCodeSink writes multi-byte values in the native byte order of the host. This is not the right thing to do for cross compilation.

Fields

info: CodeInfo

Information about the generated code and read-only data.

Implementations

impl<'a> MemoryCodeSink<'a>[src]

pub unsafe fn new(
    data: *mut u8,
    relocs: &'a mut dyn RelocSink,
    traps: &'a mut dyn TrapSink,
    stack_maps: &'a mut dyn StackMapSink
) -> Self
[src]

Create a new memory code sink that writes a function to the memory pointed to by data.

Safety

This function is unsafe since MemoryCodeSink does not perform bounds checking on the memory buffer, and it can’t guarantee that the data pointer is valid.

Trait Implementations

impl<'a> CodeSink for MemoryCodeSink<'a>[src]

fn offset(&self) -> CodeOffset[src]

Get the current position.

fn put1(&mut self, x: u8)[src]

Add 1 byte to the code section.

fn put2(&mut self, x: u16)[src]

Add 2 bytes to the code section.

fn put4(&mut self, x: u32)[src]

Add 4 bytes to the code section.

fn put8(&mut self, x: u64)[src]

Add 8 bytes to the code section.

fn reloc_external(
    &mut self,
    srcloc: SourceLoc,
    rel: Reloc,
    name: &ExternalName,
    addend: Addend
)
[src]

Add a relocation referencing an external symbol plus the addend at the current offset.

fn reloc_constant(&mut self, rel: Reloc, constant_offset: ConstantOffset)[src]

Add a relocation referencing a constant.

fn reloc_jt(&mut self, rel: Reloc, jt: JumpTable)[src]

Add a relocation referencing a jump table.

fn trap(&mut self, code: TrapCode, srcloc: SourceLoc)[src]

Add trap information for the current offset.

fn begin_jumptables(&mut self)[src]

Machine code output is complete, jump table data may follow.

fn begin_rodata(&mut self)[src]

Jump table output is complete, raw read-only data may follow.

fn end_codegen(&mut self)[src]

Read-only data output is complete, we’re done.

fn add_stack_map(
    &mut self,
    val_list: &[Value],
    func: &Function,
    isa: &dyn TargetIsa
)
[src]

Add a stack map at the current code offset.

fn add_call_site(&mut self, opcode: Opcode, loc: SourceLoc)[src]

Add a call site for a call with the given opcode, returning at the current offset.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for MemoryCodeSink<'a>

impl<'a> !Send for MemoryCodeSink<'a>

impl<'a> !Sync for MemoryCodeSink<'a>

impl<'a> Unpin for MemoryCodeSink<'a>

impl<'a> !UnwindSafe for MemoryCodeSink<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.