pub struct Compiled { /* private fields */ }Expand description
A compiled module: machine code, every function’s place and call-site records, the relocations against symbols defined elsewhere, and the module’s data.
The code refers to globals and imports through relocations
(relocations); calls between the module’s own
functions are already resolved. A linker places the code and data and
patches the relocations (object-lang writes them into an ELF relocatable
as they are).
§Examples
use backend_lang::Options;
use ir_lang::{Linkage, Module, Overflow, Signature, Type};
let mut m = Module::new("m");
let f = m.declare_function("add", &Signature::new(&[Type::I64, Type::I64], &[Type::I64]), Linkage::Export)?;
let mut b = m.build(f)?;
let (x, y) = (b.param(0)?, b.param(1)?);
let s = b.add(x, y, Overflow::Wrap)?;
b.ret(&[s])?;
let c = backend_lang::compile(&m, &Options::sysv().with_frame_pointer(false))?;
assert_eq!(c.function("add").unwrap().offset(), 0);
assert!(c.relocations().is_empty());
assert_eq!(c.code().last(), Some(&0xC3)); // retImplementations§
Source§impl Compiled
impl Compiled
Sourcepub fn functions(&self) -> &[EmittedFunction]
pub fn functions(&self) -> &[EmittedFunction]
Sourcepub fn function(&self, name: &str) -> Option<&EmittedFunction>
pub fn function(&self, name: &str) -> Option<&EmittedFunction>
Sourcepub fn relocations(&self) -> &[Reloc]
pub fn relocations(&self) -> &[Reloc]
Sourcepub fn data(&self) -> &[DataObject]
pub fn data(&self) -> &[DataObject]
Sourcepub fn imports(&self) -> &[String]
pub fn imports(&self) -> &[String]
The symbols the code and data refer to that the module does not define (imports and runtime entry points), in name order.
§Examples
use backend_lang::Options;
use ir_lang::{Linkage, Module, Signature};
let mut m = Module::new("m");
let f = m.declare_function("f", &Signature::new(&[], &[]), Linkage::Export)?;
let mut b = m.build(f)?;
b.trap(1)?;
let c = backend_lang::compile(&m, &Options::sysv())?;
assert_eq!(c.imports(), ["__lexersketch_trap"]);Trait Implementations§
impl Eq for Compiled
impl StructuralPartialEq for Compiled
Auto Trait Implementations§
impl Freeze for Compiled
impl RefUnwindSafe for Compiled
impl Send for Compiled
impl Sync for Compiled
impl Unpin for Compiled
impl UnsafeUnpin for Compiled
impl UnwindSafe for Compiled
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