Skip to main content

Compiled

Struct Compiled 

Source
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

Source

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 entry
Source

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());
Source

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());
Source

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);
Source

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());
Source

pub fn function(&self, item: ItemId) -> Option<FuncId>

The direct-call function compiled for a HIR function item: its parameters are dyn (a by-reference parameter is a cell), followed by an i64 presence mask when any parameter has a default; it returns dyn. Root-level functions are exported under their names.

§Examples

See Compiled.

Source

pub fn origin(&self, func: FuncId, pc: u32) -> Option<NodeRef>

The HIR node instruction pc of func was compiled from.

§Examples

See Compiled.

Source

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§

Source§

impl Clone for Compiled

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Compiled

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Compiled

Source§

impl PartialEq for Compiled

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Compiled

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.