| 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 | package fi.helsinki.cs.titokone; | |
| 7 | ||
| 8 | import fi.helsinki.cs.ttk91.TTK91Cpu; | |
| 9 | ||
| 10 | /** | |
| 11 | * This data class contains all the register information. The registers | |
| 12 | * are accessed via index numbers which are defined in the TTK91CPU | |
| 13 | * interface. | |
| 14 | */ | |
| 15 | public class Registers { | |
| 16 | /** | |
| 17 | * This field contains the register values. 0..7 are general-purpose | |
| 18 | * registers, 8..12 are CU registers. | |
| 19 | */ | |
| 20 | 3 | private int[] registerValues = new int[13]; |
| 21 | ||
| 22 | /** | |
| 23 | * Returns the value of a register. The index numbers | |
| 24 | * are available from the TTK91CPU interface. | |
| 25 | * | |
| 26 | * @param registerId Identifying number of the register. | |
| 27 | * @return Value stored in the register. | |
| 28 | */ | |
| 29 | public int getRegister(int registerId) { | |
| 30 | 1 | int index = getIndex(registerId); |
| 31 | 3 | if (index != -1) { |
| 32 | 1 | return registerValues[index]; |
| 33 | } else { | |
| 34 | 7 | throw new IllegalArgumentException(new Message("Unknown registerId: {0}", |
| 35 | "" + registerId).toString()); | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Returns the value of a register. | |
| 41 | * | |
| 42 | * @param registerName The name of the register. | |
| 43 | * @return Value stored in the register. | |
| 44 | */ | |
| 45 | public int getRegister(String registerName) { | |
| 46 | 1 | int index = getIndex(registerName); |
| 47 | 3 | if (index != -1) { |
| 48 | 1 | return registerValues[index]; |
| 49 | } else { | |
| 50 | 7 | throw new IllegalArgumentException(new Message("Unknown registerName: {0}", |
| 51 | "" + registerName).toString()); | |
| 52 | } | |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Sets a new value to a register. | |
| 57 | * | |
| 58 | * @param registerId The identifying number of the register. | |
| 59 | * @param value New value to set. | |
| 60 | */ | |
| 61 | public void setRegister(int registerId, int value) { | |
| 62 | 1 | int index = getIndex(registerId); |
| 63 | 3 | if (index != -1) { |
| 64 | registerValues[index] = value; | |
| 65 | } else { | |
| 66 | 7 | throw new IllegalArgumentException(new Message("Unknown registerId: {0}", |
| 67 | "" + registerId).toString()); | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Sets a new value to a register. | |
| 73 | * | |
| 74 | * @param registerName The name of the register. | |
| 75 | * @param value New value to set. | |
| 76 | */ | |
| 77 | public void setRegister(String registerName, int value) { | |
| 78 | 1 | int index = getIndex(registerName); |
| 79 | 3 | if (index != -1) { |
| 80 | registerValues[index] = value; | |
| 81 | } else { | |
| 82 | 7 | throw new IllegalArgumentException(new Message("Unknown registerName: {0}", |
| 83 | "" + registerName).toString()); | |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Converts TTK91Cpu register to the corresponding index to registerValues array. | |
| 89 | * | |
| 90 | * @param TTK91Cpu_index Register index in TTK91Cpu notation | |
| 91 | * @return Index to registerValues array. Returns -1 if register | |
| 92 | * does not exists in TTK91Cpu. | |
| 93 | */ | |
| 94 | private int getIndex(int TTK91Cpu_index) { | |
| 95 | switch (TTK91Cpu_index) { | |
| 96 | case TTK91Cpu.REG_R0: | |
| 97 | 3 | return 0; |
| 98 | case TTK91Cpu.REG_R1: | |
| 99 | 3 | return 1; |
| 100 | case TTK91Cpu.REG_R2: | |
| 101 | 3 | return 2; |
| 102 | case TTK91Cpu.REG_R3: | |
| 103 | 3 | return 3; |
| 104 | case TTK91Cpu.REG_R4: | |
| 105 | 3 | return 4; |
| 106 | case TTK91Cpu.REG_R5: | |
| 107 | 3 | return 5; |
| 108 | case TTK91Cpu.REG_R6: | |
| 109 | 3 | return 6; |
| 110 | case TTK91Cpu.REG_R7: | |
| 111 | 3 | return 7; |
| 112 | case TTK91Cpu.CU_TR: | |
| 113 | 3 | return 8; |
| 114 | case TTK91Cpu.CU_IR: | |
| 115 | 3 | return 9; |
| 116 | case TTK91Cpu.CU_PC: | |
| 117 | 3 | return 10; |
| 118 | case TTK91Cpu.CU_PC_CURRENT: | |
| 119 | 3 | return 11; |
| 120 | case TTK91Cpu.CU_SR: | |
| 121 | 3 | return 12; |
| 122 | default: | |
| 123 | 3 | return -1; |
| 124 | } | |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Converts given String to the corresponding index to registerValues array. | |
| 129 | * | |
| 130 | * @param registerName The name of the register. | |
| 131 | * @return Index to registerValues array. Returns -1 if register | |
| 132 | * does not exists. | |
| 133 | */ | |
| 134 | private int getIndex(String registerName) { | |
| 135 | 1 | if (registerName == null) { |
| 136 | 3 | return -1; |
| 137 | } | |
| 138 | 2 | String str = registerName.toUpperCase().trim(); |
| 139 | 2 | if (str.equals("R0")) { |
| 140 | 3 | return 0; |
| 141 | } | |
| 142 | 2 | if (str.equals("R1")) { |
| 143 | 3 | return 1; |
| 144 | } | |
| 145 | 2 | if (str.equals("R2")) { |
| 146 | 3 | return 2; |
| 147 | } | |
| 148 | 2 | if (str.equals("R3")) { |
| 149 | 3 | return 3; |
| 150 | } | |
| 151 | 2 | if (str.equals("R4")) { |
| 152 | 3 | return 4; |
| 153 | } | |
| 154 | 2 | if (str.equals("R5")) { |
| 155 | 3 | return 5; |
| 156 | } | |
| 157 | 2 | if (str.equals("R6")) { |
| 158 | 3 | return 6; |
| 159 | } | |
| 160 | 2 | if (str.equals("R7")) { |
| 161 | 3 | return 7; |
| 162 | } | |
| 163 | 2 | if (str.equals("SP")) { |
| 164 | 3 | return 6; |
| 165 | } | |
| 166 | 2 | if (str.equals("FP")) { |
| 167 | 3 | return 7; |
| 168 | } | |
| 169 | 2 | if (str.equals("TR")) { |
| 170 | 3 | return 8; |
| 171 | } | |
| 172 | 2 | if (str.equals("IR")) { |
| 173 | 3 | return 9; |
| 174 | } | |
| 175 | 2 | if (str.equals("PC")) { |
| 176 | 3 | return 10; |
| 177 | } | |
| 178 | 2 | if (str.equals("PC_CURRENT")) { |
| 179 | 3 | return 11; |
| 180 | } | |
| 181 | 2 | if (str.equals("SR")) { |
| 182 | 3 | return 12; |
| 183 | } | |
| 184 | 3 | return -1; |
| 185 | } | |
| 186 | } | |
Mutations | ||
| 20 |
Removed assignment to member variable registerValues : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 13 with 14 : SURVIVED Replaced constant value of 13 with 14 : SURVIVED |
|
| 30 |
removed call to fi/helsinki/cs/titokone/Registers::getIndex : SURVIVED |
|
| 31 |
Substituted -1 with 1 : SURVIVED Substituted -1 with 0 : SURVIVED negated conditional : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 32 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED |
|
| 34 |
removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE |
|
| 46 |
removed call to fi/helsinki/cs/titokone/Registers::getIndex : NO_COVERAGE |
|
| 47 |
Substituted -1 with 1 : NO_COVERAGE negated conditional : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE |
|
| 48 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 50 |
removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE |
|
| 62 |
removed call to fi/helsinki/cs/titokone/Registers::getIndex : SURVIVED |
|
| 63 |
negated conditional : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted -1 with 0 : SURVIVED Substituted -1 with 1 : SURVIVED |
|
| 66 |
removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE |
|
| 78 |
removed call to fi/helsinki/cs/titokone/Registers::getIndex : NO_COVERAGE |
|
| 79 |
Substituted -1 with 1 : NO_COVERAGE negated conditional : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE |
|
| 82 |
removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE removed call to java/lang/StringBuilder::toString : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE removed call to java/lang/StringBuilder::<init> : NO_COVERAGE removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE removed call to java/lang/StringBuilder::append : NO_COVERAGE |
|
| 97 |
Substituted 0 with 1 : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 99 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 101 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 2 with 3 : NO_COVERAGE Substituted 2 with 3 : NO_COVERAGE |
|
| 103 |
Substituted 3 with 4 : NO_COVERAGE Substituted 3 with 4 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 105 |
Substituted 4 with 5 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 4 with 5 : NO_COVERAGE |
|
| 107 |
Substituted 5 with 6 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 5 with -1 : NO_COVERAGE |
|
| 109 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED Substituted 6 with 7 : SURVIVED Replaced constant value of 6 with 7 : SURVIVED |
|
| 111 |
Replaced constant value of 7 with 8 : SURVIVED replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED Substituted 7 with 8 : SURVIVED |
|
| 113 |
Replaced constant value of 8 with 9 : NO_COVERAGE Substituted 8 with 9 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 115 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 9 with 10 : NO_COVERAGE Substituted 9 with 10 : NO_COVERAGE |
|
| 117 |
Replaced constant value of 10 with 11 : SURVIVED Substituted 10 with 11 : SURVIVED replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED |
|
| 119 |
Substituted 11 with 12 : SURVIVED Replaced constant value of 11 with 12 : SURVIVED replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED |
|
| 121 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 12 with 13 : NO_COVERAGE Substituted 12 with 13 : NO_COVERAGE |
|
| 123 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE Substituted -1 with 1 : NO_COVERAGE |
|
| 135 |
negated conditional : NO_COVERAGE |
|
| 136 |
Substituted -1 with 1 : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 138 |
removed call to java/lang/String::trim : NO_COVERAGE removed call to java/lang/String::toUpperCase : NO_COVERAGE |
|
| 139 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 140 |
Substituted 0 with 1 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 0 with 1 : NO_COVERAGE |
|
| 142 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 143 |
Substituted 1 with 0 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 145 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 146 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 2 with 3 : NO_COVERAGE Substituted 2 with 3 : NO_COVERAGE |
|
| 148 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 149 |
Substituted 3 with 4 : NO_COVERAGE Substituted 3 with 4 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 151 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 152 |
Substituted 4 with 5 : NO_COVERAGE Substituted 4 with 5 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 154 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 155 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 5 with -1 : NO_COVERAGE Substituted 5 with 6 : NO_COVERAGE |
|
| 157 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 158 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 6 with 7 : NO_COVERAGE Substituted 6 with 7 : NO_COVERAGE |
|
| 160 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 161 |
Substituted 7 with 8 : NO_COVERAGE Replaced constant value of 7 with 8 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 163 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 164 |
Substituted 6 with 7 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 6 with 7 : NO_COVERAGE |
|
| 166 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 167 |
Substituted 7 with 8 : NO_COVERAGE Replaced constant value of 7 with 8 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 169 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 170 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 8 with 9 : NO_COVERAGE Replaced constant value of 8 with 9 : NO_COVERAGE |
|
| 172 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 173 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 9 with 10 : NO_COVERAGE Substituted 9 with 10 : NO_COVERAGE |
|
| 175 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 176 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 10 with 11 : NO_COVERAGE Replaced constant value of 10 with 11 : NO_COVERAGE |
|
| 178 |
removed call to java/lang/String::equals : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 179 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted 11 with 12 : NO_COVERAGE Replaced constant value of 11 with 12 : NO_COVERAGE |
|
| 181 |
negated conditional : NO_COVERAGE removed call to java/lang/String::equals : NO_COVERAGE |
|
| 182 |
Substituted 12 with 13 : NO_COVERAGE replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Replaced constant value of 12 with 13 : NO_COVERAGE |
|
| 184 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE Substituted -1 with 0 : NO_COVERAGE Substituted -1 with 1 : NO_COVERAGE |