pub struct Compiled { /* private fields */ }Expand description
A compiled unit: the LSB module, its entry points, and the map from every instruction back to the HIR node it was compiled from.
§Examples
use hir_lang::{Builder, Name};
use intern_lang::Interner;
let mut names = Interner::new();
let mut b = Builder::new();
let one = b.int(1);
let body = b.block(&[], Some(one));
let f = b.func(Name::new(names.intern("one")), &[], body);
let root = b.module(None, &[f]);
let hir = b.finish(root)?;
let out = bcgen_lang::compile(&hir, &names)?;
let func = out.function(f).unwrap();
// Every instruction maps back to a node of the unit.
for pc in 0..out.module().function(func).unwrap().code().len() {
assert!(out.origin(func, pc as u32).is_some());
}Implementations§
Source§impl Compiled
impl Compiled
Sourcepub fn module(&self) -> &Module
pub fn module(&self) -> &Module
The LSB module.
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
let out = bcgen_lang::compile(&hir, &intern_lang::Interner::new())?;
assert_eq!(out.module().functions().len(), 1); // the entrySourcepub fn into_module(self) -> Module
pub fn into_module(self) -> Module
The LSB module, by value (to hand to a VM or an encoder).
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
let module = bcgen_lang::compile(&hir, &intern_lang::Interner::new())?.into_module();
assert!(!bytecode_lang::encode(&module).is_empty());Sourcepub fn entry(&self) -> FuncId
pub fn entry(&self) -> FuncId
The entry function, () -> dyn, exported as <entry>: it returns the
value of the module body (nil without one). Under
BodyMode::Start the body runs once, in the
start function, and the entry reads its kept value; under
BodyMode::Entry the entry is the body.
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
let out = bcgen_lang::compile(&hir, &intern_lang::Interner::new())?;
assert!(out.module().function(out.entry()).is_some());Sourcepub fn start(&self) -> Option<FuncId>
pub fn start(&self) -> Option<FuncId>
The module’s start function, if it has one: global and constant
initializers, defaults evaluated once, and (under BodyMode::Start)
the body.
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
assert_eq!(bcgen_lang::compile(&hir, &intern_lang::Interner::new())?.start(), None);Sourcepub fn result_global(&self) -> Option<GlobalId>
pub fn result_global(&self) -> Option<GlobalId>
The global holding the module body’s value under BodyMode::Start.
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
assert!(bcgen_lang::compile(&hir, &intern_lang::Interner::new())?.result_global().is_none());Sourcepub fn origins(&self, func: FuncId) -> &[NodeRef]
pub fn origins(&self, func: FuncId) -> &[NodeRef]
The HIR node of every instruction of func, indexed by pc.
§Examples
let hir = { let mut b = hir_lang::Builder::new(); let r = b.module(None, &[]); b.finish(r)? };
let out = bcgen_lang::compile(&hir, &intern_lang::Interner::new())?;
assert_eq!(out.origins(out.entry()).len(), out.module().function(out.entry()).unwrap().code().len());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