public class MARSSimulator
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MARSSimulator.DuplicateLabelException
Exception raised when attempting to create a label when a label of the same name already exists.
|
static class |
MARSSimulator.InvalidRegisterException
Exception thrown if invalid register number is given.
|
static class |
MARSSimulator.LabelNotFoundException
Exception thrown if user specifies a label that does not exist
|
static class |
MARSSimulator.LabelTypeException
Exception raised when a label is of the wrong type.
|
static class |
MARSSimulator.MUNITAddressErrorException
Exception raised when requesting an invalid memory address.
|
static class |
MARSSimulator.MUNITProcessingException
Exception raised when the MARS simulator raises a
ProcessingException while simulating assembly code. |
static class |
MARSSimulator.NullLabelException
Exception raised when passing
null as a label. |
static class |
MARSSimulator.SymbolType
Identifies Symbol as a label in either the .text section or the .data section.
|
| Constructor and Description |
|---|
MARSSimulator()
Constructor.
|
MARSSimulator(boolean initializeGlobals)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addData(java.lang.String toAdd)
Add a line to the program's
.data section |
mars.ErrorList |
assemble()
Assemble the set of loaded assembly files.
|
int |
get(int r_num)
Returns the value of a register.
|
double |
get(MUnit.DoubleRegister reg)
Returns the value of a double register
|
float |
get(MUnit.FloatRegister reg)
Returns the value of a float register
|
byte[] |
getBytes(int address,
int num_bytes)
Return the bytes at the specified memory locations.
|
byte[] |
getBytes(java.lang.String label,
int offset,
int num_bytes)
Return the bytes at the specified memory locations.
|
double[] |
getDoubles(int address,
int num_doubles)
Return the doubles at the specified memory locations.
|
double[] |
getDoubles(java.lang.String label,
int offset,
int num_doubles)
Return the doubles at the specified memory locations.
|
float[] |
getFloats(int address,
int num_floats)
Return the floats at the specified memory locations.
|
float[] |
getFloats(java.lang.String label,
int offset,
int num_floats)
Return the floats at the specified memory locations.
|
short[] |
getHalfwords(int address,
int num_halfwords)
Return the halfwords at the specified memory locations.
|
short[] |
getHalfwords(java.lang.String label,
int offset,
int num_halfwords)
Return the halfwords at the specified memory locations.
|
mars.assembler.Symbol |
getSymbolFromCurrentProgram(java.lang.String symbol)
Get a Symbol for a label from the current program's symbol table.
|
int[] |
getWords(int address,
int num_words)
Return the words at the specified memory locations
|
int[] |
getWords(java.lang.String label,
int offset,
int num_words)
Return the words at the specified memory locations
|
void |
load(mars.MIPSprogram p)
Add
p to the list of programs under test. |
void |
load(java.lang.String filename)
Adds a file to the the list of files to be loaded before execution (i.e., the set of assembly files under test).
|
boolean |
noOtherMemoryModifications()
Return
true if all modified memory locations have been returned through a "get..." call. |
boolean |
noOtherNonStackModifications(int stackMax)
Return
true if all modified non-stack memory locations have been returned through a
"get..." call. |
boolean |
noOtherStaticDataMemoryModifications()
Return
true if all modified static data memory locations have been returned through a
"get..." call. |
int |
run(java.lang.String label)
Run the function under test
|
void |
set(int r_num,
int value)
Sets a register to the supplied value
|
void |
set(int r_num,
java.lang.String value,
boolean verify)
Sets a register to the supplied label.
|
void |
set(MUnit.DoubleRegister reg,
double value)
Sets a double register to the supplied value
|
void |
set(MUnit.FloatRegister reg,
float value)
Sets a float register to the supplied value
|
void |
setAssemblyFiles(java.util.ArrayList<mars.MIPSprogram> assemblyFiles) |
static MARSSimulator |
singleton()
Return the singleton
MARSSimulator object |
public MARSSimulator(boolean initializeGlobals)
initializeGlobals - true to call Mars's Globals.initialize() method.java.lang.IllegalStateException - if the singleton object has already been created.public MARSSimulator()
java.lang.IllegalStateException - if the singleton object has already been created.public void setAssemblyFiles(java.util.ArrayList<mars.MIPSprogram> assemblyFiles)
public static MARSSimulator singleton()
MARSSimulator objectMARSSimulator objectpublic mars.assembler.Symbol getSymbolFromCurrentProgram(java.lang.String symbol)
symbol - the symbol to getSymbol, or {code null} if the label is not found (or if st is null).public void load(java.lang.String filename)
throws mars.ProcessingException
filename - name of file to be loaded.mars.ProcessingException - if the file can't be tokenized.public void load(mars.MIPSprogram p)
p to the list of programs under test. (This method is used to attach this
object to the program currently being run in the MARS simulator.)p - the MIPSprogram to add.public mars.ErrorList assemble()
throws mars.ProcessingException
mars.ProcessingException - if the assembly code contains errors.public void set(int r_num,
int value)
r_num - Register to be set.value - Integer value to set the register to.public void set(int r_num,
java.lang.String value,
boolean verify)
String value can come from two places:
It can be a label in the code under test, in which case verify should be true (to be sure it is in the
symbol table). value can also come from a MUnit.Label, in which case verify should be false
(The symbol behind the Label doesn't get added to the symbol table until run(java.lang.String) is called. Thus,
the verification will fail.)r_num - Register to be set.value - Label to set the register to.verify - verify that value appears in the symbol table.public void set(MUnit.DoubleRegister reg, double value)
reg - the double register to be setvalue - the valuepublic void set(MUnit.FloatRegister reg, float value)
reg - the float register to be setvalue - the valuepublic void addData(java.lang.String toAdd)
.data sectiontoAdd - The line to add.public int get(int r_num)
r_num - The register to be returned.public double get(MUnit.DoubleRegister reg)
reg - the registerpublic float get(MUnit.FloatRegister reg)
reg - the registerpublic int[] getWords(int address,
int num_words)
throws MARSSimulator.MUNITAddressErrorException
address - the base address of the words to loadnum_words - number of words to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public int[] getWords(java.lang.String label,
int offset,
int num_words)
throws MARSSimulator.MUNITAddressErrorException
label - data label in memoryoffset - byte offset to the data labelnum_words - number of words to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public short[] getHalfwords(java.lang.String label,
int offset,
int num_halfwords)
label - data label in memoryoffset - byte offset to the data labelnum_halfwords - number of bytes to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public short[] getHalfwords(int address,
int num_halfwords)
address - the address of the datanum_halfwords - number of bytes to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.public byte[] getBytes(java.lang.String label,
int offset,
int num_bytes)
label - data label in memoryoffset - byte offset to the data labelnum_bytes - number of halfwords to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public byte[] getBytes(int address,
int num_bytes)
address - the address of the desired datanum_bytes - number of halfwords to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public double[] getDoubles(java.lang.String label,
int offset,
int num_doubles)
label - data label in memoryoffset - byte offset to the data labelnum_doubles - number of doubles to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public double[] getDoubles(int address,
int num_doubles)
address - the address of the desired datanum_doubles - number of doubles to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public float[] getFloats(java.lang.String label,
int offset,
int num_floats)
label - data label in memoryoffset - byte offset to the data labelnum_floats - number of floats to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.MARSSimulator.LabelNotFoundException - if label isn't found.public float[] getFloats(int address,
int num_floats)
address - the address of the desired datanum_floats - number of floats to returnMARSSimulator.MUNITAddressErrorException - if the address isn't valid.public boolean noOtherMemoryModifications()
true if all modified memory locations have been returned through a "get..." call.
(In other words, return true if the test writer has inspected all the memory values that have changed.)true if all modified memory locations have been returned through a "get..." call.public boolean noOtherStaticDataMemoryModifications()
true if all modified static data memory locations have been returned through a
"get..." call.
(In other words, return true if the test writer has inspected all the static data memory values that have
changed.) The "static data" memory area typically runs from 0x1000_0000 through 0x1000_40000. The heap
typically begins at 0x1004_0000. This method does not verify whether heap changes or stack changes have been
inspected.true if all modified static data memory locations have been returned through a "get..."
call.public boolean noOtherNonStackModifications(int stackMax)
true if all modified non-stack memory locations have been returned through a
"get..." call.
(In other words, return true if the test writer has inspected all the memory values that have
changed -- except for those on the stack.) For purposes of this check, the stack is assumed to be at most
stackMax bytes. Thus,
0x0x7fff_effc - stackMax is checked.
(0x0x7fff_effc is the default starting value of the stack.)stackMax bytes on the stack.stackMax - the assumed maximum size of the stack.true if all modified non-stack memory locations have been returned through a "get..." call.public int run(java.lang.String label)
label - the function under test