| 1 | // Copyright © 2004-2006 University of Helsinki, Department of Computer Science | |
| 2 | // Copyright © 2012 various contributors | |
| 3 | // This software is released under GNU Lesser General Public License 2.1. | |
| 4 | // The license text is at http://www.gnu.org/licenses/lgpl-2.1.html | |
| 5 | ||
| 6 | /* Huomautukset: | |
| 7 | Lisäsin metodin public String[][] getSymbolTable() | |
| 8 | */ | |
| 9 | ||
| 10 | package fi.helsinki.cs.titokone; | |
| 11 | ||
| 12 | /** | |
| 13 | * This class provides info about the loading of a program. It has the | |
| 14 | * code area and the data area as a MemoryLine array. The code is in its | |
| 15 | * numeric form as well as a list of symbolic operation codes with comments and | |
| 16 | * symbols in place, if known. LoadInfo also stores the values of FP and | |
| 17 | * SP. | |
| 18 | */ | |
| 19 | public class LoadInfo extends DebugInfo { | |
| 20 | /** | |
| 21 | * This field contains the contents of the code area after the loading | |
| 22 | * is complete. | |
| 23 | */ | |
| 24 | private MemoryLine[] codeArea; | |
| 25 | ||
| 26 | /** | |
| 27 | * This field contains the symbotable | |
| 28 | */ | |
| 29 | private SymbolTable symbolTable; | |
| 30 | ||
| 31 | ||
| 32 | /** | |
| 33 | * This field contains the contents of the data area after the loading | |
| 34 | * is complete. | |
| 35 | */ | |
| 36 | private MemoryLine[] dataArea; | |
| 37 | /** | |
| 38 | * This field contains the value to be stored to the SP register. | |
| 39 | */ | |
| 40 | private int initSP; | |
| 41 | /** | |
| 42 | * This field contains the value to be stored to the FP register. | |
| 43 | */ | |
| 44 | private int initFP; | |
| 45 | /** This fiels stores the status message to be shown to user in GUI. */ | |
| 46 | //private String statusMessage; | |
| 47 | ||
| 48 | /** | |
| 49 | * @param codeArea Has the opcodes as MemoryLine array. | |
| 50 | * @param dataArea Has the data part as MemoryLine array. | |
| 51 | * @param symbolTable Contains the symboltable. | |
| 52 | * @param initSP The initial value of SP. | |
| 53 | * @param initFP The initial value of FP. | |
| 54 | * @param statusMessage Message to GUI to be displayed at the status bar. | |
| 55 | */ | |
| 56 | public LoadInfo(MemoryLine[] codeArea, MemoryLine[] dataArea, | |
| 57 | SymbolTable symbolTable, int initSP, int initFP, | |
| 58 | String statusMessage) { | |
| 59 | ||
| 60 | 1 | this.codeArea = codeArea; |
| 61 | 1 | this.dataArea = dataArea; |
| 62 | 1 | this.symbolTable = symbolTable; |
| 63 | 1 | this.initSP = initSP; |
| 64 | 1 | this.initFP = initFP; |
| 65 | 1 | setStatusMessage(statusMessage); // Defined in DebugInfo. |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * @return String array that contains the symbolic operation codes. | |
| 70 | */ | |
| 71 | public String[] getSymbolicCommands() { | |
| 72 | String[] retString = new String[codeArea.length]; | |
| 73 | 5 | for (int i = 0; i < codeArea.length; i++) { |
| 74 | 1 | retString[i] = codeArea[i].getSymbolic(); |
| 75 | } | |
| 76 | 1 | return retString; |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * @return Int array that contains operation codes in their numeric form. | |
| 81 | */ | |
| 82 | public int[] getBinaryCommands() { | |
| 83 | int[] retInt = new int[codeArea.length]; | |
| 84 | 5 | for (int i = 0; i < codeArea.length; i++) { |
| 85 | 1 | retInt[i] = codeArea[i].getBinary(); |
| 86 | } | |
| 87 | 1 | return retInt; |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * @return Int array that contains the data segment of a program in memory. | |
| 92 | */ | |
| 93 | public int[] getData() { | |
| 94 | int[] retInt = new int[dataArea.length]; | |
| 95 | 5 | for (int i = 0; i < dataArea.length; i++) { |
| 96 | 1 | retInt[i] = dataArea[i].getBinary(); |
| 97 | } | |
| 98 | 1 | return retInt; |
| 99 | } | |
| 100 | ||
| 101 | ||
| 102 | /** | |
| 103 | * @return String array that contains the initial data segment of a | |
| 104 | * program in memory as symbolic commands. | |
| 105 | */ | |
| 106 | public String[] getDataSymbolic() { | |
| 107 | String[] retStr = new String[dataArea.length]; | |
| 108 | 5 | for (int i = 0; i < dataArea.length; i++) { |
| 109 | 1 | retStr[i] = dataArea[i].getSymbolic(); |
| 110 | } | |
| 111 | 1 | return retStr; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * @return A string arary containing only the initial data area | |
| 116 | * of the program. getDataSymbolic returns the entire memory minus | |
| 117 | * the code area. The length is max{initSP - initFP, 0}. | |
| 118 | */ | |
| 119 | public String[] getDataAreaSymbolic() { | |
| 120 | String[] retStr; | |
| 121 | 1 | int dataAreaLength = initSP - initFP; |
| 122 | 2 | if (dataAreaLength < 0) { |
| 123 | 2 | dataAreaLength = 0; |
| 124 | } | |
| 125 | retStr = new String[dataAreaLength]; | |
| 126 | 5 | for (int i = 0; i < retStr.length; i++) { |
| 127 | 1 | retStr[i] = dataArea[i].getSymbolic(); |
| 128 | } | |
| 129 | 1 | return retStr; |
| 130 | } | |
| 131 | ||
| 132 | public String[][] getSymbolTable() { | |
| 133 | 1 | String[] symbols = symbolTable.getAllSymbols(); |
| 134 | 2 | String[][] symbolsValues = new String[symbols.length][2]; |
| 135 | 5 | for (int i = 0; i < symbols.length; i++) { |
| 136 | 2 | symbolsValues[i][0] = symbols[i]; |
| 137 | 7 | symbolsValues[i][1] = "" + symbolTable.getSymbol(symbols[i]); |
| 138 | } | |
| 139 | 1 | return symbolsValues; |
| 140 | } | |
| 141 | ||
| 142 | ||
| 143 | /** | |
| 144 | * @return The value of the Stack pointer (SP) after the program is loaded into memory. | |
| 145 | */ | |
| 146 | public int getSP() { | |
| 147 | 1 | return initSP; |
| 148 | } | |
| 149 | ||
| 150 | /** | |
| 151 | * @return The value of the Frame pointer (FP) after the program is loaded into memory. | |
| 152 | */ | |
| 153 | public int getFP() { | |
| 154 | 1 | return initFP; |
| 155 | } | |
| 156 | ||
| 157 | /**@return The message for GUI to be displayed at the status bar. | |
| 158 | */ | |
| 159 | /*public String getStatusMessage() { | |
| 160 | return statusMessage; | |
| 161 | //This is not needed, because DebugInfo already implements it. | |
| 162 | }*/ | |
| 163 | ||
| 164 | } | |
Mutations | ||
| 60 |
Removed assignment to member variable codeArea : SURVIVED |
|
| 61 |
Removed assignment to member variable dataArea : SURVIVED |
|
| 62 |
Removed assignment to member variable symbolTable : SURVIVED |
|
| 63 |
Removed assignment to member variable initSP : SURVIVED |
|
| 64 |
Removed assignment to member variable initFP : SURVIVED |
|
| 65 |
removed call to fi/helsinki/cs/titokone/LoadInfo::setStatusMessage : SURVIVED |
|
| 73 |
Substituted 0 with 1 : NO_COVERAGE Changed increment from 1 to -1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE negated conditional : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 74 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getSymbolic : NO_COVERAGE |
|
| 76 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getSymbolicCommands to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 84 |
negated conditional : NO_COVERAGE Changed increment from 1 to -1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 85 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : NO_COVERAGE |
|
| 87 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getBinaryCommands to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 95 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE negated conditional : NO_COVERAGE Changed increment from 1 to -1 : NO_COVERAGE |
|
| 96 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : NO_COVERAGE |
|
| 98 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getData to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 108 |
Changed increment from 1 to -1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 109 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getSymbolic : NO_COVERAGE |
|
| 111 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getDataSymbolic to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 121 |
Replaced integer subtraction with addition : NO_COVERAGE |
|
| 122 |
changed conditional boundary : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 123 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 126 |
Substituted 0 with 1 : NO_COVERAGE negated conditional : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE Changed increment from 1 to -1 : NO_COVERAGE |
|
| 127 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getSymbolic : NO_COVERAGE |
|
| 129 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getDataAreaSymbolic to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 133 |
removed call to fi/helsinki/cs/titokone/SymbolTable::getAllSymbols : NO_COVERAGE |
|
| 134 |
Substituted 2 with 3 : NO_COVERAGE Substituted 2 with 3 : NO_COVERAGE |
|
| 135 |
Substituted 0 with 1 : NO_COVERAGE Changed increment from 1 to -1 : NO_COVERAGE negated conditional : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE changed conditional boundary : NO_COVERAGE |
|
| 136 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 137 |
removed call to java/lang/StringBuilder::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to fi/helsinki/cs/titokone/SymbolTable::getSymbol : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 139 |
mutated return of Object value for fi/helsinki/cs/titokone/LoadInfo::getSymbolTable to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 147 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 154 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |