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
impl ConstantTable
pub fn new() -> Self
pub fn new() -> Self
Creates a new constant table.
pub fn add_string(&mut self, constant_string: &str) -> ConstantIndex
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
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
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
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
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
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
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>
pub fn get_float_constants(&self) -> Vec<ConstantFloatEntry>
Returns a vector of all the floating point constants.