mars
Class MIPSprogram

java.lang.Object
  |
  +--mars.MIPSprogram

public class MIPSprogram
extends java.lang.Object

Internal representations of MIPS program. Connects source, tokens and machine code. Having all these structures available facilitates construction of good messages, debugging, and easy simulation.


Constructor Summary
MIPSprogram()
           
 
Method Summary
 ErrorList assemble(java.util.ArrayList MIPSprogramsToAssemble, boolean extendedAssemblerEnabled)
          Assembles the MIPS source program.
 boolean backSteppingEnabled()
          Returns status of BackStepper associated with this program.
 java.util.ArrayList createParsedList()
          Produces new empty list to hold parsed source code statements.
 BackStepper getBackStepper()
          Returns BackStepper associated with this program.
 java.lang.String getFilename()
          Produces name of associated source code file.
 SymbolTable getLocalSymbolTable()
          Returns SymbolTable associated with this program.
 java.util.ArrayList getMachineList()
          Produces list of machine statements that are assembled from the program.
 java.util.ArrayList getParsedList()
          Produces existing list of parsed source code statements.
 java.lang.String getSourceLine(int i)
          Produces specified line of MIPS source program.
 java.util.ArrayList getSourceList()
          Produces list of source statements that comprise the program.
 java.util.ArrayList getTokenList()
          Produces list of tokens that comprise the program.
 boolean inSteppedExecution()
          Will be true only while in process of simulating a program statement in step mode (e.g.
 java.util.ArrayList prepareFilesForAssembly(java.util.ArrayList filenames, java.lang.String leadFilename, java.lang.String exceptionHandler)
          Prepares the given list of files for assembly.
 void readSource(java.lang.String file)
          Reads MIPS source code from file into structure.
 boolean simulate(int maxSteps)
          Simulates execution of the MIPS program.
 boolean simulate(int[] breakPoints)
          Simulates execution of the MIPS program.
 boolean simulateFromPC(int[] breakPoints, int maxSteps, javax.swing.AbstractAction a)
          Simulates execution of the MIPS program.
 boolean simulateStepAtPC(javax.swing.AbstractAction a)
          Simulates execution of the MIPS program.
 void tokenize()
          Tokenizes the MIPS source program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MIPSprogram

public MIPSprogram()
Method Detail

getSourceList

public java.util.ArrayList getSourceList()
Produces list of source statements that comprise the program.

Returns:
ArrayList of String. Each String is one line of MIPS source code.

getFilename

public java.lang.String getFilename()
Produces name of associated source code file.

Returns:
File name as String.

getTokenList

public java.util.ArrayList getTokenList()
Produces list of tokens that comprise the program.

Returns:
ArrayList of TokenList. Each TokenList is list of tokens generated by corresponding line of MIPS source code.
See Also:
TokenList

createParsedList

public java.util.ArrayList createParsedList()
Produces new empty list to hold parsed source code statements.

Returns:
ArrayList of ProgramStatement. Each ProgramStatement represents a parsed MIPS statement.
See Also:
ProgramStatement

getParsedList

public java.util.ArrayList getParsedList()
Produces existing list of parsed source code statements.

Returns:
ArrayList of ProgramStatement. Each ProgramStatement represents a parsed MIPS statement.
See Also:
ProgramStatement

getMachineList

public java.util.ArrayList getMachineList()
Produces list of machine statements that are assembled from the program.

Returns:
ArrayList of ProgramStatement. Each ProgramStatement represents an assembled basic MIPS instruction.
See Also:
ProgramStatement

getBackStepper

public BackStepper getBackStepper()
Returns BackStepper associated with this program. It is created upon successful assembly.

Returns:
BackStepper object, null if there is none.

getLocalSymbolTable

public SymbolTable getLocalSymbolTable()
Returns SymbolTable associated with this program. It is created at assembly time, and stores local labels (those not declared using .globl directive).


backSteppingEnabled

public boolean backSteppingEnabled()
Returns status of BackStepper associated with this program.

Returns:
true if enabled, false if disabled or non-existant.

getSourceLine

public java.lang.String getSourceLine(int i)
Produces specified line of MIPS source program.

Parameters:
i - Line number of MIPS source program to get. Line 1 is first line.
Returns:
Returns specified line of MIPS source. If outside the line range, it returns null. Line 1 is first line.

readSource

public void readSource(java.lang.String file)
                throws ProcessingException
Reads MIPS source code from file into structure. Will always read from file. It is GUI responsibility to assure that source edits are written to file when user selects compile or run/step options.

Parameters:
file - String containing name of MIPS source code file.
Throws:
ProcessingException - Will throw exception if there is any problem reading the file.

tokenize

public void tokenize()
              throws ProcessingException
Tokenizes the MIPS source program. Program must have already been read from file.

Throws:
ProcessingException - Will throw exception if errors occured while tokenizing.

prepareFilesForAssembly

public java.util.ArrayList prepareFilesForAssembly(java.util.ArrayList filenames,
                                                   java.lang.String leadFilename,
                                                   java.lang.String exceptionHandler)
                                            throws ProcessingException
Prepares the given list of files for assembly. This involves reading and tokenizing all the source files. There may be only one.

Parameters:
filenames - ArrayList containing the source file name(s) in no particular order
leadFilename - String containing name of source file that needs to go first and will be represented by "this" MIPSprogram object.
exceptionHandler - String containing name of source file containing exception handler. This will be assembled first, even ahead of leadFilename, to allow it to include "startup" instructions loaded beginning at 0x00400000. Specify null or empty String to indicate there is no such designated exception handler.
Returns:
ArrayList containing one MIPSprogram object for each file to assemble. objects for any additional files (send ArrayList to assembler)
Throws:
ProcessingException - Will throw exception if errors occured while reading or tokenizing.

assemble

public ErrorList assemble(java.util.ArrayList MIPSprogramsToAssemble,
                          boolean extendedAssemblerEnabled)
                   throws ProcessingException
Assembles the MIPS source program. All files comprising the program must have already been tokenized.

Parameters:
MIPSprogramsToAssemble - ArrayList of MIPSprogram objects, each representing a tokenized source file.
extendedAssemblerEnabled - A boolean value - true means extended (pseudo) instructions are permitted in source code and false means they are to be flagged as errors.
Returns:
ErrorList containing nothing or only warnings (otherwise would have thrown exception).
Throws:
ProcessingException - Will throw exception if errors occured while assembling.

simulate

public boolean simulate(int[] breakPoints)
                 throws ProcessingException
Simulates execution of the MIPS program. Program must have already been assembled. Begins simulation at beginning of text segment and continues to completion.

Parameters:
breakPoints - int array of breakpoints (PC addresses). Can be null.
Returns:
true if execution completed and false otherwise
Throws:
ProcessingException - Will throw exception if errors occured while simulating.

simulate

public boolean simulate(int maxSteps)
                 throws ProcessingException
Simulates execution of the MIPS program. Program must have already been assembled. Begins simulation at beginning of text segment and continues to completion or until the specified maximum number of steps are simulated.

Parameters:
maxSteps - maximum number of steps to simulate.
Returns:
true if execution completed and false otherwise
Throws:
ProcessingException - Will throw exception if errors occured while simulating.

simulateFromPC

public boolean simulateFromPC(int[] breakPoints,
                              int maxSteps,
                              javax.swing.AbstractAction a)
                       throws ProcessingException
Simulates execution of the MIPS program. Program must have already been assembled. Begins simulation at current program counter address and continues until stopped, paused, maximum steps exceeded, or exception occurs.

Parameters:
breakPoints - int array of breakpoints (PC addresses). Can be null.
maxSteps - maximum number of instruction executions. Default -1 means no maximum.
a - the GUI component responsible for this call (GO normally). set to null if none.
Returns:
true if execution completed and false otherwise
Throws:
ProcessingException - Will throw exception if errors occured while simulating.

simulateStepAtPC

public boolean simulateStepAtPC(javax.swing.AbstractAction a)
                         throws ProcessingException
Simulates execution of the MIPS program. Program must have already been assembled. Begins simulation at current program counter address and executes one step.

Parameters:
a - the GUI component responsible for this call (STEP normally). Set to null if none.
Returns:
true if execution completed and false otherwise
Throws:
ProcessingException - Will throw exception if errors occured while simulating.

inSteppedExecution

public boolean inSteppedExecution()
Will be true only while in process of simulating a program statement in step mode (e.g. returning to GUI after each step). This is used to prevent spurious AccessNotices from being sent from Memory and Register to observers at other times (e.g. while updating the data and register displays, while assembling program's data segment, etc).