Skip to main content

MetadataLoweringContext

Struct MetadataLoweringContext 

Source
pub struct MetadataLoweringContext { /* private fields */ }
Expand description

Symbol lookups and string interning backed by program metadata and the section’s symbol table.

Every @name operand resolves through one section-wide symbol table: label_address accepts any symbol, while function_address additionally requires a function declaration with that name. Function indices retain metadata table order, independently of executable addresses.

string_index interns: a string already in the table keeps its index, and a new one is appended. Lowering a code stream in address order therefore appends its literals in address order, after the strings the header derived. Take the completed table with into_strings and store it in the metadata before assembling the module. The context is independent of any instruction set; dialect crates implement their lowering-capability traits for it.

Implementations§

Source§

impl MetadataLoweringContext

Source

pub fn new<V, Ty, Info>( metadata: &ProgramMetadata<V, Ty, Info>, symbols: &[Symbol], ) -> Result<MetadataLoweringContext, Report>

Prepare section-wide string, function, and symbol lookups.

§Errors

Rejects invalid function-name indices, duplicate function names, duplicate symbols, and tables whose indices cannot be represented by u32. Full program validation remains the responsibility of the metadata loading driver.

Source

pub fn function_address(&self, name: &str) -> Result<u32, Report>

Look up a function’s executable start address: its symbol’s address.

Source

pub fn function_index(&self, name: &str) -> Result<u32, Report>

Look up a function’s index in the supplied metadata table.

Source

pub fn label_address(&self, name: &str) -> Result<u32, Report>

Look up any symbol’s address in the section’s symbol table.

Source

pub fn string_index(&mut self, text: &str) -> Result<u32, Report>

Intern decoded string contents: the index of the first equal entry, or of a new entry appended to the table.

§Errors

Fails only if the table cannot represent another u32 index.

Source

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

The string table so far: the metadata’s strings, then every interned string.

Source

pub fn into_strings(self) -> Vec<String>

The completed string table, for metadata.strings before metadata.into_module(...).

Trait Implementations§

Source§

impl Debug for MetadataLoweringContext

Source§

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

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

impl InternedStrings for MetadataLoweringContext

Source§

fn take_strings(&mut self) -> Vec<String>

Take the string table: the metadata’s strings followed by every string interned during lowering, in first-occurrence order.

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<D> Apply<PushToStack<()>> for D

Source§

fn apply(&mut self, _: PushToStack<()>)

Apply a single effect to this destination.
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> 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.

§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.