Skip to main content

SymbolTable

Struct SymbolTable 

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

Stores and manages symbols defined in the assembly source.

Typically used in a two-pass assembly process:

  1. Pass 1: Populate the table with label definitions and their addresses.
  2. Pass 2: Use the table to resolve symbol references in instruction operands.

Implementations§

Source§

impl SymbolTable

Source

pub fn new() -> Self

Creates a new, empty symbol table.

Source

pub fn define( &mut self, name: String, address: u32, line_number: Option<usize>, ) -> Result<(), AssemblerError>

Defines a new symbol or updates an existing one.

§Arguments
  • name - The name of the symbol (label).
  • address - The address associated with the symbol.
  • line_number - The line number where the symbol is defined (optional).
§Returns
  • Ok(()) - If the symbol was successfully defined.
  • Err(SymbolError::Redefinition) - If a symbol with the same name already exists.
Source

pub fn lookup(&self, name: &str) -> Option<&Symbol>

Looks up a symbol by its name.

§Arguments
  • name - The name of the symbol to look up.
§Returns
  • Some(&Symbol) - If the symbol is found.
  • None - If the symbol is not defined in the table.
Source

pub fn is_defined(&self, name: &str) -> bool

Checks if a symbol with the given name is defined.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &Symbol)>

Returns an iterator over the symbols in the table.

Source

pub fn len(&self) -> usize

Returns the total number of defined symbols.

Source

pub fn is_empty(&self) -> bool

Checks if the symbol table is empty.

Source

pub fn add_unresolved_reference(&mut self, name: &str, line_number: usize)

Records that an unresolved symbol was encountered at a specific location. Call this during Pass 1 when an operand uses a symbol not yet defined.

Source

pub fn check_unresolved(&self) -> Vec<(&String, &Vec<usize>)>

Checks for any symbols that were referenced but never defined after Pass 1.

Trait Implementations§

Source§

impl Debug for SymbolTable

Source§

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

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

impl Default for SymbolTable

Source§

fn default() -> SymbolTable

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.