Skip to content

Commit

Permalink
add code and data dump functionality in GUI also
Browse files Browse the repository at this point in the history
  • Loading branch information
andrescv committed Jan 14, 2019
1 parent 4e0c9b8 commit 373064e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
8 changes: 6 additions & 2 deletions V-Sim/resources/css/vsim.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
-fx-spacing: 5;
}

#goBtn, #stopBtn, #stepBtn, #backstepBtn, #resetBtn, #dumpBtn, #downBtn, #upBtn {
#goBtn, #stopBtn, #stepBtn, #backstepBtn, #resetBtn, #dumpCodeBtn, #dumpDataBtn, #downBtn, #upBtn {
-fx-cursor: hand;
-fx-font-family: 'Roboto';
-fx-font-weight: bold;
Expand All @@ -328,10 +328,14 @@
-fx-background-color: #ffa000;
}

#dumpBtn {
#dumpCodeBtn {
-fx-background-color: #7b1fa2;
}

#dumpDataBtn {
-fx-background-color: #3949ab;
}

#upBtn {
-fx-background-color: #00897b;
}
Expand Down
15 changes: 12 additions & 3 deletions V-Sim/resources/fxml/Simulator.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<SplitPane dividerPositions="0.62" prefHeight="553.0" prefWidth="837.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vsim.gui.controllers.SimulatorController">
<SplitPane dividerPositions="0.62" prefHeight="624.0" prefWidth="966.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vsim.gui.controllers.SimulatorController">
<items>
<VBox alignment="CENTER" minWidth="520.0" prefHeight="263.0" prefWidth="520.0">
<children>
Expand Down Expand Up @@ -62,11 +62,20 @@
</ImageView>
</graphic>
</JFXButton>
<JFXButton id="dumpBtn" fx:id="dumpBtn" text="Dump">
<JFXButton id="dumpCodeBtn" fx:id="dumpCodeBtn" text="Dump Code">
<graphic>
<ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/icons/dumpBtn.png" />
<Image url="@../img/icons/code.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton id="dumpDataBtn" fx:id="dumpDataBtn" layoutX="491.0" layoutY="10.0" text="Dump Data">
<graphic>
<ImageView fitHeight="24.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/icons/data.png" />
</image>
</ImageView>
</graphic>
Expand Down
Binary file added V-Sim/resources/img/icons/code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added V-Sim/resources/img/icons/data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed V-Sim/resources/img/icons/dumpBtn.png
Binary file not shown.
48 changes: 20 additions & 28 deletions V-Sim/src/vsim/gui/controllers/SimulatorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

package vsim.gui.controllers;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import javafx.application.Platform;
Expand Down Expand Up @@ -83,8 +80,10 @@ public class SimulatorController {
@FXML protected JFXButton backstepBtn;
/** Simulator reset button */
@FXML protected JFXButton resetBtn;
/** Simulator dump button */
@FXML protected JFXButton dumpBtn;
/** Simulator dump code button */
@FXML protected JFXButton dumpCodeBtn;
/** Simulator dump data button */
@FXML protected JFXButton dumpDataBtn;

/** Simulator text segment table view */
@FXML protected TableView<InfoStatement> textTable;
Expand Down Expand Up @@ -344,30 +343,21 @@ protected void clearAllBreakpoints() {
}

/** Dumps generated machine code to a file. */
protected void dump() {
protected void dumpCode() {
FileChooser chooser = new FileChooser();
chooser.setTitle("Dump Machine Code To File");
File file = chooser.showSaveDialog(this.mainController.stage);
if (file != null) {
try {
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
Message.error("the file " + file + " could not be created");
return;
}
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
for (InfoStatement stmt : this.textTable.getItems()) {
bw.write(stmt.getMachineCode().substring(2));
bw.newLine();
}
bw.close();
Message.log("machine code dumped to: " + file);
} catch (IOException e) {
Message.error("the file " + file + " could not be written");
}
}
if (file != null)
Linker.dumpCode(this.debugger.getProgram(), file);
}

/** Dumps static data segment code to a file */
protected void dumpData() {
FileChooser chooser = new FileChooser();
chooser.setTitle("Dump Static Data To File");
File file = chooser.showSaveDialog(this.mainController.stage);
if (file != null)
Linker.dumpData(file);
}

/** Shows Symbol Table tab if SHOW_LABELS setting is set to true. */
Expand Down Expand Up @@ -558,8 +548,10 @@ private void initButtons() {
this.backstepBtn.disableProperty().bind(Bindings.or(Status.EMPTY, Bindings.or(Status.EXIT, Status.RUNNING)));
this.resetBtn.setOnAction(e -> this.reset());
this.resetBtn.disableProperty().bind(Bindings.or(Status.RUNNING, Status.EMPTY));
this.dumpBtn.setOnAction(e -> this.dump());
this.dumpBtn.disableProperty().bind(Status.RUNNING);
this.dumpCodeBtn.setOnAction(e -> this.dumpCode());
this.dumpCodeBtn.disableProperty().bind(Status.RUNNING);
this.dumpDataBtn.setOnAction(e -> this.dumpData());
this.dumpDataBtn.disableProperty().bind(Status.RUNNING);
}

/** This method initializes the text segment table. */
Expand Down
9 changes: 9 additions & 0 deletions V-Sim/src/vsim/simulator/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,15 @@ else if (args[0].equals("reset")) {
Message.warning("unknown command '" + args[0] + "' (ignoring)");
}

/**
* Gets linked program.
*
* @return linked program
*/
public LinkedProgram getProgram() {
return this.program;
}

/**
* This method creates a command line interface that the user can use to interact with the debugger.
*/
Expand Down

0 comments on commit 373064e

Please sign in to comment.