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).
Here is a table of the mappings that the symbol table provides:
| from ↓, to → | label | memory address | source line/span |
|---|---|---|---|
| label | - | SymbolTable::lookup_label | SymbolTable::get_label_source |
| memory address | SymbolTable::rev_lookup_label | - | SymbolTable::rev_lookup_line |
| source line | none | SymbolTable::lookup_line | - |
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 lookup_label(&self, label: &str) -> Option<u16>
pub fn lookup_label(&self, label: &str) -> Option<u16>
Gets the memory address of a given label (if it exists).
sourcepub fn rev_lookup_label(&self, addr: u16) -> Option<&str>
pub fn rev_lookup_label(&self, addr: u16) -> Option<&str>
Gets the label at a given memory address (if it exists).
sourcepub fn get_label_source(&self, label: &str) -> Option<Range<usize>>
pub fn get_label_source(&self, label: &str) -> Option<Range<usize>>
Gets the source span of a given label (if it exists).
sourcepub fn lookup_line(&self, line: usize) -> Option<u16>
pub fn lookup_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 rev_lookup_line(&self, addr: u16) -> Option<usize>
pub fn rev_lookup_line(&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).
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.