Struct cranelift_codegen::binemit::MemoryCodeSink
source · [−]pub struct MemoryCodeSink<'a> {
pub info: CodeInfo,
/* private fields */
}
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
sourceimpl<'a> MemoryCodeSink<'a>
impl<'a> MemoryCodeSink<'a>
sourcepub unsafe fn new(
data: *mut u8,
relocs: &'a mut dyn RelocSink,
traps: &'a mut dyn TrapSink,
stack_maps: &'a mut dyn StackMapSink
) -> Self
pub unsafe fn new(
data: *mut u8,
relocs: &'a mut dyn RelocSink,
traps: &'a mut dyn TrapSink,
stack_maps: &'a mut dyn StackMapSink
) -> Self
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
sourceimpl<'a> CodeSink for MemoryCodeSink<'a>
impl<'a> CodeSink for MemoryCodeSink<'a>
sourcefn offset(&self) -> CodeOffset
fn offset(&self) -> CodeOffset
Get the current position.
sourcefn reloc_external(
&mut self,
srcloc: SourceLoc,
rel: Reloc,
name: &ExternalName,
addend: Addend
)
fn reloc_external(
&mut self,
srcloc: SourceLoc,
rel: Reloc,
name: &ExternalName,
addend: Addend
)
Add a relocation referencing an external symbol plus the addend at the current offset.
sourcefn reloc_constant(&mut self, rel: Reloc, constant_offset: ConstantOffset)
fn reloc_constant(&mut self, rel: Reloc, constant_offset: ConstantOffset)
Add a relocation referencing a constant.
sourcefn trap(&mut self, code: TrapCode, srcloc: SourceLoc)
fn trap(&mut self, code: TrapCode, srcloc: SourceLoc)
Add trap information for the current offset.
sourcefn begin_jumptables(&mut self)
fn begin_jumptables(&mut self)
Machine code output is complete, jump table data may follow.
sourcefn begin_rodata(&mut self)
fn begin_rodata(&mut self)
Jump table output is complete, raw read-only data may follow.
sourcefn end_codegen(&mut self)
fn end_codegen(&mut self)
Read-only data output is complete, we’re done.
sourcefn add_stack_map(
&mut self,
val_list: &[Value],
func: &Function,
isa: &dyn TargetIsa
)
fn add_stack_map(
&mut self,
val_list: &[Value],
func: &Function,
isa: &dyn TargetIsa
)
Add a stack map at the current code offset.
sourcefn add_call_site(&mut self, opcode: Opcode, loc: SourceLoc)
fn add_call_site(&mut self, opcode: Opcode, loc: SourceLoc)
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more