Skip to main content

Compiled

Struct Compiled 

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

Implementations§

Source§

impl Compiled

Source

pub fn code(&self) -> &[u8] ⓘ

The machine code of every function, back to back.

§Examples

See Compiled.

Source

pub fn program(&self) -> &Program

The emitted program (code, functions, relocations).

§Examples

See Compiled.

Source

pub fn functions(&self) -> &[EmittedFunction]

Every function, in module order.

§Examples

See Compiled.

Source

pub fn function(&self, name: &str) -> Option<&EmittedFunction>

The function named name.

§Examples

See Compiled.

Source

pub fn relocations(&self) -> &[Reloc]

The code’s relocations against globals, imports, and runtime entry points.

§Examples

See Compiled.

Source

pub fn data(&self) -> &[DataObject]

The module’s globals (imported globals excluded).

§Examples

See DataObject.

Source

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

pub fn exports(&self) -> &[String]

The functions and globals with export linkage, in name order.

§Examples

See Compiled::imports.

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.