Struct lc3_ensemble::asm::SymbolTable
source · pub struct SymbolTable { /* private fields */ }Expand description
The symbol table created in the first assembler pass that encodes source code mappings to memory addresses in the object file.
The symbol table consists of:
- A mapping from source code labels to memory addresses.
- A mapping from source code line numbers to memory addresses (if debug symbols are enabled, see
SymbolTable::new). - The source text (if debug symbols are enabled, see
SymbolTable::new).
Implementations§
source§impl SymbolTable
impl SymbolTable
sourcepub fn new(stmts: &[Stmt], src: Option<&str>) -> Result<Self, AsmErr>
pub fn new(stmts: &[Stmt], src: Option<&str>) -> Result<Self, AsmErr>
Creates a new symbol table.
This performs the first assembler pass, calculating the memory address of labels at each provided statement.
If a src argument is provided, this also computes debug symbols and includes them
within this SymbolTable struct. These debug symbols include:
- Mappings from source code line numbers to memory addresses
- Source code text (and more detailed calculations with source code, see
SourceInfofor more details)
sourcepub fn get_label(&self, label: &str) -> Option<u16>
pub fn get_label(&self, label: &str) -> Option<u16>
Gets the memory address of a given label (if it exists).
sourcepub fn find_label_source(&self, label: &str) -> Option<Range<usize>>
pub fn find_label_source(&self, label: &str) -> Option<Range<usize>>
Gets the source span of a given label (if it exists).
sourcepub fn label_iter(&self) -> impl Iterator<Item = (&str, u16)> + '_
pub fn label_iter(&self) -> impl Iterator<Item = (&str, u16)> + '_
Gets an iterable of the mapping from labels to addresses.
sourcepub fn get_line(&self, line: usize) -> Option<u16>
pub fn get_line(&self, line: usize) -> Option<u16>
Gets the address of a given source line.
If debug symbols are not enabled, this unconditionally returns None.
sourcepub fn find_line_source(&self, addr: u16) -> Option<usize>
pub fn find_line_source(&self, addr: u16) -> Option<usize>
Gets the source line of a given memory address (if it exists.)
The result can be converted into a source span (range of characters encompassed by the instruction)
using SymbolTable::source_info and SourceInfo::line_span.
If debug symbols are not enabled, this unconditionally returns None.
sourcepub fn source_info(&self) -> Option<&SourceInfo>
pub fn source_info(&self) -> Option<&SourceInfo>
Reads the source info from this symbol table (if debug symbols are enabled).