Package mars
Class MIPSprogram
java.lang.Object
mars.MIPSprogram
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.
- Version:
- August 2003
- Author:
- Pete Sanderson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassemble(ArrayList<MIPSprogram> MIPSprogramsToAssemble, boolean extendedAssemblerEnabled)
Assembles the MIPS source program.assemble(ArrayList<MIPSprogram> MIPSprogramsToAssemble, boolean extendedAssemblerEnabled, boolean warningsAreErrors)
Assembles the MIPS source program.boolean
Returns status of BackStepper associated with this program.Instantiates a newMacroPool
and sends reference of thisMIPSprogram
to itProduces new empty list to hold parsed source code statements.Returns BackStepper associated with this program.Produces name of associated source code file.Gets local macro poolMacroPool
for this programReturns SymbolTable associated with this program.Produces list of machine statements that are assembled from the program.Produces existing list of parsed source code statements.getSourceLine(int i)
Produces specified line of MIPS source program.Retrieve list of source statements that comprise the program.Produces list of source statements that comprise the program.Retrieves Tokenizer for this programProduces list of tokens that comprise the program.boolean
Will be true only while in process of simulating a program statement in step mode (e.g. returning to GUI after each step).prepareFilesForAssembly(ArrayList<String> filenames, String leadFilename, String exceptionHandler)
Prepares the given list of files for assembly.void
readSource(String file)
Reads MIPS source code from file into structure.void
setLocalMacroPool(MacroPool macroPool)
Sets local macro poolMacroPool
for this programvoid
setSourceLineList(ArrayList<SourceLine> sourceLineList)
Set list of source statements that comprise the program.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, AbstractAction a)
Simulates execution of the MIPS program.boolean
Simulates execution of the MIPS program.void
tokenize()
Tokenizes the MIPS source program.
-
Constructor Details
-
MIPSprogram
public MIPSprogram()
-
-
Method Details
-
getSourceList
Produces list of source statements that comprise the program.- Returns:
- ArrayList of String. Each String is one line of MIPS source code.
-
setSourceLineList
Set list of source statements that comprise the program.- Parameters:
sourceLineList
- ArrayList of SourceLine. Each SourceLine represents one line of MIPS source code.
-
getSourceLineList
Retrieve list of source statements that comprise the program.- Returns:
- ArrayList of SourceLine. Each SourceLine represents one line of MIPS source cod
-
getFilename
Produces name of associated source code file.- Returns:
- File name as String.
-
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
-
getTokenizer
Retrieves Tokenizer for this program- Returns:
- Tokenizer
-
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
Produces existing list of parsed source code statements.- Returns:
- ArrayList of ProgramStatement. Each ProgramStatement represents a parsed MIPS statement.
- See Also:
ProgramStatement
-
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
Returns BackStepper associated with this program. It is created upon successful assembly.- Returns:
- BackStepper object, null if there is none.
-
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
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
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
Tokenizes the MIPS source program. Program must have already been read from file.- Throws:
ProcessingException
- Will throw exception if errors occurred while tokenizing.
-
prepareFilesForAssembly
public ArrayList<MIPSprogram> prepareFilesForAssembly(ArrayList<String> filenames, String leadFilename, String exceptionHandler) throws ProcessingExceptionPrepares 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 orderleadFilename
- 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 occurred while reading or tokenizing.
-
assemble
public ErrorList assemble(ArrayList<MIPSprogram> MIPSprogramsToAssemble, boolean extendedAssemblerEnabled) throws ProcessingExceptionAssembles the MIPS source program. All files comprising the program must have already been tokenized. Assembler warnings are not considered errors.- 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 occurred while assembling.
-
assemble
public ErrorList assemble(ArrayList<MIPSprogram> MIPSprogramsToAssemble, boolean extendedAssemblerEnabled, boolean warningsAreErrors) throws ProcessingExceptionAssembles 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 errorswarningsAreErrors
- A boolean value - true means assembler warnings will be considered errors and terminate the assemble; false means the assembler will produce warning message but otherwise ignore warnings.- Returns:
- ErrorList containing nothing or only warnings (otherwise would have thrown exception).
- Throws:
ProcessingException
- Will throw exception if errors occurred while assembling.
-
simulate
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 occurred while simulating.
-
simulate
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 occurred while simulating.
-
simulateFromPC
public boolean simulateFromPC(int[] breakPoints, int maxSteps, AbstractAction a) throws ProcessingExceptionSimulates 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 occurred while simulating.
-
simulateStepAtPC
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 occurred 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). -
createMacroPool
Instantiates a newMacroPool
and sends reference of thisMIPSprogram
to it- Returns:
- instantiated MacroPool
-
getLocalMacroPool
Gets local macro poolMacroPool
for this program- Returns:
- MacroPool
-
setLocalMacroPool
Sets local macro poolMacroPool
for this program- Parameters:
macroPool
- reference to MacroPool
-