Class SymbolTable

java.lang.Object
mars.assembler.SymbolTable

public class SymbolTable extends Object
A symbol table used by the assembler to map symbols to the corresponding addresses.
Author:
Jason Bumgarner & Jason Shrewsbury, June 2003
  • Constructor Details

    • SymbolTable

      public SymbolTable(String filename)
      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

      public String getFilename()
    • defineSymbol

      public Symbol defineSymbol(String identifier, int address, boolean isData)
      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

      public Symbol defineSymbol(Symbol symbol)
      Adds a Symbol object into the array of Symbols.
      Parameters:
      symbol - The symbol to add.
    • removeSymbol

      public void removeSymbol(String identifier)
      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

      public Integer getAddress(String identifier)
      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

      public Symbol getSymbol(String identifier)
      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

      public Symbol[] getDataSymbols()
      Get all symbols in the table which represent data.
      Returns:
      Array of data symbols.
    • getTextSymbols

      public Symbol[] getTextSymbols()
      Get all symbols in the table which represent text.
      Returns:
      Array of text symbols.
    • getAllSymbols

      public Symbol[] 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)