[O] Refactor

This commit is contained in:
Azalea
2022-11-09 23:41:40 -05:00
parent 380de99170
commit 13c408bbdd
417 changed files with 5494 additions and 5561 deletions
-1
View File
@@ -1 +0,0 @@
jar cmf mainclass.txt Mars.jar PseudoOps.txt Config.properties Syscall.properties Settings.properties MARSlicense.txt mainclass.txt MipsXRayOpcode.xml registerDatapath.xml controlDatapath.xml ALUcontrolDatapath.xml CreateMarsJar.bat CreateMarsJar.sh Mars.java Mars.class docs help images mars
-2
View File
@@ -1,2 +0,0 @@
# If you can't generate due of permissions, do a "chmod +x CreateMarsJar.sh".
jar cmf mainclass.txt Mars.jar PseudoOps.txt Config.properties Syscall.properties Settings.properties MARSlicense.txt mainclass.txt MipsXRayOpcode.xml registerDatapath.xml controlDatapath.xml ALUcontrolDatapath.xml CreateMarsJar.bat CreateMarsJar.sh Mars.java Mars.class docs help images mars
+1 -10
View File
@@ -1,12 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.5.1/userguide/building_java_projects.html
* This project uses @Incubating APIs which are subject to change.
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
@@ -34,5 +25,5 @@ testing {
application {
// Define the main class for the application.
mainClass = 'mars.assembler.App'
mainClass = 'Mars'
}
+17
View File
@@ -0,0 +1,17 @@
import os
from pathlib import Path
from subprocess import check_output
if __name__ == '__main__':
java = Path('src/main/java')
files = [Path(root) / f for root, dir, files in os.walk(java) for f in files]
for f in files:
ftype = check_output(f'file {f}', shell=True).decode()
if '8859' not in ftype:
continue
print(f'Converting {f} to UTF-8...')
f.write_text(f.read_text('ISO-8859-1'), 'utf8')
# print(files)
+1 -11
View File
@@ -1,11 +1 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.5.1/userguide/multi_project_builds.html
* This project uses @Incubating APIs which are subject to change.
*/
rootProject.name = 'MARS-Assembler'
rootProject.name = 'MARS'
+2 -3
View File
@@ -1,4 +1,3 @@
/*
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
@@ -34,9 +33,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @version March 2006
**/
public class Mars {
public class Mars {
public static void main(String[] args) {
new mars.MarsLaunch(args);
}
}
}
-2
View File
@@ -1,2 +0,0 @@
Main-Class: Mars
Class-Path: .
+109 -63
View File
@@ -1,12 +1,16 @@
package mars;
import mars.mips.instructions.syscalls.*;
import mars.mips.instructions.*;
import mars.mips.hardware.*;
import mars.assembler.*;
import mars.venus.*;
import mars.util.*;
import java.io.*;
import java.util.*;
package mars;
import mars.assembler.SymbolTable;
import mars.mips.hardware.Memory;
import mars.mips.instructions.InstructionSet;
import mars.mips.instructions.syscalls.SyscallNumberOverride;
import mars.util.PropertiesFile;
import mars.venus.VenusUI;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import java.util.StringTokenizer;
/*
Copyright (c) 2003-2008, Pete Sanderson and Kenneth Vollmar
@@ -42,74 +46,113 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @author Pete Sanderson
* @version August 2003
*/
public class Globals
{
// List these first because they are referenced by methods called at initialization.
private static String configPropertiesFile = "Config";
private static String syscallPropertiesFile = "Syscall";
/** The set of implemented MIPS instructions. **/
public static InstructionSet instructionSet;
/** the program currently being worked with. Used by GUI only, not command line. **/
public static MIPSprogram program;
/** Symbol table for file currently being assembled. **/
public static SymbolTable symbolTable;
/** Simulated MIPS memory component. **/
public static Memory memory;
/** Lock variable used at head of synchronized block to guard MIPS memory and registers **/
public static Object memoryAndRegistersLock = new Object();
/** Flag to determine whether or not to produce internal debugging information. **/
public static boolean debug = false;
/** Object that contains various settings that can be accessed modified internally. **/
static Settings settings;
/** String to GUI's RunI/O text area when echoing user input from pop-up dialog. */
public static String userInputAlert = "**** user input : ";
/** Path to folder that contains images */
public class Globals {
/**
* Path to folder that contains images
*/
// The leading "/" in filepath prevents package name from being pre-pended.
public static final String imagesPath = "/images/";
/** Path to folder that contains help text */
/**
* Path to folder that contains help text
*/
public static final String helpPath = "/help/";
/* Flag that indicates whether or not instructionSet has been initialized. */
private static boolean initialized = false;
/**
* The current MARS version number. Can't wait for "initialize()" call to get it.
*/
public static final String version = "4.5";
/**
* MARS copyright years
*/
public static final String copyrightYears = getCopyrightYears();
/**
* MARS copyright holders
*/
public static final String copyrightHolders = getCopyrightHolders();
/**
* The set of implemented MIPS instructions.
**/
public static InstructionSet instructionSet;
/**
* the program currently being worked with. Used by GUI only, not command line.
**/
public static MIPSprogram program;
/**
* Symbol table for file currently being assembled.
**/
public static SymbolTable symbolTable;
/**
* Simulated MIPS memory component.
**/
public static Memory memory;
/**
* Lock variable used at head of synchronized block to guard MIPS memory and registers
**/
public static Object memoryAndRegistersLock = new Object();
/**
* Flag to determine whether or not to produce internal debugging information.
**/
public static boolean debug = false;
/**
* String to GUI's RunI/O text area when echoing user input from pop-up dialog.
*/
public static String userInputAlert = "**** user input : ";
/**
* MARS exit code -- useful with SYSCALL 17 when running from command line (not GUI)
*/
public static int exitCode = 0;
public static boolean runSpeedPanelExists = false;
/**
* Object that contains various settings that can be accessed modified internally.
**/
static Settings settings;
/* The GUI being used (if any) with this simulator. */
static VenusUI gui = null;
/** The current MARS version number. Can't wait for "initialize()" call to get it. */
public static final String version = "4.5";
/** List of accepted file extensions for MIPS assembly source files. */
// List these first because they are referenced by methods called at initialization.
private static final String configPropertiesFile = "Config";
/**
* List of accepted file extensions for MIPS assembly source files.
*/
public static final ArrayList fileExtensions = getFileExtensions();
/** Maximum length of scrolled message window (MARS Messages and Run I/O) */
/**
* Maximum length of scrolled message window (MARS Messages and Run I/O)
*/
public static final int maximumMessageCharacters = getMessageLimit();
/** Maximum number of assembler errors produced by one assemble operation */
/**
* Maximum number of assembler errors produced by one assemble operation
*/
public static final int maximumErrorMessages = getErrorLimit();
/** Maximum number of back-step operations to buffer */
/**
* Maximum number of back-step operations to buffer
*/
public static final int maximumBacksteps = getBackstepLimit();
/** MARS copyright years */
public static final String copyrightYears = getCopyrightYears();
/** MARS copyright holders */
public static final String copyrightHolders = getCopyrightHolders();
/** Placeholder for non-printable ASCII codes */
/**
* Placeholder for non-printable ASCII codes
*/
public static final String ASCII_NON_PRINT = getAsciiNonPrint();
/** Array of strings to display for ASCII codes in ASCII display of data segment. ASCII code 0-255 is array index. */
/**
* Array of strings to display for ASCII codes in ASCII display of data segment. ASCII code 0-255 is array index.
*/
public static final String[] ASCII_TABLE = getAsciiStrings();
/** MARS exit code -- useful with SYSCALL 17 when running from command line (not GUI) */
public static int exitCode = 0;
public static boolean runSpeedPanelExists = false;
private static final String syscallPropertiesFile = "Syscall";
/* Flag that indicates whether or not instructionSet has been initialized. */
private static boolean initialized = false;
private static String getCopyrightYears() {
return "2003-2014";
}
private static String getCopyrightHolders() {
return "Pete Sanderson and Kenneth Vollmar";
}
public static void setGui(VenusUI g) {
gui = g;
}
public static VenusUI getGui() {
return gui;
}
public static void setGui(VenusUI g) {
gui = g;
}
public static Settings getSettings() {
return settings;
}
@@ -149,14 +192,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Read ASCII default display character for non-printing characters, from properties file.
public static String getAsciiNonPrint() {
String anp = getPropertyEntry(configPropertiesFile, "AsciiNonPrint");
return (anp == null) ? "." : ( (anp.equals("space")) ? " " : anp );
return (anp == null) ? "." : ((anp.equals("space")) ? " " : anp);
}
// Read ASCII strings for codes 0-255, from properties file. If string
// value is "null", substitute value of ASCII_NON_PRINT. If string is
// "space", substitute string containing one space character.
public static String[] getAsciiStrings() {
String let = getPropertyEntry(configPropertiesFile,"AsciiTable");
String let = getPropertyEntry(configPropertiesFile, "AsciiTable");
String placeHolder = getAsciiNonPrint();
String[] lets = let.split(" +");
int maxLength = 0;
@@ -168,7 +211,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
String padding = " ";
maxLength++;
for (int i = 0; i < lets.length; i++) {
lets[i] = padding.substring(0,maxLength-lets[i].length()) + lets[i];
lets[i] = padding.substring(0, maxLength - lets[i].length()) + lets[i];
}
return lets;
}
@@ -180,8 +223,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Properties properties = PropertiesFile.loadPropertiesFromFile(propertiesFile);
try {
limit = Integer.parseInt(properties.getProperty(propertyName, Integer.toString(defaultValue)));
}
catch (NumberFormatException nfe) { } // do nothing, I already have a default
} catch (NumberFormatException nfe) {
} // do nothing, I already have a default
return limit;
}
@@ -190,7 +233,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// string is tokenized into array list (assume StringTokenizer default delimiters).
private static ArrayList getFileExtensions() {
ArrayList extensionsList = new ArrayList();
String extensions = getPropertyEntry(configPropertiesFile,"Extensions");
String extensions = getPropertyEntry(configPropertiesFile, "Extensions");
if (extensions != null) {
StringTokenizer st = new StringTokenizer(extensions);
while (st.hasMoreTokens()) {
@@ -204,13 +247,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Get list of MarsTools that reside outside the MARS distribution.
* Currently this is done by adding the tool's path name to the list
* of values for the external_tools property. Use ";" as delimiter!
*
* @return ArrayList. Each item is file path to .class file
* of a class that implements MarsTool. If none, returns empty list.
*/
public static ArrayList getExternalTools() {
ArrayList toolsList = new ArrayList();
String delimiter = ";";
String tools = getPropertyEntry(configPropertiesFile,"ExternalTools");
String tools = getPropertyEntry(configPropertiesFile, "ExternalTools");
if (tools != null) {
StringTokenizer st = new StringTokenizer(tools, delimiter);
while (st.hasMoreTokens()) {
@@ -222,6 +266,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Read and return property file value (if any) for requested property.
*
* @param propertiesFile name of properties file (do NOT include filename extension,
* which is assumed to be ".properties")
* @param propertyName String containing desired property name
@@ -233,6 +278,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Read any syscall number assignment overrides from config file.
*
* @return ArrayList of SyscallNumberOverride objects
*/
public ArrayList getSyscallOverrides() {
@@ -241,9 +287,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Enumeration keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
overrides.add(new SyscallNumberOverride(key,properties.getProperty(key)));
overrides.add(new SyscallNumberOverride(key, properties.getProperty(key)));
}
return overrides;
}
}
}
+106 -103
View File
@@ -1,9 +1,11 @@
package mars;
import mars.assembler.*;
import mars.mips.instructions.*;
import mars.mips.hardware.*;
import mars.util.*;
import java.util.*;
package mars;
import mars.assembler.*;
import mars.mips.instructions.*;
import mars.mips.hardware.*;
import mars.util.*;
import java.util.*;
/*
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar
@@ -43,7 +45,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class ProgramStatement {
public class ProgramStatement {
private MIPSprogram sourceMIPSprogram;
private String source, basicAssemblyStatement, machineStatement;
private TokenList originalTokenList, strippedTokenList;
@@ -58,9 +60,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
private static final String invalidOperator = "<INVALID>";
//////////////////////////////////////////////////////////////////////////////////
/**
* Constructor for ProgramStatement when there are links back to all source and token
* information. These can be used by a debugger later on.
*
* @param sourceMIPSprogram The MIPSprogram object that contains this statement
* @param source The corresponding MIPS source statement.
* @param origTokenList Complete list of Token objects (includes labels, comments, parentheses, etc)
@@ -69,8 +73,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @param textAddress The Text Segment address in memory where the binary machine code for this statement
* is stored.
**/
public ProgramStatement(MIPSprogram sourceMIPSprogram, String source, TokenList origTokenList, TokenList strippedTokenList,
Instruction inst, int textAddress, int sourceLine) {
public ProgramStatement(MIPSprogram sourceMIPSprogram, String source, TokenList origTokenList, TokenList strippedTokenList, Instruction inst, int textAddress, int sourceLine) {
this.sourceMIPSprogram = sourceMIPSprogram;
this.source = source;
this.originalTokenList = origTokenList;
@@ -89,12 +92,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//////////////////////////////////////////////////////////////////////////////////
/**
* Constructor for ProgramStatement used only for writing a binary machine
* instruction with no source code to refer back to. Originally supported
* only NOP instruction (all zeroes), but extended in release 4.4 to support
* all basic instructions. This was required for the self-modifying code
* feature.
*
* @param binaryStatement The 32-bit machine code.
* @param textAddress The Text Segment address in memory where the binary machine code for this statement
* is stored.
@@ -110,11 +115,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if (instr == null) {
this.operands = null;
this.numOperands = 0;
this.instruction = (binaryStatement==0) // this is a "nop" statement
? (Instruction) Globals.instructionSet.matchOperator("nop").get(0)
: null;
}
else {
this.instruction = (binaryStatement == 0) // this is a "nop" statement
? (Instruction) Globals.instructionSet.matchOperator("nop").get(0) : null;
} else {
this.operands = new int[4];
this.numOperands = 0;
this.instruction = instr;
@@ -132,8 +135,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int opand = (binaryStatement >> k0) & ((1 << (k1 - k0 + 1)) - 1);
if (instrFormat.equals(BasicInstructionFormat.I_BRANCH_FORMAT) && numOps == 2) {
opand = opand << 16 >> 16;
}
else if (instrFormat.equals(BasicInstructionFormat.J_FORMAT) && numOps == 0) {
} else if (instrFormat.equals(BasicInstructionFormat.J_FORMAT) && numOps == 0) {
opand |= (textAddress >> 2) & 0x3C000000;
}
this.operands[numOps] = opand;
@@ -148,22 +150,25 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/////////////////////////////////////////////////////////////////////////////
/**
* Given specification of BasicInstruction for this operator, build the
* corresponding assembly statement in basic assembly format (e.g. substituting
* register numbers for register names, replacing labels by values).
*
* @param errors The list of assembly errors encountered so far. May add to it here.
**/
public void buildBasicStatementFromBasicInstruction(ErrorList errors) {
Token token = strippedTokenList.get(0);
String basicStatementElement = token.getValue()+" ";;
String basicStatementElement = token.getValue() + " ";
;
String basic = basicStatementElement;
basicStatementList.addString(basicStatementElement); // the operator
TokenTypes tokenType, nextTokenType;
String tokenValue;
int registerNumber;
this.numOperands = 0;
for (int i=1; i<strippedTokenList.size(); i++) {
for (int i = 1; i < strippedTokenList.size(); i++) {
token = strippedTokenList.get(i);
tokenType = token.getType();
tokenValue = token.getValue();
@@ -173,43 +178,38 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
basicStatementList.addString(basicStatementElement);
try {
registerNumber = RegisterFile.getUserRegister(tokenValue).getNumber();
}
catch (Exception e) {
} catch (Exception e) {
// should never happen; should be caught before now...
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(),"invalid register name"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(), "invalid register name"));
return;
}
this.operands[this.numOperands++] = registerNumber;
}
else if (tokenType == TokenTypes.REGISTER_NAME) {
} else if (tokenType == TokenTypes.REGISTER_NAME) {
registerNumber = RegisterFile.getNumber(tokenValue);
basicStatementElement = "$" + registerNumber;
basic += basicStatementElement;
basicStatementList.addString(basicStatementElement);
if (registerNumber < 0) {
// should never happen; should be caught before now...
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(),"invalid register name"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(), "invalid register name"));
return;
}
this.operands[this.numOperands++] = registerNumber;
}
else if (tokenType == TokenTypes.FP_REGISTER_NAME) {
} else if (tokenType == TokenTypes.FP_REGISTER_NAME) {
registerNumber = Coprocessor1.getRegisterNumber(tokenValue);
basicStatementElement = "$f" + registerNumber;
basic += basicStatementElement;
basicStatementList.addString(basicStatementElement);
if (registerNumber < 0) {
// should never happen; should be caught before now...
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(),"invalid FPU register name"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(), "invalid FPU register name"));
return;
}
this.operands[this.numOperands++] = registerNumber;
}
else if (tokenType == TokenTypes.IDENTIFIER) {
} else if (tokenType == TokenTypes.IDENTIFIER) {
int address = this.sourceMIPSprogram.getLocalSymbolTable().getAddressLocalOrGlobal(tokenValue);
if (address == SymbolTable.NOT_FOUND) { // symbol used without being defined
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(),
"Symbol \""+tokenValue+"\" not found in symbol table."));
errors.add(new ErrorMessage(this.sourceMIPSprogram, token.getSourceLine(), token.getStartPos(), "Symbol \"" + tokenValue + "\" not found in symbol table."));
return;
}
boolean absoluteAddress = true; // (used below)
@@ -232,10 +232,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// method. There are some comments there as well.
if (instruction instanceof BasicInstruction) {
BasicInstructionFormat format = ((BasicInstruction)instruction).getInstructionFormat();
BasicInstructionFormat format = ((BasicInstruction) instruction).getInstructionFormat();
if (format == BasicInstructionFormat.I_BRANCH_FORMAT) {
//address = (address - (this.textAddress+((Globals.getSettings().getDelayedBranchingEnabled())? Instruction.INSTRUCTION_LENGTH : 0))) >> 2;
address = (address - (this.textAddress+Instruction.INSTRUCTION_LENGTH)) >> 2;
address = (address - (this.textAddress + Instruction.INSTRUCTION_LENGTH)) >> 2;
absoluteAddress = false;
}
}
@@ -243,14 +243,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
basic += address;
if (absoluteAddress) { // record as address if absolute, value if relative
basicStatementList.addAddress(address);
}
else {
} else {
basicStatementList.addValue(address);
}
this.operands[this.numOperands++] = address;
}
else if (tokenType == TokenTypes.INTEGER_5 || tokenType == TokenTypes.INTEGER_16 ||
tokenType == TokenTypes.INTEGER_16U || tokenType == TokenTypes.INTEGER_32) {
} else if (tokenType == TokenTypes.INTEGER_5 || tokenType == TokenTypes.INTEGER_16 || tokenType == TokenTypes.INTEGER_16U || tokenType == TokenTypes.INTEGER_32) {
int tempNumeric = Binary.stringToInt(tokenValue);
@@ -299,19 +296,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
basicStatementList.addValue(tempNumeric);
this.operands[this.numOperands++] = tempNumeric;
///// End modification 1/7/05 KENV ///////////////////////////////////////////
}
else {
} else {
basicStatementElement = tokenValue;
basic += basicStatementElement;
basicStatementList.addString(basicStatementElement);
}
// add separator if not at end of token list AND neither current nor
// next token is a parenthesis
if ((i < strippedTokenList.size()-1)) {
nextTokenType = strippedTokenList.get(i+1).getType();
if (tokenType != TokenTypes.LEFT_PAREN && tokenType != TokenTypes.RIGHT_PAREN &&
nextTokenType != TokenTypes.LEFT_PAREN && nextTokenType != TokenTypes.RIGHT_PAREN)
{
if ((i < strippedTokenList.size() - 1)) {
nextTokenType = strippedTokenList.get(i + 1).getType();
if (tokenType != TokenTypes.LEFT_PAREN && tokenType != TokenTypes.RIGHT_PAREN && nextTokenType != TokenTypes.LEFT_PAREN && nextTokenType != TokenTypes.RIGHT_PAREN) {
basicStatementElement = ",";
basic += basicStatementElement;
basicStatementList.addString(basicStatementElement);
@@ -322,48 +316,45 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
} //buildBasicStatementFromBasicInstruction()
/////////////////////////////////////////////////////////////////////////////
/**
* Given the current statement in Basic Assembly format (see above), build the
* 32-bit binary machine code statement.
*
* @param errors The list of assembly errors encountered so far. May add to it here.
**/
public void buildMachineStatementFromBasicStatement(ErrorList errors) {
try {
//mask indicates bit positions for 'f'irst, 's'econd, 't'hird operand
this.machineStatement = ((BasicInstruction)instruction).getOperationMask();
this.machineStatement = ((BasicInstruction) instruction).getOperationMask();
} // This means the pseudo-instruction expansion generated another
// pseudo-instruction (expansion must be to all basic instructions).
// This is an error on the part of the pseudo-instruction author.
catch (ClassCastException cce) {
errors.add(new ErrorMessage(this.sourceMIPSprogram,this.sourceLine,0,
"INTERNAL ERROR: pseudo-instruction expansion contained a pseudo-instruction"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, this.sourceLine, 0, "INTERNAL ERROR: pseudo-instruction expansion contained a pseudo-instruction"));
return;
}
BasicInstructionFormat format = ((BasicInstruction)instruction).getInstructionFormat();
BasicInstructionFormat format = ((BasicInstruction) instruction).getInstructionFormat();
if (format == BasicInstructionFormat.J_FORMAT) {
if ((this.textAddress & 0xF0000000) != (this.operands[0] & 0xF0000000)) {
// attempt to jump beyond 28-bit byte (26-bit word) address range.
// SPIM flags as warning, I'll flag as error b/c MARS text segment not long enough for it to be OK.
errors.add(new ErrorMessage(this.sourceMIPSprogram, this.sourceLine, 0,
"Jump target word address beyond 26-bit range"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, this.sourceLine, 0, "Jump target word address beyond 26-bit range"));
return;
}
// Note the bit shift to make this a word address.
this.operands[0] = this.operands[0] >>> 2;
this.insertBinaryCode(this.operands[0], Instruction.operandMask[0], errors);
}
else if (format == BasicInstructionFormat.I_BRANCH_FORMAT) {
for (int i=0; i<this.numOperands-1; i++) {
} else if (format == BasicInstructionFormat.I_BRANCH_FORMAT) {
for (int i = 0; i < this.numOperands - 1; i++) {
this.insertBinaryCode(this.operands[i], Instruction.operandMask[i], errors);
}
this.insertBinaryCode(operands[this.numOperands-1], Instruction.operandMask[this.numOperands-1], errors);
}
else { // R_FORMAT or I_FORMAT
for (int i=0; i<this.numOperands; i++)
this.insertBinaryCode(operands[this.numOperands - 1], Instruction.operandMask[this.numOperands - 1], errors);
} else { // R_FORMAT or I_FORMAT
for (int i = 0; i < this.numOperands; i++)
this.insertBinaryCode(this.operands[i], Instruction.operandMask[i], errors);
}
this.binaryStatement = Binary.binaryStringToInt(this.machineStatement);
@@ -371,42 +362,42 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
} // buildMachineStatementFromBasicStatement(
/////////////////////////////////////////////////////////////////////////////
/**
* Crude attempt at building String representation of this complex structure.
*
* @return A String representing the ProgramStatement.
**/
public String toString() {
// a crude attempt at string formatting. Where's C when you need it?
String blanks = " ";
String result = "["+this.textAddress+"]";
String result = "[" + this.textAddress + "]";
if (this.basicAssemblyStatement != null) {
int firstSpace = this.basicAssemblyStatement.indexOf(" ");
result += blanks.substring(0, 16-result.length()) + this.basicAssemblyStatement.substring(0,firstSpace);
result += blanks.substring(0, 24-result.length()) + this.basicAssemblyStatement.substring(firstSpace+1);;
}
else {
result += blanks.substring(0, 16 - result.length()) + this.basicAssemblyStatement.substring(0, firstSpace);
result += blanks.substring(0, 24 - result.length()) + this.basicAssemblyStatement.substring(firstSpace + 1);
;
} else {
result += blanks.substring(0, 16 - result.length()) + "0x" + Integer.toString(this.binaryStatement, 16);
}
result += blanks.substring(0, 40-result.length()) + "; "; // this.source;
result += blanks.substring(0, 40 - result.length()) + "; "; // this.source;
if (operands != null) {
for (int i=0; i<this.numOperands; i++)
for (int i = 0; i < this.numOperands; i++)
// result += operands[i] + " ";
result += Integer.toString(operands[i], 16) + " ";
}
if (this.machineStatement != null) {
result += "["+Binary.binaryStringToHexString(this.machineStatement)+"]";
result += " "+this.machineStatement.substring(0,6)+"|" + this.machineStatement.substring(6,11)+"|"+
this.machineStatement.substring(11,16)+"|" + this.machineStatement.substring(16,21)+"|"+
this.machineStatement.substring(21,26)+"|" + this.machineStatement.substring(26,32);
result += "[" + Binary.binaryStringToHexString(this.machineStatement) + "]";
result += " " + this.machineStatement.substring(0, 6) + "|" + this.machineStatement.substring(6, 11) + "|" + this.machineStatement.substring(11, 16) + "|" + this.machineStatement.substring(16, 21) + "|" + this.machineStatement.substring(21, 26) + "|" + this.machineStatement.substring(26, 32);
}
return result;
} // toString()
/**
* Assigns given String to be Basic Assembly statement equivalent to this source line.
*
* @param statement A String containing equivalent Basic Assembly statement.
**/
@@ -417,6 +408,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Assigns given String to be binary machine code (32 characters, all of them 0 or 1)
* equivalent to this source line.
*
* @param statement A String containing equivalent machine code.
**/
@@ -426,6 +418,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Assigns given int to be binary machine code equivalent to this source line.
*
* @param binaryCode An int containing equivalent binary machine code.
**/
@@ -437,6 +430,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* associates MIPS source statement. Used by assembler when generating basic
* statements during macro expansion of extended statement.
*
* @param src a MIPS source statement.
**/
@@ -447,6 +441,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces MIPSprogram object representing the source file containing this statement.
*
* @return The MIPSprogram object. May be null...
**/
public MIPSprogram getSourceMIPSprogram() {
@@ -455,6 +450,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces String name of the source file containing this statement.
*
* @return The file name.
**/
public String getSourceFile() {
@@ -462,9 +458,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
/**
* Produces MIPS source statement.
*
* @return The MIPS source statement.
**/
@@ -474,6 +470,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces line number of MIPS source statement.
*
* @return The MIPS source statement line number.
**/
@@ -484,6 +481,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces Basic Assembly statement for this MIPS source statement.
* All numeric values are in decimal.
*
* @return The Basic Assembly statement.
**/
@@ -496,6 +494,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* statement. This is generated dynamically and any addresses and
* values will be rendered in hex or decimal depending on the current
* setting.
*
* @return The Basic Assembly statement.
**/
public String getPrintableBasicAssemblyStatement() {
@@ -504,6 +503,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces binary machine statement as 32 character string, all '0' and '1' chars.
*
* @return The String version of 32-bit binary machine code.
**/
@@ -513,47 +513,59 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Produces 32-bit binary machine statement as int.
*
* @return The int version of 32-bit binary machine code.
**/
public int getBinaryStatement() {
return binaryStatement;
}
/**
* Produces token list generated from original source statement.
*
* @return The TokenList of Token objects generated from original source.
**/
public TokenList getOriginalTokenList() {
return originalTokenList;
}
/**
* Produces token list stripped of all but operator and operand tokens.
*
* @return The TokenList of Token objects generated by stripping original list of all
* except operator and operand tokens.
**/
public TokenList getStrippedTokenList() {
return strippedTokenList;
}
/**
* Produces Instruction object corresponding to this statement's operator.
*
* @return The Instruction that matches the operator used in this statement.
**/
public Instruction getInstruction() {
return instruction;
}
/**
* Produces Text Segment address where the binary machine statement is stored.
*
* @return address in Text Segment of this binary machine statement.
**/
public int getAddress() {
return textAddress;
}
/**
* Produces int array of operand values for this statement.
*
* @return int array of operand values (if any) required by this statement's operator.
**/
public int[] getOperands() {
return operands;
}
/**
* Produces operand value from given array position (first operand is position 0).
*
@@ -563,8 +575,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public int getOperand(int i) {
if (i >= 0 && i < this.numOperands) {
return operands[i];
}
else {
} else {
return -1;
}
}
@@ -577,14 +588,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int startPos = this.machineStatement.indexOf(mask);
int endPos = this.machineStatement.lastIndexOf(mask);
if (startPos == -1 || endPos == -1) { // should NEVER occur
errors.add(new ErrorMessage(this.sourceMIPSprogram,this.sourceLine,0,
"INTERNAL ERROR: mismatch in number of operands in statement vs mask"));
errors.add(new ErrorMessage(this.sourceMIPSprogram, this.sourceLine, 0, "INTERNAL ERROR: mismatch in number of operands in statement vs mask"));
return;
}
String bitString = Binary.intToBinaryString(value, endPos-startPos+1);
String bitString = Binary.intToBinaryString(value, endPos - startPos + 1);
String state = this.machineStatement.substring(0, startPos) + bitString;
if (endPos < this.machineStatement.length()-1)
state = state + this.machineStatement.substring(endPos+1);
if (endPos < this.machineStatement.length() - 1) state = state + this.machineStatement.substring(endPos + 1);
this.machineStatement = state;
return;
} // insertBinaryCode()
@@ -603,46 +612,41 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if (instr == null) {
statementList.addString(invalidOperator);
return statementList;
} else {
statementList.addString(instr.getName() + " ");
}
else {
statementList.addString(instr.getName()+" ");
}
for (int i=0; i<numOperands;i++) {
for (int i = 0; i < numOperands; i++) {
// add separator if not at end of token list AND neither current nor
// next token is a parenthesis
if (tokenListCounter > 1 && tokenListCounter<instr.getTokenList().size()) {
if (tokenListCounter > 1 && tokenListCounter < instr.getTokenList().size()) {
TokenTypes thisTokenType = instr.getTokenList().get(tokenListCounter).getType();
if (thisTokenType != TokenTypes.LEFT_PAREN && thisTokenType != TokenTypes.RIGHT_PAREN) {
statementList.addString(",");
}
}
boolean notOperand = true;
while (notOperand && tokenListCounter<instr.getTokenList().size()) {
while (notOperand && tokenListCounter < instr.getTokenList().size()) {
TokenTypes tokenType = instr.getTokenList().get(tokenListCounter).getType();
if (tokenType.equals(TokenTypes.LEFT_PAREN)) {
statementList.addString("(");
}
else if (tokenType.equals(TokenTypes.RIGHT_PAREN)) {
} else if (tokenType.equals(TokenTypes.RIGHT_PAREN)) {
statementList.addString(")");
}
else if (tokenType.toString().contains("REGISTER")) {
} else if (tokenType.toString().contains("REGISTER")) {
String marker = (tokenType.toString().contains("FP_REGISTER")) ? "$f" : "$";
statementList.addString(marker+operands[i]);
statementList.addString(marker + operands[i]);
notOperand = false;
}
else {
} else {
statementList.addValue(operands[i]);
notOperand = false;
}
tokenListCounter++;
}
}
while (tokenListCounter<instr.getTokenList().size()) {
while (tokenListCounter < instr.getTokenList().size()) {
TokenTypes tokenType = instr.getTokenList().get(tokenListCounter).getType();
if (tokenType.equals(TokenTypes.LEFT_PAREN)) {
statementList.addString("(");
}
else if (tokenType.equals(TokenTypes.RIGHT_PAREN)) {
} else if (tokenType.equals(TokenTypes.RIGHT_PAREN)) {
statementList.addString(")");
}
tokenListCounter++;
@@ -651,7 +655,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
} // buildBasicStatementListFromBinaryCode()
//////////////////////////////////////////////////////////
//
// Little class to represent basic statement as list
@@ -692,20 +695,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int valueBase = (Globals.getSettings().getBooleanSetting(Settings.DISPLAY_VALUES_IN_HEX)) ? mars.venus.NumberDisplayBaseChooser.HEXADECIMAL : mars.venus.NumberDisplayBaseChooser.DECIMAL;
StringBuffer result = new StringBuffer();
for (int i=0; i<list.size(); i++) {
for (int i = 0; i < list.size(); i++) {
ListElement e = (ListElement) list.get(i);
switch (e.type) {
case 0 :
case 0:
result.append(e.sValue);
break;
case 1 :
case 1:
result.append(mars.venus.NumberDisplayBaseChooser.formatNumber(e.iValue, addressBase));
break;
case 2 :
case 2:
if (valueBase == mars.venus.NumberDisplayBaseChooser.HEXADECIMAL) {
result.append(mars.util.Binary.intToHexString(e.iValue)); // 13-July-2011, was: intToHalfHexString()
}
else {
} else {
result.append(mars.venus.NumberDisplayBaseChooser.formatNumber(e.iValue, valueBase));
}
default:
@@ -719,6 +721,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
int type;
String sValue;
int iValue;
ListElement(int type, String sValue, int iValue) {
this.type = type;
this.sValue = sValue;
@@ -727,4 +730,4 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
}
}
}
File diff suppressed because it is too large Load Diff
+14 -10
View File
@@ -1,9 +1,13 @@
package mars.mips.hardware;
import mars.*;
import mars.util.*;
import mars.simulator.*;
import mars.mips.instructions.*;
import java.util.*;
package mars.mips.hardware;
import mars.Globals;
import mars.ProgramStatement;
import mars.Settings;
import mars.mips.instructions.Instruction;
import mars.simulator.Exceptions;
import mars.util.Binary;
import java.util.*;
/*
Copyright (c) 2003-2009, Pete Sanderson and Kenneth Vollmar
@@ -769,10 +773,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
else if (inTextSegment(address) || inKernelTextSegment(address)) {
try {
value = (getStatementNoNotify(address) == null) ? null : new Integer(getStatementNoNotify(address).getBinaryStatement());
value = (getStatementNoNotify(address) == null) ? null : getStatementNoNotify(address).getBinaryStatement();
} catch (AddressErrorException aee) {
value = null;
}
catch (AddressErrorException aee) {
value = null; }
}
else if (inKernelDataSegment(address)) {
// in kernel data segment
@@ -1382,7 +1386,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
else {
value = blockTable[block][offset];
}
return new Integer(value);
return value;
}
////////////////////////////////////////////////////////////////////////////////////
@@ -1,11 +1,25 @@
package mars.mips.instructions;
import mars.simulator.*;
import mars.mips.hardware.*;
import mars.mips.instructions.syscalls.*;
import mars.*;
import mars.util.*;
import java.util.*;
import java.io.*;
package mars.mips.instructions;
import mars.Globals;
import mars.ProcessingException;
import mars.ProgramStatement;
import mars.mips.hardware.AddressErrorException;
import mars.mips.hardware.Coprocessor0;
import mars.mips.hardware.Coprocessor1;
import mars.mips.hardware.RegisterFile;
import mars.mips.instructions.syscalls.Syscall;
import mars.simulator.DelayedBranch;
import mars.simulator.Exceptions;
import mars.util.Binary;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
/*
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar
@@ -1672,7 +1686,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
round = Integer.MAX_VALUE;
}
else {
Float floatObj = new Float(floatValue);
Float floatObj = floatValue;
// If we are EXACTLY in the middle, then round to even! To determine this,
// find next higher integer and next lower integer, then see if distances
// are exactly equal.
@@ -1920,7 +1934,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
round = Integer.MAX_VALUE;
}
else {
Double doubleObj = new Double(doubleValue);
Double doubleObj = doubleValue;
// If we are EXACTLY in the middle, then round to even! To determine this,
// find next higher integer and next lower integer, then see if distances
// are exactly equal.
@@ -1,7 +1,9 @@
package mars.mips.instructions.syscalls;
import mars.util.*;
import mars.mips.hardware.*;
import mars.*;
package mars.mips.instructions.syscalls;
import mars.ProcessingException;
import mars.ProgramStatement;
import mars.mips.hardware.Coprocessor1;
import mars.util.SystemIO;
/*
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
@@ -49,7 +51,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Performs syscall function to display float whose bits are stored in $f12
*/
public void simulate(ProgramStatement statement) throws ProcessingException {
SystemIO.printString(new Float(Float.intBitsToFloat(
Coprocessor1.getValue(12))).toString());
}
SystemIO.printString(Float.toString(Float.intBitsToFloat(
Coprocessor1.getValue(12))));
}
}
@@ -1,7 +1,9 @@
package mars.mips.instructions.syscalls;
import mars.util.*;
import mars.mips.hardware.*;
import mars.*;
package mars.mips.instructions.syscalls;
import mars.ProcessingException;
import mars.ProgramStatement;
import mars.mips.hardware.RegisterFile;
import mars.util.SystemIO;
/*
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
@@ -51,6 +53,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public void simulate(ProgramStatement statement) throws ProcessingException {
SystemIO.printString(
new Integer(RegisterFile.getValue(4)).toString());
Integer.toString(RegisterFile.getValue(4)));
}
}
+9 -8
View File
@@ -1,17 +1,18 @@
package mars.tools;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import mars.Globals;
import mars.mips.hardware.AddressErrorException;
import mars.mips.hardware.Coprocessor0;
import mars.mips.hardware.Memory;
import mars.mips.hardware.MemoryAccessNotice;
import mars.simulator.Exceptions;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Observable;
@SuppressWarnings("serial")
/* Add these two lines in exceptions.java file
* public static final int EXTERNAL_INTERRUPT_TIMER = 0x00000100; //Add for digital Lab Sim
@@ -19,7 +20,7 @@ import mars.simulator.Exceptions;
*/
/*
* Didier Teifreto LIFC Université de franche-Comté www.lifc.univ-fcomte.fr/~teifreto
* Didier Teifreto LIFC Université de franche-Comté www.lifc.univ-fcomte.fr/~teifreto
* didier.teifreto@univ-fcomte.fr
*/
public class DigitalLabSim extends AbstractMarsToolAndApplication {
+30 -69
View File
@@ -1,62 +1,5 @@
package mars.tools;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Observable;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
//import java.util.Timer;
import javax.swing.event.InternalFrameEvent;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import mars.Globals;
import mars.ProgramStatement;
import mars.mips.hardware.AccessNotice;
@@ -69,6 +12,25 @@ import mars.venus.RunAssembleAction;
import mars.venus.RunBackstepAction;
import mars.venus.RunStepAction;
import mars.venus.VenusUI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Observable;
import java.util.Vector;
public class MipsXray extends AbstractMarsToolAndApplication{
private static final long serialVersionUID = -1L;
@@ -118,21 +80,20 @@ public class MipsXray extends AbstractMarsToolAndApplication{
*/
protected JComponent getHelpComponent() {
final String helpContent =
"This plugin is used to visualizate the behavior of mips processor using the default datapath. \n"+
"It reads the source code instruction and generates an animation representing the inputs and \n"+
"outputs of functional blocks and the interconnection between them. The basic signals \n"+
"represented are, control signals, opcode bits and data of functional blocks.\n"+
"\n"+
"Besides the datapath representation, information for each instruction is displayed below\n"+
"the datapath. That display includes opcode value, with the correspondent colors used to\n"+
"represent the signals in datapath, mnemonic of the instruction processed at the moment, registers\n"+
"This plugin is used to visualizate the behavior of mips processor using the default datapath. \n" +
"It reads the source code instruction and generates an animation representing the inputs and \n" +
"outputs of functional blocks and the interconnection between them. The basic signals \n" +
"represented are, control signals, opcode bits and data of functional blocks.\n" +
"\n" +
"Besides the datapath representation, information for each instruction is displayed below\n" +
"the datapath. That display includes opcode value, with the correspondent colors used to\n" +
"represent the signals in datapath, mnemonic of the instruction processed at the moment, registers\n" +
"used in the instruction and a label that indicates the color code used to represent control signals\n" +
"\n"+
"\n" +
"To see the datapath of register bank and control units click inside the functional unit.\n\n" +
"Version 2.0\n" +
"Developed by Márcio Roberto, Guilherme Sales, Fabrício Vivas, Flávio Cardeal and Fábio Lúcio\n" +
"Contact Marcio Roberto at marcio.rdaraujo@gmail.com with questions or comments.\n"
;
"Developed by Márcio Roberto, Guilherme Sales, Fabrício Vivas, Flávio Cardeal and Fábio Lúcio\n" +
"Contact Marcio Roberto at marcio.rdaraujo@gmail.com with questions or comments.\n";
JButton help = new JButton("Help");
help.addActionListener(
new ActionListener() {
+25 -17
View File
@@ -1,15 +1,22 @@
package mars.venus;
import mars.*;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
import java.util.concurrent.ArrayBlockingQueue;
import javax.swing.event.DocumentListener;
import javax.swing.undo.UndoableEdit;
import mars.simulator.Simulator;
import javax.swing.event.DocumentEvent;
import javax.swing.text.Position.Bias;
package mars.venus;
import mars.ErrorList;
import mars.Globals;
import mars.simulator.Simulator;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.NavigationFilter;
import javax.swing.text.Position.Bias;
import javax.swing.undo.UndoableEdit;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.ArrayBlockingQueue;
/*
Copyright (c) 2003-2010, Pete Sanderson and Kenneth Vollmar
@@ -377,15 +384,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////
// Thread class for obtaining user input in the Run I/O window (MessagesPane)
// Written by Ricardo Fernández Pascual [rfernandez@ditec.um.es] December 2009.
// Written by Ricardo Fernández Pascual [rfernandez@ditec.um.es] December 2009.
class Asker implements Runnable {
ArrayBlockingQueue<String> resultQueue = new ArrayBlockingQueue<String>(1);
int initialPos;
int maxLen;
Asker(int maxLen) {
this.maxLen = maxLen;
// initialPos will be set in run()
}
final DocumentListener listener =
new DocumentListener() {
public void insertUpdate(final DocumentEvent e) {
@@ -430,6 +433,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
public void changedUpdate(DocumentEvent e) { }
};
Asker(int maxLen) {
this.maxLen = maxLen;
// initialPos will be set in run()
}
final NavigationFilter navigationFilter =
new NavigationFilter() {
public void moveDot(FilterBypass fb, int dot, Bias bias) {
+247 -418
View File
@@ -1,12 +1,15 @@
package mars.venus;
import mars.*;
import mars.mips.dump.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
package mars.venus;
import mars.Globals;
import mars.Settings;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
/*
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar
@@ -36,19 +39,24 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(MIT license, http://www.opensource.org/licenses/mit-license.html)
*/
/**
/**
* Top level container for Venus GUI.
*
* @author Sanderson and Team JSpim
**/
/* Heavily modified by Pete Sanderson, July 2004, to incorporate JSPIMMenu and JSPIMToolbar
/* Heavily modified by Pete Sanderson, July 2004, to incorporate JSPIMMenu and JSPIMToolbar
* not as subclasses of JMenuBar and JToolBar, but as instances of them. They are both
* here primarily so both can share the Action objects.
*/
public class VenusUI extends JFrame{
VenusUI mainUI;
public class VenusUI extends JFrame {
private static int menuState = FileStatus.NO_FILE;
// PLEASE PUT THESE TWO (& THEIR METHODS) SOMEWHERE THEY BELONG, NOT HERE
private static boolean reset = true; // registers/memory reset for execution
private static boolean started = false; // started execution
public JMenuBar menu;
VenusUI mainUI;
JToolBar toolbar;
MainPane mainPane;
RegistersPane registersPane;
@@ -58,53 +66,38 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MessagesPane messagesPane;
JSplitPane splitter, horizonSplitter;
JPanel north;
private int frameState; // see windowActivated() and windowDeactivated()
private static int menuState = FileStatus.NO_FILE;
// PLEASE PUT THESE TWO (& THEIR METHODS) SOMEWHERE THEY BELONG, NOT HERE
private static boolean reset= true; // registers/memory reset for execution
private static boolean started = false; // started execution
Editor editor;
EditUndoAction editUndoAction;
EditRedoAction editRedoAction;
private int frameState; // see windowActivated() and windowDeactivated()
// components of the menubar
private JMenu file, run, window, help, edit, settings;
private JMenuItem fileNew, fileOpen, fileClose, fileCloseAll, fileSave, fileSaveAs, fileSaveAll, fileDumpMemory, filePrint, fileExit;
private JMenuItem editUndo, editRedo, editCut, editCopy, editPaste, editFindReplace, editSelectAll;
private JMenuItem runGo, runStep, runBackstep, runReset, runAssemble, runStop, runPause, runClearBreakpoints, runToggleBreakpoints;
private JCheckBoxMenuItem settingsLabel, settingsPopupInput, settingsValueDisplayBase, settingsAddressDisplayBase,
settingsExtended, settingsAssembleOnOpen, settingsAssembleAll, settingsWarningsAreErrors, settingsStartAtMain,
settingsDelayedBranching, settingsProgramArguments, settingsSelfModifyingCode;
private JCheckBoxMenuItem settingsLabel, settingsPopupInput, settingsValueDisplayBase, settingsAddressDisplayBase, settingsExtended, settingsAssembleOnOpen, settingsAssembleAll, settingsWarningsAreErrors, settingsStartAtMain, settingsDelayedBranching, settingsProgramArguments, settingsSelfModifyingCode;
private JMenuItem settingsExceptionHandler, settingsEditor, settingsHighlighting, settingsMemoryConfiguration;
private JMenuItem helpHelp, helpAbout;
// components of the toolbar
private JButton Undo, Redo, Cut, Copy, Paste, FindReplace, SelectAll;
private JButton New, Open, Save, SaveAs, SaveAll, DumpMemory, Print;
private JButton Run, Assemble, Reset, Step, Backstep, Stop, Pause;
private JButton Help;
// The "action" objects, which include action listeners. One of each will be created then
// shared between a menu item and its corresponding toolbar button. This is a very cool
// technique because it relates the button and menu item so closely
private JButton Run, Assemble, Reset, Step, Backstep, Stop, Pause;
private JButton Help;
private Action fileNewAction, fileOpenAction, fileCloseAction, fileCloseAllAction, fileSaveAction;
private Action fileSaveAsAction, fileSaveAllAction, fileDumpMemoryAction, filePrintAction, fileExitAction;
EditUndoAction editUndoAction;
EditRedoAction editRedoAction;
private Action editCutAction, editCopyAction, editPasteAction, editFindReplaceAction, editSelectAllAction;
private Action runAssembleAction, runGoAction, runStepAction, runBackstepAction, runResetAction,
runStopAction, runPauseAction, runClearBreakpointsAction, runToggleBreakpointsAction;
private Action settingsLabelAction, settingsPopupInputAction, settingsValueDisplayBaseAction, settingsAddressDisplayBaseAction,
settingsExtendedAction, settingsAssembleOnOpenAction, settingsAssembleAllAction,
settingsWarningsAreErrorsAction, settingsStartAtMainAction, settingsProgramArgumentsAction,
settingsDelayedBranchingAction, settingsExceptionHandlerAction, settingsEditorAction,
settingsHighlightingAction, settingsMemoryConfigurationAction, settingsSelfModifyingCodeAction;
private Action runAssembleAction, runGoAction, runStepAction, runBackstepAction, runResetAction, runStopAction, runPauseAction, runClearBreakpointsAction, runToggleBreakpointsAction;
private Action settingsLabelAction, settingsPopupInputAction, settingsValueDisplayBaseAction, settingsAddressDisplayBaseAction, settingsExtendedAction, settingsAssembleOnOpenAction, settingsAssembleAllAction, settingsWarningsAreErrorsAction, settingsStartAtMainAction, settingsProgramArgumentsAction, settingsDelayedBranchingAction, settingsExceptionHandlerAction, settingsEditorAction, settingsHighlightingAction, settingsMemoryConfigurationAction, settingsSelfModifyingCodeAction;
private Action helpHelpAction, helpAboutAction;
/**
* Constructor for the Class. Sets up a window object for the UI
*
* @param s Name of the window to be created.
**/
@@ -117,16 +110,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
// basically give up some screen space if running at 800 x 600
double messageWidthPct = (screenWidth<1000.0)? 0.67 : 0.73;
double messageHeightPct = (screenWidth<1000.0)? 0.12 : 0.15;
double mainWidthPct = (screenWidth<1000.0)? 0.67 : 0.73;
double mainHeightPct = (screenWidth<1000.0)? 0.60 : 0.65;
double registersWidthPct = (screenWidth<1000.0)? 0.18 : 0.22;
double registersHeightPct = (screenWidth<1000.0)? 0.72 : 0.80;
double messageWidthPct = (screenWidth < 1000.0) ? 0.67 : 0.73;
double messageHeightPct = (screenWidth < 1000.0) ? 0.12 : 0.15;
double mainWidthPct = (screenWidth < 1000.0) ? 0.67 : 0.73;
double mainHeightPct = (screenWidth < 1000.0) ? 0.60 : 0.65;
double registersWidthPct = (screenWidth < 1000.0) ? 0.18 : 0.22;
double registersHeightPct = (screenWidth < 1000.0) ? 0.72 : 0.80;
Dimension messagesPanePreferredSize = new Dimension((int)(screenWidth*messageWidthPct),(int)(screenHeight*messageHeightPct));
Dimension mainPanePreferredSize = new Dimension((int)(screenWidth*mainWidthPct),(int)(screenHeight*mainHeightPct));
Dimension registersPanePreferredSize = new Dimension((int)(screenWidth*registersWidthPct),(int)(screenHeight*registersHeightPct));
Dimension messagesPanePreferredSize = new Dimension((int) (screenWidth * messageWidthPct), (int) (screenHeight * messageHeightPct));
Dimension mainPanePreferredSize = new Dimension((int) (screenWidth * mainWidthPct), (int) (screenHeight * mainHeightPct));
Dimension registersPanePreferredSize = new Dimension((int) (screenWidth * registersWidthPct), (int) (screenHeight * registersHeightPct));
// the "restore" size (window control button that toggles with maximize)
// I want to keep it large, with enough room for user to get handles
@@ -135,7 +128,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Globals.initialize(true);
// image courtesy of NASA/JPL.
URL im = this.getClass().getResource(Globals.imagesPath+"RedMars16.gif");
URL im = this.getClass().getResource(Globals.imagesPath + "RedMars16.gif");
if (im == null) {
System.out.println("Internal Error: images folder or file not found");
System.exit(0);
@@ -159,7 +152,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
registersTab = new RegistersWindow();
coprocessor1Tab = new Coprocessor1Window();
coprocessor0Tab = new Coprocessor0Window();
registersPane = new RegistersPane(mainUI, registersTab,coprocessor1Tab, coprocessor0Tab);
registersPane = new RegistersPane(mainUI, registersTab, coprocessor1Tab, coprocessor0Tab);
registersPane.setPreferredSize(registersPanePreferredSize);
//Insets defaultTabInsets = (Insets)UIManager.get("TabbedPane.tabInsets");
@@ -168,9 +161,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//UIManager.put("TabbedPane.tabInsets", defaultTabInsets);
mainPane.setPreferredSize(mainPanePreferredSize);
messagesPane= new MessagesPane();
messagesPane = new MessagesPane();
messagesPane.setPreferredSize(messagesPanePreferredSize);
splitter= new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPane, messagesPane);
splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPane, messagesPane);
splitter.setOneTouchExpandable(true);
splitter.resetToPreferredSizes();
horizonSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitter, registersPane);
@@ -179,20 +172,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// due to dependencies, do not set up menu/toolbar until now.
this.createActionObjects();
menu= this.setUpMenuBar();
menu = this.setUpMenuBar();
this.setJMenuBar(menu);
toolbar= this.setUpToolBar();
toolbar = this.setUpToolBar();
JPanel jp = new JPanel(new FlowLayout(FlowLayout.LEFT));
jp.add(toolbar);
jp.add(RunSpeedPanel.getInstance());
JPanel center= new JPanel(new BorderLayout());
JPanel center = new JPanel(new BorderLayout());
center.add(jp, BorderLayout.NORTH);
center.add(horizonSplitter);
this.getContentPane().add(center);
FileStatus.reset();
@@ -201,8 +193,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This is invoked when opening the app. It will set the app to
// appear at full screen size.
this.addWindowListener(
new WindowAdapter() {
this.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
mainUI.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
@@ -210,8 +201,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This is invoked when exiting the app through the X icon. It will in turn
// check for unsaved edits before exiting.
this.addWindowListener(
new WindowAdapter() {
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (mainUI.editor.closeAll()) {
System.exit(0);
@@ -228,6 +218,109 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
this.setVisible(true);
}
/**
* Get current menu state. State values are constants in FileStatus class. DPS 23 July 2008
*
* @return current menu state.
**/
public static int getMenuState() {
return menuState;
}
/*
* build the menus and connect them to action objects (which serve as action listeners
* shared between menu item and corresponding toolbar icon).
*/
/* Determine from FileStatus what the menu state (enabled/disabled)should
* be then call the appropriate method to set it. Current states are:
*
* setMenuStateInitial: set upon startup and after File->Close
* setMenuStateEditingNew: set upon File->New
* setMenuStateEditing: set upon File->Open or File->Save or erroneous Run->Assemble
* setMenuStateRunnable: set upon successful Run->Assemble
* setMenuStateRunning: set upon Run->Go
* setMenuStateTerminated: set upon completion of simulated execution
*/
void setMenuState(int status) {
menuState = status;
switch (status) {
case FileStatus.NO_FILE:
setMenuStateInitial();
break;
case FileStatus.NEW_NOT_EDITED:
setMenuStateEditingNew();
break;
case FileStatus.NEW_EDITED:
setMenuStateEditingNew();
break;
case FileStatus.NOT_EDITED:
setMenuStateNotEdited(); // was MenuStateEditing. DPS 9-Aug-2011
break;
case FileStatus.EDITED:
setMenuStateEditing();
break;
case FileStatus.RUNNABLE:
setMenuStateRunnable();
break;
case FileStatus.RUNNING:
setMenuStateRunning();
break;
case FileStatus.TERMINATED:
setMenuStateTerminated();
break;
case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011
break;
default:
System.out.println("Invalid File Status: " + status);
break;
}
}
/*
* build the toolbar and connect items to action objects (which serve as action listeners
* shared between toolbar icon and corresponding menu item).
*/
/**
* To find out whether the register values are reset.
*
* @return Boolean true if the register values have been reset.
**/
public static boolean getReset() {
return reset;
}
/**
* To set whether the register values are reset.
*
* @param b Boolean true if the register values have been reset.
**/
public static void setReset(boolean b) {
reset = b;
}
/**
* To find out whether MIPS program is currently executing.
*
* @return true if MIPS program is currently executing.
**/
public static boolean getStarted() {
return started;
}
/**
* To set whether MIPS program execution has started.
*
* @param b true if the MIPS program execution has started.
**/
public static void setStarted(boolean b) {
started = b;
}
/*
* Action objects are used instead of action listeners because one can be easily shared between
@@ -238,240 +331,69 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Toolkit tk = Toolkit.getDefaultToolkit();
Class cs = this.getClass();
try {
fileNewAction = new FileNewAction("New",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"New22.png"))),
"Create a new file for editing", new Integer(KeyEvent.VK_N),
KeyStroke.getKeyStroke( KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
fileOpenAction = new FileOpenAction("Open ...",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Open22.png"))),
"Open a file for editing", new Integer(KeyEvent.VK_O),
KeyStroke.getKeyStroke( KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
fileCloseAction = new FileCloseAction("Close", null,
"Close the current file", new Integer(KeyEvent.VK_C),
KeyStroke.getKeyStroke( KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
fileCloseAllAction = new FileCloseAllAction("Close All", null,
"Close all open files", new Integer(KeyEvent.VK_L),
null, mainUI);
fileSaveAction = new FileSaveAction("Save",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Save22.png"))),
"Save the current file", new Integer(KeyEvent.VK_S),
KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
fileSaveAsAction = new FileSaveAsAction("Save as ...",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"SaveAs22.png"))),
"Save current file with different name", new Integer(KeyEvent.VK_A),
null, mainUI);
fileSaveAllAction = new FileSaveAllAction("Save All", null,
"Save all open files", new Integer(KeyEvent.VK_V),
null, mainUI);
fileDumpMemoryAction = new FileDumpMemoryAction("Dump Memory ...",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Dump22.png"))),
"Dump machine code or data in an available format", new Integer(KeyEvent.VK_D),
KeyStroke.getKeyStroke( KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
filePrintAction = new FilePrintAction("Print ...",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Print22.gif"))),
"Print current file", new Integer(KeyEvent.VK_P),
null, mainUI);
fileExitAction = new FileExitAction("Exit", null,
"Exit Mars", new Integer(KeyEvent.VK_X),
null, mainUI);
editUndoAction = new EditUndoAction("Undo",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Undo22.png"))),
"Undo last edit", new Integer(KeyEvent.VK_U),
KeyStroke.getKeyStroke( KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editRedoAction = new EditRedoAction("Redo",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Redo22.png"))),
"Redo last edit", new Integer(KeyEvent.VK_R),
KeyStroke.getKeyStroke( KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editCutAction = new EditCutAction("Cut",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Cut22.gif"))),
"Cut", new Integer(KeyEvent.VK_C),
KeyStroke.getKeyStroke( KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editCopyAction = new EditCopyAction("Copy",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Copy22.png"))),
"Copy", new Integer(KeyEvent.VK_O),
KeyStroke.getKeyStroke( KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editPasteAction = new EditPasteAction("Paste",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Paste22.png"))),
"Paste", new Integer(KeyEvent.VK_P),
KeyStroke.getKeyStroke( KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editFindReplaceAction = new EditFindReplaceAction("Find/Replace",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find22.png"))),
"Find/Replace", new Integer(KeyEvent.VK_F),
KeyStroke.getKeyStroke( KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
editSelectAllAction = new EditSelectAllAction("Select All",
null, //new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find22.png"))),
"Select All", new Integer(KeyEvent.VK_A),
KeyStroke.getKeyStroke( KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
runAssembleAction = new RunAssembleAction("Assemble",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Assemble22.png"))),
"Assemble the current file and clear breakpoints", new Integer(KeyEvent.VK_A),
KeyStroke.getKeyStroke( KeyEvent.VK_F3, 0),
mainUI);
runGoAction = new RunGoAction("Go",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Play22.png"))),
"Run the current program", new Integer(KeyEvent.VK_G),
KeyStroke.getKeyStroke( KeyEvent.VK_F5, 0),
mainUI);
runStepAction = new RunStepAction("Step",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"StepForward22.png"))),
"Run one step at a time", new Integer(KeyEvent.VK_T),
KeyStroke.getKeyStroke( KeyEvent.VK_F7, 0),
mainUI);
runBackstepAction = new RunBackstepAction("Backstep",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"StepBack22.png"))),
"Undo the last step", new Integer(KeyEvent.VK_B),
KeyStroke.getKeyStroke( KeyEvent.VK_F8, 0),
mainUI);
runPauseAction = new RunPauseAction("Pause",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Pause22.png"))),
"Pause the currently running program", new Integer(KeyEvent.VK_P),
KeyStroke.getKeyStroke( KeyEvent.VK_F9, 0),
mainUI);
runStopAction = new RunStopAction("Stop",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Stop22.png"))),
"Stop the currently running program", new Integer(KeyEvent.VK_S),
KeyStroke.getKeyStroke( KeyEvent.VK_F11, 0),
mainUI);
runResetAction = new RunResetAction("Reset",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Reset22.png"))),
"Reset MIPS memory and registers", new Integer(KeyEvent.VK_R),
KeyStroke.getKeyStroke( KeyEvent.VK_F12,0),
mainUI);
runClearBreakpointsAction = new RunClearBreakpointsAction("Clear all breakpoints",
null,
"Clears all execution breakpoints set since the last assemble.",
new Integer(KeyEvent.VK_K),
KeyStroke.getKeyStroke( KeyEvent.VK_K, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
runToggleBreakpointsAction = new RunToggleBreakpointsAction("Toggle all breakpoints",
null,
"Disable/enable all breakpoints without clearing (can also click Bkpt column header)",
new Integer(KeyEvent.VK_T),
KeyStroke.getKeyStroke( KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
mainUI);
settingsLabelAction = new SettingsLabelAction("Show Labels Window (symbol table)",
null,
"Toggle visibility of Labels window (symbol table) in the Execute tab",
null,null,
mainUI);
settingsPopupInputAction = new SettingsPopupInputAction("Popup dialog for input syscalls (5,6,7,8,12)",
null,
"If set, use popup dialog for input syscalls (5,6,7,8,12) instead of cursor in Run I/O window",
null,null,
mainUI);
fileNewAction = new FileNewAction("New", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "New22.png"))), "Create a new file for editing", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
fileOpenAction = new FileOpenAction("Open ...", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Open22.png"))), "Open a file for editing", KeyEvent.VK_O, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
fileCloseAction = new FileCloseAction("Close", null, "Close the current file", KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
fileCloseAllAction = new FileCloseAllAction("Close All", null, "Close all open files", KeyEvent.VK_L, null, mainUI);
fileSaveAction = new FileSaveAction("Save", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Save22.png"))), "Save the current file", KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
fileSaveAsAction = new FileSaveAsAction("Save as ...", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "SaveAs22.png"))), "Save current file with different name", KeyEvent.VK_A, null, mainUI);
fileSaveAllAction = new FileSaveAllAction("Save All", null, "Save all open files", KeyEvent.VK_V, null, mainUI);
fileDumpMemoryAction = new FileDumpMemoryAction("Dump Memory ...", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Dump22.png"))), "Dump machine code or data in an available format", KeyEvent.VK_D, KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
filePrintAction = new FilePrintAction("Print ...", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Print22.gif"))), "Print current file", KeyEvent.VK_P, null, mainUI);
fileExitAction = new FileExitAction("Exit", null, "Exit Mars", KeyEvent.VK_X, null, mainUI);
editUndoAction = new EditUndoAction("Undo", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Undo22.png"))), "Undo last edit", KeyEvent.VK_U, KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editRedoAction = new EditRedoAction("Redo", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Redo22.png"))), "Redo last edit", KeyEvent.VK_R, KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editCutAction = new EditCutAction("Cut", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Cut22.gif"))), "Cut", KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editCopyAction = new EditCopyAction("Copy", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Copy22.png"))), "Copy", KeyEvent.VK_O, KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editPasteAction = new EditPasteAction("Paste", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Paste22.png"))), "Paste", KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editFindReplaceAction = new EditFindReplaceAction("Find/Replace", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Find22.png"))), "Find/Replace", KeyEvent.VK_F, KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
editSelectAllAction = new EditSelectAllAction("Select All", null, //new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find22.png"))),
"Select All", KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
runAssembleAction = new RunAssembleAction("Assemble", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Assemble22.png"))), "Assemble the current file and clear breakpoints", KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), mainUI);
runGoAction = new RunGoAction("Go", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Play22.png"))), "Run the current program", KeyEvent.VK_G, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), mainUI);
runStepAction = new RunStepAction("Step", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepForward22.png"))), "Run one step at a time", KeyEvent.VK_T, KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), mainUI);
runBackstepAction = new RunBackstepAction("Backstep", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepBack22.png"))), "Undo the last step", KeyEvent.VK_B, KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), mainUI);
runPauseAction = new RunPauseAction("Pause", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Pause22.png"))), "Pause the currently running program", KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), mainUI);
runStopAction = new RunStopAction("Stop", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Stop22.png"))), "Stop the currently running program", KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), mainUI);
runResetAction = new RunResetAction("Reset", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Reset22.png"))), "Reset MIPS memory and registers", KeyEvent.VK_R, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), mainUI);
runClearBreakpointsAction = new RunClearBreakpointsAction("Clear all breakpoints", null, "Clears all execution breakpoints set since the last assemble.", KeyEvent.VK_K, KeyStroke.getKeyStroke(KeyEvent.VK_K, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
runToggleBreakpointsAction = new RunToggleBreakpointsAction("Toggle all breakpoints", null, "Disable/enable all breakpoints without clearing (can also click Bkpt column header)", KeyEvent.VK_T, KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI);
settingsLabelAction = new SettingsLabelAction("Show Labels Window (symbol table)", null, "Toggle visibility of Labels window (symbol table) in the Execute tab", null, null, mainUI);
settingsPopupInputAction = new SettingsPopupInputAction("Popup dialog for input syscalls (5,6,7,8,12)", null, "If set, use popup dialog for input syscalls (5,6,7,8,12) instead of cursor in Run I/O window", null, null, mainUI);
settingsValueDisplayBaseAction = new SettingsValueDisplayBaseAction("Values displayed in hexadecimal",
null,
"Toggle between hexadecimal and decimal display of memory/register values",
null,null,
mainUI);
settingsAddressDisplayBaseAction = new SettingsAddressDisplayBaseAction("Addresses displayed in hexadecimal",
null,
"Toggle between hexadecimal and decimal display of memory addresses",
null,null,
mainUI);
settingsExtendedAction = new SettingsExtendedAction("Permit extended (pseudo) instructions and formats",
null,
"If set, MIPS extended (pseudo) instructions are formats are permitted.",
null,null,
mainUI);
settingsAssembleOnOpenAction = new SettingsAssembleOnOpenAction("Assemble file upon opening",
null,
"If set, a file will be automatically assembled as soon as it is opened. File Open dialog will show most recently opened file.",
null,null,
mainUI);
settingsAssembleAllAction = new SettingsAssembleAllAction("Assemble all files in directory",
null,
"If set, all files in current directory will be assembled when Assemble operation is selected.",
null,null,
mainUI);
settingsWarningsAreErrorsAction = new SettingsWarningsAreErrorsAction("Assembler warnings are considered errors",
null,
"If set, assembler warnings will be interpreted as errors and prevent successful assembly.",
null,null,
mainUI);
settingsStartAtMainAction = new SettingsStartAtMainAction("Initialize Program Counter to global 'main' if defined",
null,
"If set, assembler will initialize Program Counter to text address globally labeled 'main', if defined.",
null,null,
mainUI);
settingsProgramArgumentsAction = new SettingsProgramArgumentsAction("Program arguments provided to MIPS program",
null,
"If set, program arguments for MIPS program can be entered in border of Text Segment window.",
null,null,
mainUI);
settingsDelayedBranchingAction = new SettingsDelayedBranchingAction("Delayed branching",
null,
"If set, delayed branching will occur during MIPS execution.",
null,null,
mainUI);
settingsSelfModifyingCodeAction = new SettingsSelfModifyingCodeAction("Self-modifying code",
null,
"If set, the MIPS program can write and branch to both text and data segments.",
null,null,
mainUI);
settingsEditorAction = new SettingsEditorAction("Editor...",
null,
"View and modify text editor settings.",
null,null,
mainUI);
settingsHighlightingAction = new SettingsHighlightingAction("Highlighting...",
null,
"View and modify Execute Tab highlighting colors",
null,null,
mainUI);
settingsExceptionHandlerAction = new SettingsExceptionHandlerAction("Exception Handler...",
null,
"If set, the specified exception handler file will be included in all Assemble operations.",
null,null,
mainUI);
settingsMemoryConfigurationAction = new SettingsMemoryConfigurationAction("Memory Configuration...",
null,
"View and modify memory segment base addresses for simulated MIPS.",
null,null,
mainUI);
helpHelpAction = new HelpHelpAction("Help",
new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Help22.png"))),
"Help", new Integer(KeyEvent.VK_H),
KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0),
mainUI);
helpAboutAction = new HelpAboutAction("About ...",null,
"Information about Mars", null,null, mainUI);
}
catch (NullPointerException e) {
settingsValueDisplayBaseAction = new SettingsValueDisplayBaseAction("Values displayed in hexadecimal", null, "Toggle between hexadecimal and decimal display of memory/register values", null, null, mainUI);
settingsAddressDisplayBaseAction = new SettingsAddressDisplayBaseAction("Addresses displayed in hexadecimal", null, "Toggle between hexadecimal and decimal display of memory addresses", null, null, mainUI);
settingsExtendedAction = new SettingsExtendedAction("Permit extended (pseudo) instructions and formats", null, "If set, MIPS extended (pseudo) instructions are formats are permitted.", null, null, mainUI);
settingsAssembleOnOpenAction = new SettingsAssembleOnOpenAction("Assemble file upon opening", null, "If set, a file will be automatically assembled as soon as it is opened. File Open dialog will show most recently opened file.", null, null, mainUI);
settingsAssembleAllAction = new SettingsAssembleAllAction("Assemble all files in directory", null, "If set, all files in current directory will be assembled when Assemble operation is selected.", null, null, mainUI);
settingsWarningsAreErrorsAction = new SettingsWarningsAreErrorsAction("Assembler warnings are considered errors", null, "If set, assembler warnings will be interpreted as errors and prevent successful assembly.", null, null, mainUI);
settingsStartAtMainAction = new SettingsStartAtMainAction("Initialize Program Counter to global 'main' if defined", null, "If set, assembler will initialize Program Counter to text address globally labeled 'main', if defined.", null, null, mainUI);
settingsProgramArgumentsAction = new SettingsProgramArgumentsAction("Program arguments provided to MIPS program", null, "If set, program arguments for MIPS program can be entered in border of Text Segment window.", null, null, mainUI);
settingsDelayedBranchingAction = new SettingsDelayedBranchingAction("Delayed branching", null, "If set, delayed branching will occur during MIPS execution.", null, null, mainUI);
settingsSelfModifyingCodeAction = new SettingsSelfModifyingCodeAction("Self-modifying code", null, "If set, the MIPS program can write and branch to both text and data segments.", null, null, mainUI);
settingsEditorAction = new SettingsEditorAction("Editor...", null, "View and modify text editor settings.", null, null, mainUI);
settingsHighlightingAction = new SettingsHighlightingAction("Highlighting...", null, "View and modify Execute Tab highlighting colors", null, null, mainUI);
settingsExceptionHandlerAction = new SettingsExceptionHandlerAction("Exception Handler...", null, "If set, the specified exception handler file will be included in all Assemble operations.", null, null, mainUI);
settingsMemoryConfigurationAction = new SettingsMemoryConfigurationAction("Memory Configuration...", null, "View and modify memory segment base addresses for simulated MIPS.", null, null, mainUI);
helpHelpAction = new HelpHelpAction("Help", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Help22.png"))), "Help", KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), mainUI);
helpAboutAction = new HelpAboutAction("About ...", null, "Information about Mars", null, null, mainUI);
} catch (NullPointerException e) {
System.out.println("Internal Error: images folder not found, or other null pointer exception while creating Action objects");
e.printStackTrace();
System.exit(0);
}
}
/*
* build the menus and connect them to action objects (which serve as action listeners
* shared between menu item and corresponding toolbar icon).
*/
private JMenuBar setUpMenuBar() {
Toolkit tk = Toolkit.getDefaultToolkit();
Class cs = this.getClass();
JMenuBar menuBar = new JMenuBar();
file=new JMenu("File");
file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
edit = new JMenu("Edit");
edit.setMnemonic(KeyEvent.VK_E);
run=new JMenu("Run");
run = new JMenu("Run");
run.setMnemonic(KeyEvent.VK_R);
//window = new JMenu("Window");
//window.setMnemonic(KeyEvent.VK_W);
@@ -482,25 +404,25 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// slight bug: user typing alt-H activates help menu item directly, not help menu
fileNew = new JMenuItem(fileNewAction);
fileNew.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"New16.png"))));
fileNew.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "New16.png"))));
fileOpen = new JMenuItem(fileOpenAction);
fileOpen.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Open16.png"))));
fileOpen.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Open16.png"))));
fileClose = new JMenuItem(fileCloseAction);
fileClose.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
fileClose.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
fileCloseAll = new JMenuItem(fileCloseAllAction);
fileCloseAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
fileCloseAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
fileSave = new JMenuItem(fileSaveAction);
fileSave.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Save16.png"))));
fileSave.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Save16.png"))));
fileSaveAs = new JMenuItem(fileSaveAsAction);
fileSaveAs.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"SaveAs16.png"))));
fileSaveAs.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "SaveAs16.png"))));
fileSaveAll = new JMenuItem(fileSaveAllAction);
fileSaveAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
fileSaveAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
fileDumpMemory = new JMenuItem(fileDumpMemoryAction);
fileDumpMemory.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Dump16.png"))));
fileDumpMemory.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Dump16.png"))));
filePrint = new JMenuItem(filePrintAction);
filePrint.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Print16.gif"))));
filePrint.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Print16.gif"))));
fileExit = new JMenuItem(fileExitAction);
fileExit.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
fileExit.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
file.add(fileNew);
file.add(fileOpen);
file.add(fileClose);
@@ -518,19 +440,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
file.add(fileExit);
editUndo = new JMenuItem(editUndoAction);
editUndo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Undo16.png"))));//"Undo16.gif"))));
editUndo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Undo16.png"))));//"Undo16.gif"))));
editRedo = new JMenuItem(editRedoAction);
editRedo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Redo16.png"))));//"Redo16.gif"))));
editRedo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Redo16.png"))));//"Redo16.gif"))));
editCut = new JMenuItem(editCutAction);
editCut.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Cut16.gif"))));
editCut.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Cut16.gif"))));
editCopy = new JMenuItem(editCopyAction);
editCopy.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Copy16.png"))));//"Copy16.gif"))));
editCopy.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Copy16.png"))));//"Copy16.gif"))));
editPaste = new JMenuItem(editPasteAction);
editPaste.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Paste16.png"))));//"Paste16.gif"))));
editPaste.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Paste16.png"))));//"Paste16.gif"))));
editFindReplace = new JMenuItem(editFindReplaceAction);
editFindReplace.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find16.png"))));//"Paste16.gif"))));
editFindReplace.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Find16.png"))));//"Paste16.gif"))));
editSelectAll = new JMenuItem(editSelectAllAction);
editSelectAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
editSelectAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
edit.add(editUndo);
edit.add(editRedo);
edit.addSeparator();
@@ -542,23 +464,23 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
edit.add(editSelectAll);
runAssemble = new JMenuItem(runAssembleAction);
runAssemble.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Assemble16.png"))));//"MyAssemble16.gif"))));
runAssemble.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Assemble16.png"))));//"MyAssemble16.gif"))));
runGo = new JMenuItem(runGoAction);
runGo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Play16.png"))));//"Play16.gif"))));
runGo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Play16.png"))));//"Play16.gif"))));
runStep = new JMenuItem(runStepAction);
runStep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"StepForward16.png"))));//"MyStepForward16.gif"))));
runStep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepForward16.png"))));//"MyStepForward16.gif"))));
runBackstep = new JMenuItem(runBackstepAction);
runBackstep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"StepBack16.png"))));//"MyStepBack16.gif"))));
runBackstep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepBack16.png"))));//"MyStepBack16.gif"))));
runReset = new JMenuItem(runResetAction);
runReset.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Reset16.png"))));//"MyReset16.gif"))));
runReset.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Reset16.png"))));//"MyReset16.gif"))));
runStop = new JMenuItem(runStopAction);
runStop.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Stop16.png"))));//"Stop16.gif"))));
runStop.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Stop16.png"))));//"Stop16.gif"))));
runPause = new JMenuItem(runPauseAction);
runPause.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Pause16.png"))));//"Pause16.gif"))));
runPause.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Pause16.png"))));//"Pause16.gif"))));
runClearBreakpoints = new JMenuItem(runClearBreakpointsAction);
runClearBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
runClearBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
runToggleBreakpoints = new JMenuItem(runToggleBreakpointsAction);
runToggleBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
runToggleBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
run.add(runAssemble);
run.add(runGo);
@@ -625,9 +547,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
settings.add(settingsMemoryConfiguration);
helpHelp = new JMenuItem(helpHelpAction);
helpHelp.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Help16.png"))));//"Help16.gif"))));
helpHelp.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Help16.png"))));//"Help16.gif"))));
helpAbout = new JMenuItem(helpAboutAction);
helpAbout.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"MyBlank16.gif"))));
helpAbout.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif"))));
help.add(helpHelp);
help.addSeparator();
help.add(helpAbout);
@@ -646,11 +568,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return menuBar;
}
/*
* build the toolbar and connect items to action objects (which serve as action listeners
* shared between toolbar icon and corresponding menu item).
*/
JToolBar setUpToolBar() {
JToolBar toolBar = new JToolBar();
@@ -664,18 +581,18 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SaveAs.setText("");
DumpMemory = new JButton(fileDumpMemoryAction);
DumpMemory.setText("");
Print= new JButton(filePrintAction);
Print = new JButton(filePrintAction);
Print.setText("");
Undo = new JButton(editUndoAction);
Undo.setText("");
Redo = new JButton(editRedoAction);
Redo.setText("");
Cut= new JButton(editCutAction);
Cut = new JButton(editCutAction);
Cut.setText("");
Copy= new JButton(editCopyAction);
Copy = new JButton(editCopyAction);
Copy.setText("");
Paste= new JButton(editPasteAction);
Paste = new JButton(editPasteAction);
Paste.setText("");
FindReplace = new JButton(editFindReplaceAction);
FindReplace.setText("");
@@ -696,7 +613,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Stop.setText("");
Pause = new JButton(runPauseAction);
Pause.setText("");
Help= new JButton(helpHelpAction);
Help = new JButton(helpHelpAction);
Help.setText("");
toolBar.add(New);
@@ -729,53 +646,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return toolBar;
}
/* Determine from FileStatus what the menu state (enabled/disabled)should
* be then call the appropriate method to set it. Current states are:
*
* setMenuStateInitial: set upon startup and after File->Close
* setMenuStateEditingNew: set upon File->New
* setMenuStateEditing: set upon File->Open or File->Save or erroneous Run->Assemble
* setMenuStateRunnable: set upon successful Run->Assemble
* setMenuStateRunning: set upon Run->Go
* setMenuStateTerminated: set upon completion of simulated execution
*/
void setMenuState(int status) {
menuState = status;
switch (status) {
case FileStatus.NO_FILE:
setMenuStateInitial();
break;
case FileStatus.NEW_NOT_EDITED:
setMenuStateEditingNew();
break;
case FileStatus.NEW_EDITED:
setMenuStateEditingNew();
break;
case FileStatus.NOT_EDITED:
setMenuStateNotEdited(); // was MenuStateEditing. DPS 9-Aug-2011
break;
case FileStatus.EDITED:
setMenuStateEditing();
break;
case FileStatus.RUNNABLE:
setMenuStateRunnable();
break;
case FileStatus.RUNNING:
setMenuStateRunning();
break;
case FileStatus.TERMINATED:
setMenuStateTerminated();
break;
case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011
break;
default:
System.out.println("Invalid File Status: "+status);
break;
}
}
void setMenuStateInitial() {
fileNewAction.setEnabled(true);
fileOpenAction.setEnabled(true);
@@ -852,9 +722,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
editRedoAction.updateRedoState();
}
void setMenuStateEditing() {
/* Note: undo and redo are handled separately by the undo manager*/
fileNewAction.setEnabled(true);
@@ -949,9 +816,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
runAssembleAction.setEnabled(true);
runGoAction.setEnabled(true);
runStepAction.setEnabled(true);
runBackstepAction.setEnabled(
(Globals.getSettings().getBackSteppingEnabled()&& !Globals.program.getBackStepper().empty())
? true : false);
runBackstepAction.setEnabled(Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty());
runResetAction.setEnabled(true);
runStopAction.setEnabled(false);
runPauseAction.setEnabled(false);
@@ -996,6 +861,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
editUndoAction.setEnabled(false);//updateUndoState(); // DPS 10 Jan 2008
editRedoAction.setEnabled(false);//updateRedoState(); // DPS 10 Jan 2008
}
/* Use this upon completion of execution
*/
void setMenuStateTerminated() {
@@ -1020,9 +886,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
runAssembleAction.setEnabled(true);
runGoAction.setEnabled(false);
runStepAction.setEnabled(false);
runBackstepAction.setEnabled(
(Globals.getSettings().getBackSteppingEnabled()&& !Globals.program.getBackStepper().empty())
? true : false);
runBackstepAction.setEnabled(Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty());
runResetAction.setEnabled(true);
runStopAction.setEnabled(false);
runPauseAction.setEnabled(false);
@@ -1033,52 +897,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
editRedoAction.updateRedoState();
}
/**
* Get current menu state. State values are constants in FileStatus class. DPS 23 July 2008
* @return current menu state.
**/
public static int getMenuState() {
return menuState;
}
/**
* To set whether the register values are reset.
* @param b Boolean true if the register values have been reset.
**/
public static void setReset(boolean b){
reset=b;
}
/**
* To set whether MIPS program execution has started.
* @param b true if the MIPS program execution has started.
**/
public static void setStarted(boolean b){
started=b;
}
/**
* To find out whether the register values are reset.
* @return Boolean true if the register values have been reset.
**/
public static boolean getReset(){
return reset;
}
/**
* To find out whether MIPS program is currently executing.
* @return true if MIPS program is currently executing.
**/
public static boolean getStarted(){
return started;
}
/**
* Get reference to Editor object associated with this GUI.
*
* @return Editor for the GUI.
**/
@@ -1088,13 +909,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Get reference to messages pane associated with this GUI.
*
* @return MessagesPane object associated with the GUI.
**/
public MainPane getMainPane() {
return mainPane;
} /**
}
/**
* Get reference to messages pane associated with this GUI.
*
* @return MessagesPane object associated with the GUI.
**/
@@ -1104,6 +929,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Get reference to registers pane associated with this GUI.
*
* @return RegistersPane object associated with the GUI.
**/
@@ -1113,6 +939,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Get reference to settings menu item for display base of memory/register values.
*
* @return the menu item
**/
@@ -1122,6 +949,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Get reference to settings menu item for display base of memory/register values.
*
* @return the menu item
**/
@@ -1132,6 +960,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Return reference tothe Run->Assemble item's action. Needed by File->Open in case
* assemble-upon-open flag is set.
*
* @return the Action object for the Run->Assemble operation.
*/
public Action getRunAssembleAction() {
@@ -1147,6 +976,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Send keyboard event to menu for possible processing. DPS 5-4-10
*
* @param evt KeyEvent for menu component to consider for processing.
*/
public void dispatchEventToMenu(KeyEvent evt) {
@@ -1170,5 +1000,4 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
}
}

Some files were not shown because too many files have changed in this diff Show More