Package mars.assembler
Class SymbolTable
java.lang.Object
mars.assembler.SymbolTable
Creates a table of Symbol objects.
- Version:
- June 2003
- Author:
- Jason Bumgarner, Jason Shrewsbury
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSymbolTable(String filename)
Create a new empty symbol table for given file -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a Symbol object into the array of Symbols.void
clear()
Creates a fresh arrayList for a new table.void
fixSymbolTableAddress(int originalAddress, int replacementAddress)
Fix address in symbol table entry.int
getAddress(String s)
Method to return the address associated with the given label.int
Method to return the address associated with the given label.For obtaining all the Symbols.For obtaining the Data Symbols.int
getSize()
Get the count of entries currently in the table.static String
Fetches the text segment label (symbol) which, if declared global, indicates the starting address for execution.Produce Symbol object from symbol table that corresponds to given String.Produce Symbol object from symbol table that has the given address.Produce Symbol object from either local or global symbol table that has the given address.For obtaining the Text Symbols.void
removeSymbol(Token token)
Removes a symbol from the Symbol table.
-
Field Details
-
NOT_FOUND
public static final int NOT_FOUND- See Also:
- Constant Field Values
-
-
Constructor Details
-
SymbolTable
Create a new empty symbol table for given file- Parameters:
filename
- name of file this symbol table is associated with. Will be used only for output/display so it can be any descriptive string.
-
-
Method Details
-
addSymbol
Adds a Symbol object into the array of Symbols.- Parameters:
token
- The token representing the Symbol.address
- The address of the Symbol.b
- The type of Symbol, true for data, false for text.errors
- List to which to add any processing errors that occur.
-
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:
token
- The token representing the Symbol.
-
getAddress
Method to return the address associated with the given label.- Parameters:
s
- The label.- Returns:
- The memory address of the label given, or NOT_FOUND if not found in symbol table.
-
getAddressLocalOrGlobal
Method to return the address associated with the given label. Look first in this (local) symbol table then in symbol table of labels declared global (.globl directive).- Parameters:
s
- The label.- Returns:
- The memory address of the label given, or NOT_FOUND if not found in symbol table.
-
getSymbol
Produce Symbol object from symbol table that corresponds to given String.- Parameters:
s
- target String- Returns:
- Symbol object for requested target, null if not found in symbol table.
-
getSymbolGivenAddress
Produce Symbol object from symbol table that has the given address.- Parameters:
s
- String representing address- Returns:
- Symbol object having requested address, null if address not found in symbol table.
-
getSymbolGivenAddressLocalOrGlobal
Produce Symbol object from either local or global symbol table that has the given address.- Parameters:
s
- String representing address- Returns:
- Symbol object having requested address, null if address not found in symbol table.
-
getDataSymbols
For obtaining the Data Symbols.- Returns:
- An ArrayList of Symbol objects.
-
getTextSymbols
For obtaining the Text Symbols.- Returns:
- An ArrayList of Symbol objects.
-
getAllSymbols
For obtaining all the Symbols.- Returns:
- An ArrayList of Symbol objects.
-
getSize
public int getSize()Get the count of entries currently in the table.- Returns:
- Number of symbol table entries.
-
clear
public void clear()Creates a fresh arrayList for a new table. -
fixSymbolTableAddress
public void fixSymbolTableAddress(int originalAddress, int replacementAddress)Fix address in symbol table entry. Any and all entries that match the original address will be modified to contain the replacement address. There is no effect, if none of the addresses matches.- Parameters:
originalAddress
- Address associated with 0 or more symtab entries.replacementAddress
- Any entry that has originalAddress will have its address updated to this value. Does nothing if none do.
-
getStartLabel
Fetches the text segment label (symbol) which, if declared global, indicates the starting address for execution.- Returns:
- String containing global label whose text segment address is starting address for program execution.
-