pub struct Code { /* private fields */ }Expand description
Finished machine code and the final offsets of its labels.
§Examples
use isa_lang::x86_64::{Assembler, Inst, Mnemonic};
let mut asm = Assembler::new();
let entry = asm.label();
asm.bind(entry)?;
asm.emit(&Inst::new(Mnemonic::Ret, []))?;
let code = asm.finish()?;
assert_eq!(code.label_offset(entry), Some(0));
assert_eq!(code.into_bytes(), vec![0xC3]);Implementations§
Source§impl Code
impl Code
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
The machine code.
§Examples
use isa_lang::x86_64::{Assembler, Inst, Mnemonic};
let mut asm = Assembler::new();
asm.emit(&Inst::new(Mnemonic::Cqo, []))?;
assert_eq!(asm.finish()?.bytes(), [0x48, 0x99]);Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
The machine code, by value.
§Examples
use isa_lang::x86_64::Assembler;
assert!(Assembler::new().finish()?.into_bytes().is_empty());Sourcepub fn label_offset(&self, label: Label) -> Option<usize>
pub fn label_offset(&self, label: Label) -> Option<usize>
Where label ended up, or None if it was never bound (or belongs
to another assembler).
§Examples
use isa_lang::x86_64::Assembler;
let mut asm = Assembler::new();
let unused = asm.label();
assert_eq!(asm.finish()?.label_offset(unused), None);Trait Implementations§
impl Eq for Code
impl StructuralPartialEq for Code
Auto Trait Implementations§
impl Freeze for Code
impl RefUnwindSafe for Code
impl Send for Code
impl Sync for Code
impl Unpin for Code
impl UnsafeUnpin for Code
impl UnwindSafe for Code
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more