Struct ConstantTable

pub struct ConstantTable { /* private fields */ }
Expand description

A table of constant values.

The constant table allows us to deduplicate data. Instead of repeating the same constant value (e.g. string literal, or floating-point value) in the generated assembly code, we store it once and refer to it by its unique index.

Implementations§

§

impl ConstantTable

pub fn new() -> Self

Creates a new constant table.

pub fn is_empty(&self) -> bool

Returns true if the table contains no entries.

pub fn len(&self) -> usize

The number of entries in the table.

pub fn add_string(&mut self, constant_string: &str) -> ConstantIndex

Adds a new string constant to the table and returns its unique identifier, or if the constant already exists then returns the existing unique identifier that represents the constant value.

pub fn add_string_array( &mut self, variable_name: AstUniqueName, values: Vec<String>, ) -> ConstantIndex

Adds a new constant array of strings to the table for the given variable name.

pub fn add_f32( &mut self, constant_value: f32, required_alignment: usize, ) -> ConstantIndex

Adds a new f32 constant to the table and returns its unique identifier, or if the constant already exists then returns the existing unique identifier that represents the constant value.

pub fn add_f64( &mut self, constant_value: f64, required_alignment: usize, ) -> ConstantIndex

Adds a new f64 constant to the table and returns its unique identifier, or if the constant already exists then returns the existing unique identifier that represents the constant value.

pub fn get_constant_value_by_index( &self, index: ConstantIndex, ) -> &ConstantValue

Returns the value for the constant at the given index.

pub fn get_constant_value_by_name(&self, name: &str) -> &ConstantValue

Returns the value for the given constant.

pub fn make_const_symbol_name(&self, index: ConstantIndex) -> String

Creates a symbol name for the given constant index.

pub fn get_float_constants(&self) -> Vec<ConstantFloatEntry>

Returns a vector of all the floating point constants.

Trait Implementations§

§

impl Debug for ConstantTable

§

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

Formats the value using the given formatter. Read more
§

impl Default for ConstantTable

§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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.