diff --git a/src/main/java/mars/Globals.java b/src/main/java/mars/Globals.java index a80be05..e6e63d3 100644 --- a/src/main/java/mars/Globals.java +++ b/src/main/java/mars/Globals.java @@ -62,7 +62,7 @@ public class Globals /** * The current MARS version number. Can't wait for "initialize()" call to get it. */ - public static final String version = "4.5"; + public static final String version = "4.7"; /** * MARS copyright years @@ -132,7 +132,7 @@ public class Globals /** * Lock variable used at head of synchronized block to guard MIPS memory and registers **/ - public static Object memoryAndRegistersLock = new Object(); + public static final Object memoryAndRegistersLock = new Object(); /** * Flag to determine whether or not to produce internal debugging information. diff --git a/src/main/java/mars/MarsLaunch.kt b/src/main/java/mars/MarsLaunch.kt index 9bee9b7..976d411 100644 --- a/src/main/java/mars/MarsLaunch.kt +++ b/src/main/java/mars/MarsLaunch.kt @@ -8,12 +8,12 @@ import mars.util.Binary import mars.util.FilenameFinder import mars.util.MemoryDump import mars.venus.VenusUI +import net.sourceforge.argparse4j.ArgumentParsers import java.io.File import java.io.FileNotFoundException import java.io.IOException import java.io.PrintStream import java.util.* -import javax.swing.SwingUtilities import kotlin.system.exitProcess /* @@ -43,43 +43,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (MIT license, http://www.opensource.org/licenses/mit-license.html) */ -/** - * Main takes a number of command line arguments.

Usage: Mars [options] filename

Valid options (not case - * sensitive, separate by spaces) are:

a -- assemble only, do not simulate

ad -- both a and d

ae - * -- terminate MARS with integer exit code if an assemble error occurs.

ascii -- display memory or - * register contents interpreted as ASCII b -- brief - do not display register/memory address along with - * contents

d -- print debugging statements

da -- both a and d

db -- MIPS delayed branching is - * enabled.

dec -- display memory or register contents in decimal.

dump -- dump memory contents to file. - * Option has 3 arguments, e.g.

- * dump <segment> <format> <file>. Also supports

- * an address range (see *m-n* below). Current supported

segments are .text and .data. - * Current supported dump formats

are Binary, HexText, BinaryText.

h -- display - * help. Use by itself and with no filename hex -- display memory or register contents in hexadecimal - * (default)

ic -- display count of MIPS basic instructions 'executed'"); mc -- set memory configuration. - * Option has 1 argument, e.g.

- * mc <config$gt;, where <config$gt; is Default

- * for the MARS default 32-bit address space, CompactDataAtZero for

a 32KB address space with data - * segment at address 0, or CompactTextAtZero

for a 32KB address space with text segment at address - * 0.

me -- display MARS messages to standard err instead of standard out. Can separate via redirection. - * nc -- do not display copyright notice (for cleaner redirected/piped output). np -- No Pseudo-instructions - * allowed ("ne" will work also).

p -- Project mode - assemble all files in the same directory as given - * file.

se -- terminate MARS with integer exit code if a simulation (run) error occurs.

sm -- - * Start execution at Main - Execution will start at program statement globally labeled main.

smc -- Self - * Modifying Code - Program can write and branch to either text or data segment

we -- assembler Warnings will - * be considered Errors

- * -- where is an integer maximum count of steps to simulate.

- * If 0, negative or not specified, there is no maximum.

$ -- where is number or name (e.g. 5, t3, - * f10) of register whose

content to display at end of run. Option may be repeated.

- * -- where is name (e.g. t3, f10) of register whose

- * content to display at end of run. Option may be repeated. $ not required.

- * - -- memory address range from to whose contents to

- * display at end of run. and may be hex or decimal,

- * <= , both must be on word boundary. Option may be repeated.

- * pa -- Program Arguments follow in a space-separated list. This

option must be placed AFTER ALL FILE NAMES, - * because everything

that follows it is interpreted as a program argument to be

made available to the MIPS - * program at runtime.

- */ -class MarsLaunch(args: Array) +class MarsLaunch(var args: Array) { private var simulate = true private var displayFormat = HEXADECIMAL @@ -134,11 +98,27 @@ class MarsLaunch(args: Array) init { - val gui = args.isEmpty() + // Start gui if "cmd" argument is not specified + val gui = !args.contains("cmd") + args = args.filter { it != "cmd" }.toTypedArray() + Globals.initialize(gui) if (gui) { - launchIDE() + val p = ArgumentParsers.newFor("E-MARS GUI Arguments").build() + .defaultHelp(true) + .description("GUI Arguments for Azalea's Extended-MARS. Add 'cmd' argument for command-line usage") + + val open by p.string("-o", "--open", help = "Open a file on start") + val runOnOpen by p.flag("--run-on-open", help = "Assemble and run a file when it's opened") + p.parseToVars(args) + + // Start IDE + val ui = VenusUI("MARS " + Globals.version) + + open?.let { + ui.editor.editTabbedPane.openFile(File(it)) + } } else { @@ -234,17 +214,6 @@ class MarsLaunch(args: Array) } } - ///////////////////////////////////////////////////////////////// - // There are no command arguments, so run in interactive mode by - // launching the GUI-fronted integrated development environment. - private fun launchIDE() - { - SwingUtilities.invokeLater { // Turn off metal's use of bold fonts - // UIManager.put("swing.boldMetal", Boolean.FALSE); - VenusUI("MARS " + Globals.version) - } - } - ////////////////////////////////////////////////////////////////////// // Parse command line arguments. The initial parsing has already been // done, since each space-separated argument is already in a String array @@ -373,15 +342,6 @@ class MarsLaunch(args: Array) i++ continue } - if (args[i].equals("ad", ignoreCase = true) || - args[i].equals("da", ignoreCase = true) - ) - { - Globals.debug = true - simulate = false - i++ - continue - } if (args[i].equals("p", ignoreCase = true)) { assembleProject = true @@ -473,7 +433,7 @@ class MarsLaunch(args: Array) } if (File(args[i]).exists()) { // is it a file name? - filenameList!!.add(args[i]) + filenameList.add(args[i]) i++ continue } @@ -687,12 +647,7 @@ class MarsLaunch(args: Array) { if (countInstructions) { - out.println( - """ - - $instructionCount - """.trimIndent() - ) + out.println("\n\n$instructionCount") } } @@ -701,7 +656,6 @@ class MarsLaunch(args: Array) private fun displayRegistersPostMortem() { var value: Int // handy local to use throughout the next couple loops - var strValue: String // Display requested register contents out.println() val regIter: Iterator = registerDisplayList.iterator() @@ -808,7 +762,7 @@ class MarsLaunch(args: Array) { var value: Int // Display requested memory range contents - val memIter: Iterator = memoryDisplayList!!.iterator() + val memIter: Iterator = memoryDisplayList.iterator() var addressStart = 0 var addressEnd = 0 while (memIter.hasNext()) diff --git a/src/main/java/mars/assembler/Directives.java b/src/main/java/mars/assembler/Directives.java index 4817d86..c9ed7c2 100644 --- a/src/main/java/mars/assembler/Directives.java +++ b/src/main/java/mars/assembler/Directives.java @@ -41,6 +41,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. public final class Directives { + private static final ArrayList directiveList = new ArrayList<>(); public static final Directives DATA = new Directives(".data", "Subsequent items stored in Data segment at next available address"); @@ -85,8 +86,6 @@ public final class Directives /* INCLUDE added by DPS 11 Jan 2013 */ public static final Directives INCLUDE = new Directives(".include", "Insert the contents of the specified file. Put filename in quotes."); - private static final ArrayList directiveList = new ArrayList(); - private final String descriptor; private final String description; // help text @@ -115,13 +114,11 @@ public final class Directives public static Directives matchDirective(String str) { - Directives match; - for (int i = 0; i < directiveList.size(); i++) + for (Directives directives : directiveList) { - match = (Directives) directiveList.get(i); - if (str.equalsIgnoreCase(match.descriptor)) + if (str.equalsIgnoreCase(directives.descriptor)) { - return match; + return directives; } } return null; @@ -136,16 +133,16 @@ public final class Directives * @return If match is found, returns ArrayList of matching Directives objects, else returns null. **/ - public static ArrayList prefixMatchDirectives(String str) + public static ArrayList prefixMatchDirectives(String str) { - ArrayList matches = null; + ArrayList matches = null; for (int i = 0; i < directiveList.size(); i++) { - if (((Directives) directiveList.get(i)).descriptor.toLowerCase().startsWith(str.toLowerCase())) + if (directiveList.get(i).descriptor.toLowerCase().startsWith(str.toLowerCase())) { if (matches == null) { - matches = new ArrayList(); + matches = new ArrayList<>(); } matches.add(directiveList.get(i)); } @@ -158,7 +155,7 @@ public final class Directives * * @return MIPS Directive **/ - public static ArrayList getDirectiveList() + public static ArrayList getDirectiveList() { return directiveList; } diff --git a/src/main/java/mars/mips/instructions/InstructionSet.java b/src/main/java/mars/mips/instructions/InstructionSet.java index 19b62f7..341658b 100644 --- a/src/main/java/mars/mips/instructions/InstructionSet.java +++ b/src/main/java/mars/mips/instructions/InstructionSet.java @@ -56,7 +56,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. public class InstructionSet { - private final ArrayList instructionList; + private final ArrayList instructionList; private ArrayList opcodeMatchMaps; @@ -67,14 +67,14 @@ public class InstructionSet */ public InstructionSet() { - instructionList = new ArrayList(); + instructionList = new ArrayList<>(); } /** * Retrieve the current instruction set. */ - public ArrayList getInstructionList() + public ArrayList getInstructionList() { return instructionList; diff --git a/src/main/java/mars/venus/Editor.java b/src/main/java/mars/venus/Editor.java index ab5dc26..b99d473 100644 --- a/src/main/java/mars/venus/Editor.java +++ b/src/main/java/mars/venus/Editor.java @@ -47,7 +47,7 @@ public class Editor private final VenusUI mainUI; - private EditTabbedPane editTabbedPane; + public EditTabbedPane editTabbedPane; private final String mainUIbaseTitle; diff --git a/src/main/java/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java b/src/main/java/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java index 64a603b..4229f60 100644 --- a/src/main/java/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java +++ b/src/main/java/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java @@ -101,16 +101,16 @@ public class MIPSTokenMarker extends TokenMarker { cKeywords = new KeywordMap(false); // add Instruction mnemonics - java.util.ArrayList instructionSet = mars.Globals.instructionSet.getInstructionList(); + ArrayList instructionSet = mars.Globals.instructionSet.getInstructionList(); for (int i = 0; i < instructionSet.size(); i++) { - cKeywords.add(((mars.mips.instructions.Instruction) instructionSet.get(i)).getName(), Token.KEYWORD1); + cKeywords.add(instructionSet.get(i).getName(), Token.KEYWORD1); } // add assembler directives - java.util.ArrayList directiveSet = mars.assembler.Directives.getDirectiveList(); + ArrayList directiveSet = mars.assembler.Directives.getDirectiveList(); for (int i = 0; i < directiveSet.size(); i++) { - cKeywords.add(((mars.assembler.Directives) directiveSet.get(i)).getName(), Token.KEYWORD2); + cKeywords.add(directiveSet.get(i).getName(), Token.KEYWORD2); } // add integer register file mars.mips.hardware.Register[] registerFile = mars.mips.hardware.RegisterFile.getRegisters();