[+] --open option

This commit is contained in:
Hykilpikonna
2022-11-10 19:29:22 -05:00
parent f2cf4805c5
commit 9f45379c56
6 changed files with 42 additions and 91 deletions
+2 -2
View File
@@ -62,7 +62,7 @@ public class Globals
/** /**
* The current MARS version number. Can't wait for "initialize()" call to get it. * 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 * MARS copyright years
@@ -132,7 +132,7 @@ public class Globals
/** /**
* Lock variable used at head of synchronized block to guard MIPS memory and registers * 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. * Flag to determine whether or not to produce internal debugging information.
+23 -69
View File
@@ -8,12 +8,12 @@ import mars.util.Binary
import mars.util.FilenameFinder import mars.util.FilenameFinder
import mars.util.MemoryDump import mars.util.MemoryDump
import mars.venus.VenusUI import mars.venus.VenusUI
import net.sourceforge.argparse4j.ArgumentParsers
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.io.IOException import java.io.IOException
import java.io.PrintStream import java.io.PrintStream
import java.util.* import java.util.*
import javax.swing.SwingUtilities
import kotlin.system.exitProcess 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) (MIT license, http://www.opensource.org/licenses/mit-license.html)
*/ */
/** class MarsLaunch(var args: Array<String>)
* Main takes a number of command line arguments.<br></br> Usage: Mars [options] filename<br></br> Valid options (not case
* sensitive, separate by spaces) are:<br></br> a -- assemble only, do not simulate<br></br> ad -- both a and d<br></br> ae<n>
* -- terminate MARS with integer exit code <n> if an assemble error occurs.<br></br> ascii -- display memory or
* register contents interpreted as ASCII b -- brief - do not display register/memory address along with
* contents<br></br> d -- print debugging statements<br></br> da -- both a and d<br></br> db -- MIPS delayed branching is
* enabled.<br></br> dec -- display memory or register contents in decimal.<br></br> dump -- dump memory contents to file.
* Option has 3 arguments, e.g. <br></br>
* <tt>dump &lt;segment&gt; &lt;format&gt; &lt;file&gt;</tt>. Also supports<br></br>
* an address range (see *m-n* below). Current supported <br></br> segments are <tt>.text</tt> and <tt>.data</tt>.
* Current supported dump formats <br></br> are <tt>Binary</tt>, <tt>HexText</tt>, <tt>BinaryText</tt>.<br></br> h -- display
* help. Use by itself and with no filename hex -- display memory or register contents in hexadecimal
* (default)<br></br> ic -- display count of MIPS basic instructions 'executed'"); mc -- set memory configuration.
* Option has 1 argument, e.g.<br></br>
* <tt>mc &lt;config$gt;</tt>, where &lt;config$gt; is <tt>Default</tt><br></br>
* for the MARS default 32-bit address space, <tt>CompactDataAtZero</tt> for<br></br> a 32KB address space with data
* segment at address 0, or <tt>CompactTextAtZero</tt><br></br> for a 32KB address space with text segment at address
* 0.<br></br> 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).<br></br> p -- Project mode - assemble all files in the same directory as given
* file.<br></br> se<n> -- terminate MARS with integer exit code <n> if a simulation (run) error occurs.<br></br> sm --
* Start execution at Main - Execution will start at program statement globally labeled main.<br></br> smc -- Self
* Modifying Code - Program can write and branch to either text or data segment<br></br> we -- assembler Warnings will
* be considered Errors<br></br>
* <n> -- where <n> is an integer maximum count of steps to simulate.<br></br>
* If 0, negative or not specified, there is no maximum.<br></br> $<reg> -- where <reg> is number or name (e.g. 5, t3,
* f10) of register whose <br></br> content to display at end of run. Option may be repeated.<br></br>
* <reg_name> -- where <reg_name> is name (e.g. t3, f10) of register whose <br></br>
* content to display at end of run. Option may be repeated. $ not required.<br></br>
* <m>-<n> -- memory address range from <m> to <n> whose contents to<br></br>
* display at end of run. <m> and <n> may be hex or decimal,<br></br>
* <m> <= <n>, both must be on word boundary. Option may be repeated.<br></br>
* pa -- Program Arguments follow in a space-separated list. This<br></br> option must be placed AFTER ALL FILE NAMES,
* because everything<br></br> that follows it is interpreted as a program argument to be<br></br> made available to the MIPS
* program at runtime.<br></br></n></m></n></m></n></m></n></m></reg_name></reg_name></reg></reg></n></n></n></n></n></n>
*/
class MarsLaunch(args: Array<String>)
{ {
private var simulate = true private var simulate = true
private var displayFormat = HEXADECIMAL private var displayFormat = HEXADECIMAL
@@ -134,11 +98,27 @@ class MarsLaunch(args: Array<String>)
init 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) Globals.initialize(gui)
if (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 else
{ {
@@ -234,17 +214,6 @@ class MarsLaunch(args: Array<String>)
} }
} }
/////////////////////////////////////////////////////////////////
// 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 // Parse command line arguments. The initial parsing has already been
// done, since each space-separated argument is already in a String array // done, since each space-separated argument is already in a String array
@@ -373,15 +342,6 @@ class MarsLaunch(args: Array<String>)
i++ i++
continue 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)) if (args[i].equals("p", ignoreCase = true))
{ {
assembleProject = true assembleProject = true
@@ -473,7 +433,7 @@ class MarsLaunch(args: Array<String>)
} }
if (File(args[i]).exists()) if (File(args[i]).exists())
{ // is it a file name? { // is it a file name?
filenameList!!.add(args[i]) filenameList.add(args[i])
i++ i++
continue continue
} }
@@ -687,12 +647,7 @@ class MarsLaunch(args: Array<String>)
{ {
if (countInstructions) if (countInstructions)
{ {
out.println( out.println("\n\n$instructionCount")
"""
$instructionCount
""".trimIndent()
)
} }
} }
@@ -701,7 +656,6 @@ class MarsLaunch(args: Array<String>)
private fun displayRegistersPostMortem() private fun displayRegistersPostMortem()
{ {
var value: Int // handy local to use throughout the next couple loops var value: Int // handy local to use throughout the next couple loops
var strValue: String
// Display requested register contents // Display requested register contents
out.println() out.println()
val regIter: Iterator<String> = registerDisplayList.iterator() val regIter: Iterator<String> = registerDisplayList.iterator()
@@ -808,7 +762,7 @@ class MarsLaunch(args: Array<String>)
{ {
var value: Int var value: Int
// Display requested memory range contents // Display requested memory range contents
val memIter: Iterator<String?> = memoryDisplayList!!.iterator() val memIter: Iterator<String?> = memoryDisplayList.iterator()
var addressStart = 0 var addressStart = 0
var addressEnd = 0 var addressEnd = 0
while (memIter.hasNext()) while (memIter.hasNext())
+9 -12
View File
@@ -41,6 +41,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public final class Directives public final class Directives
{ {
private static final ArrayList<Directives> directiveList = new ArrayList<>();
public static final Directives DATA = new Directives(".data", "Subsequent items stored in Data segment at next available address"); 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 */ /* 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."); 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 descriptor;
private final String description; // help text private final String description; // help text
@@ -115,13 +114,11 @@ public final class Directives
public static Directives matchDirective(String str) public static Directives matchDirective(String str)
{ {
Directives match; for (Directives directives : directiveList)
for (int i = 0; i < directiveList.size(); i++)
{ {
match = (Directives) directiveList.get(i); if (str.equalsIgnoreCase(directives.descriptor))
if (str.equalsIgnoreCase(match.descriptor))
{ {
return match; return directives;
} }
} }
return null; return null;
@@ -136,16 +133,16 @@ public final class Directives
* @return If match is found, returns ArrayList of matching Directives objects, else returns <tt>null</tt>. * @return If match is found, returns ArrayList of matching Directives objects, else returns <tt>null</tt>.
**/ **/
public static ArrayList prefixMatchDirectives(String str) public static ArrayList<Directives> prefixMatchDirectives(String str)
{ {
ArrayList matches = null; ArrayList<Directives> matches = null;
for (int i = 0; i < directiveList.size(); i++) 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) if (matches == null)
{ {
matches = new ArrayList(); matches = new ArrayList<>();
} }
matches.add(directiveList.get(i)); matches.add(directiveList.get(i));
} }
@@ -158,7 +155,7 @@ public final class Directives
* *
* @return MIPS Directive * @return MIPS Directive
**/ **/
public static ArrayList getDirectiveList() public static ArrayList<Directives> getDirectiveList()
{ {
return directiveList; return directiveList;
} }
@@ -56,7 +56,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public class InstructionSet public class InstructionSet
{ {
private final ArrayList instructionList; private final ArrayList<Instruction> instructionList;
private ArrayList opcodeMatchMaps; private ArrayList opcodeMatchMaps;
@@ -67,14 +67,14 @@ public class InstructionSet
*/ */
public InstructionSet() public InstructionSet()
{ {
instructionList = new ArrayList(); instructionList = new ArrayList<>();
} }
/** /**
* Retrieve the current instruction set. * Retrieve the current instruction set.
*/ */
public ArrayList getInstructionList() public ArrayList<Instruction> getInstructionList()
{ {
return instructionList; return instructionList;
+1 -1
View File
@@ -47,7 +47,7 @@ public class Editor
private final VenusUI mainUI; private final VenusUI mainUI;
private EditTabbedPane editTabbedPane; public EditTabbedPane editTabbedPane;
private final String mainUIbaseTitle; private final String mainUIbaseTitle;
@@ -101,16 +101,16 @@ public class MIPSTokenMarker extends TokenMarker
{ {
cKeywords = new KeywordMap(false); cKeywords = new KeywordMap(false);
// add Instruction mnemonics // add Instruction mnemonics
java.util.ArrayList instructionSet = mars.Globals.instructionSet.getInstructionList(); ArrayList<Instruction> instructionSet = mars.Globals.instructionSet.getInstructionList();
for (int i = 0; i < instructionSet.size(); i++) 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 // add assembler directives
java.util.ArrayList directiveSet = mars.assembler.Directives.getDirectiveList(); ArrayList<Directives> directiveSet = mars.assembler.Directives.getDirectiveList();
for (int i = 0; i < directiveSet.size(); i++) 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 // add integer register file
mars.mips.hardware.Register[] registerFile = mars.mips.hardware.RegisterFile.getRegisters(); mars.mips.hardware.Register[] registerFile = mars.mips.hardware.RegisterFile.getRegisters();