pub struct Program { /* private fields */ }Expand description
Machine code with the offset of each function, the relocations against external symbols, and the call-site records.
§Examples
use backend_lang::mir::Function;
use backend_lang::x86_64::{op, Emitter, SYSV};
let mut f = Function::new("f", &SYSV);
let b = f.block()?;
f.push(b, op::RET, &[])?;
let mut e = Emitter::new();
e.function(&f)?;
let program = e.finish()?;
assert_eq!(program.symbol("f"), Some(0));
// push rbp; mov rbp, rsp; pop rbp; ret
assert_eq!(program.bytes(), [0x55, 0x48, 0x89, 0xE5, 0x5D, 0xC3]);Implementations§
Source§impl Program
impl Program
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
The machine code.
§Examples
use backend_lang::x86_64::Emitter;
assert!(Emitter::new().finish()?.bytes().is_empty());Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
The machine code, by value.
§Examples
use backend_lang::x86_64::Emitter;
assert!(Emitter::new().finish()?.into_bytes().is_empty());Sourcepub fn symbol(&self, name: &str) -> Option<usize>
pub fn symbol(&self, name: &str) -> Option<usize>
The offset of the function named name.
§Examples
use backend_lang::x86_64::Emitter;
assert_eq!(Emitter::new().finish()?.symbol("missing"), None);Sourcepub fn symbols(&self) -> impl Iterator<Item = (&str, usize)>
pub fn symbols(&self) -> impl Iterator<Item = (&str, usize)>
Every function and its offset, in name order.
§Examples
use backend_lang::x86_64::Emitter;
assert_eq!(Emitter::new().finish()?.symbols().count(), 0);Sourcepub fn functions(&self) -> &[EmittedFunction]
pub fn functions(&self) -> &[EmittedFunction]
Every function, in emission order, with its size, frame, and call-site records.
§Examples
use backend_lang::x86_64::Emitter;
assert!(Emitter::new().finish()?.functions().is_empty());Sourcepub fn relocations(&self) -> &[Reloc]
pub fn relocations(&self) -> &[Reloc]
Trait Implementations§
impl Eq for Program
impl StructuralPartialEq for Program
Auto Trait Implementations§
impl Freeze for Program
impl RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnsafeUnpin for Program
impl UnwindSafe for Program
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