Package mars.assembler
Class SymbolTable
java.lang.Object
mars.assembler.SymbolTable
A symbol table used by the assembler to map symbols to the corresponding addresses.
- Author:
- Jason Bumgarner & Jason Shrewsbury, June 2003
-
Constructor Summary
ConstructorsConstructorDescriptionSymbolTable
(String filename) Create a new empty symbol table corresponding to the given filename. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all symbols from the table.defineSymbol
(String identifier, int address, boolean isData) Adds a Symbol object into the array of Symbols.defineSymbol
(Symbol symbol) Adds a Symbol object into the array of Symbols.getAddress
(String identifier) Get the address associated with the given identifier.Symbol[]
Get all symbols in the table.Symbol[]
Get all symbols in the table which represent data.int
getSize()
Get the count of entries currently in the table.Produce Symbol object from symbol table that corresponds to given String.Symbol[]
Get all symbols in the table which represent text.void
realignSymbols
(int currentAddress, int alignedAddress) void
removeSymbol
(String identifier) Removes a symbol from the Symbol table.
-
Constructor Details
-
SymbolTable
Create a new empty symbol table corresponding to the given filename.- Parameters:
filename
- The name of the file this symbol table is associated with. Will be used only for output/display so it can be any descriptive string.
-
-
Method Details
-
getFilename
-
defineSymbol
Adds a Symbol object into the array of Symbols.- Parameters:
identifier
- The identifier representing the Symbol.address
- The address of the Symbol.isData
- The type of Symbol, true for data, false for text.
-
defineSymbol
Adds a Symbol object into the array of Symbols.- Parameters:
symbol
- The symbol to add.
-
removeSymbol
Removes a symbol from the Symbol table. If not found, it does nothing. This will rarely happen (only when variable is declared .globl after already being defined in the local symbol table).- Parameters:
identifier
- The identifier for the symbol to remove.
-
getAddress
Get the address associated with the given identifier.- Parameters:
identifier
- The identifier to search for.- Returns:
- The memory address of the identifier given, or
null
if not found in symbol table.
-
getSymbol
Produce Symbol object from symbol table that corresponds to given String.- Parameters:
identifier
- The identifier to search for.- Returns:
- Symbol object for requested target, null if not found in symbol table.
-
getDataSymbols
Get all symbols in the table which represent data.- Returns:
- Array of data symbols.
-
getTextSymbols
Get all symbols in the table which represent text.- Returns:
- Array of text symbols.
-
getAllSymbols
Get all symbols in the table.- Returns:
- Array of symbols.
-
getSize
public int getSize()Get the count of entries currently in the table.- Returns:
- Number of symbol table entries.
-
clear
public void clear()Clear all symbols from the table. -
realignSymbols
public void realignSymbols(int currentAddress, int alignedAddress)
-