| 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.TTK91AddressOutOfBounds; | |
| 9 | ||
| 10 | /** | |
| 11 | * This class can load a TTK91Application. It changes the processor | |
| 12 | * state accordingly. Everything is loaded when loadApplication is | |
| 13 | * called. Function returns the state of memory after loading. If it | |
| 14 | * runs out of memory it throws a TTK91AddressOutOfBounds exception. | |
| 15 | */ | |
| 16 | public class Loader { | |
| 17 | ||
| 18 | /** | |
| 19 | * This variable holds the current application to be loaded. | |
| 20 | */ | |
| 21 | private Application application; | |
| 22 | ||
| 23 | ||
| 24 | private Processor processor; | |
| 25 | ||
| 26 | private BinaryInterpreter binInterpreter; | |
| 27 | ||
| 28 | public Loader(Processor processor) { | |
| 29 | String errorMessage; | |
| 30 | 1 | if (processor == null) { |
| 31 | 3 | errorMessage = new Message("Null is an invalid parameter," + |
| 32 | " instance of {0} required.", | |
| 33 | Processor.class.getName()).toString(); | |
| 34 | 1 | throw new IllegalArgumentException(errorMessage); |
| 35 | } | |
| 36 | 1 | this.processor = processor; |
| 37 | 2 | binInterpreter = new BinaryInterpreter(); |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * You can set the file to load. Each time an application is set to load, the counter is set to | |
| 42 | * one. | |
| 43 | */ | |
| 44 | public void setApplicationToLoad(Application application) { | |
| 45 | String errorMessage; | |
| 46 | 1 | if (application == null) { |
| 47 | 3 | errorMessage = new Message("Null is an invalid parameter," + |
| 48 | " instance of {0} required.", | |
| 49 | Application.class.getName()).toString(); | |
| 50 | 1 | throw new IllegalArgumentException(errorMessage); |
| 51 | } | |
| 52 | 1 | this.application = application; |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Loads an application to memory. LoadInfo contains all the needed information about the process. | |
| 57 | * | |
| 58 | * @return Info from the load procedure, null if no application has been set for loading. | |
| 59 | */ | |
| 60 | public LoadInfo loadApplication() throws TTK91AddressOutOfBounds { | |
| 61 | int bin; | |
| 62 | 2 | String[] messageParameters = new String[2]; |
| 63 | 1 | if (application == null) { |
| 64 | 1 | return null; |
| 65 | } | |
| 66 | ||
| 67 | 1 | MemoryLine[] code = application.getCode(); |
| 68 | 1 | MemoryLine[] data = application.getInitialData(); |
| 69 | // Add the symbolic values for the initial data area. | |
| 70 | 5 | for (int i = 0; i < data.length; i++) { |
| 71 | 3 | if (data[i].getSymbolic().equals("")) { |
| 72 | 1 | bin = data[i].getBinary(); |
| 73 | 2 | data[i] = new MemoryLine(bin, binInterpreter.binaryToString(bin)); |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | 3 | int FP = code.length - 1; |
| 78 | 4 | int SP = code.length + data.length - 1; |
| 79 | ||
| 80 | int i; | |
| 81 | 5 | for (i = 0; i < code.length; i++) { |
| 82 | 1 | processor.memoryInput(i, code[i]); //May throw TTK91AddressOutOfBounds, but it's just thrown |
| 83 | } //backwards | |
| 84 | ||
| 85 | 5 | for (int j = 0; j < data.length; j++) { |
| 86 | 2 | processor.memoryInput(i + j, data[j]); //May throw TTK91AddressOutOfBounds, but it's just thrown |
| 87 | } //backwards | |
| 88 | ||
| 89 | 6 | messageParameters[0] = "" + FP; |
| 90 | 6 | messageParameters[1] = "" + SP; |
| 91 | ||
| 92 | 2 | MemoryLine[] wholeMemoryDump = ((RandomAccessMemory) processor.getPhysicalMemory()).getMemoryLines(); |
| 93 | 1 | int wholeDataAreaLength = wholeMemoryDump.length - code.length; |
| 94 | MemoryLine[] wholeDataArea = new MemoryLine[wholeDataAreaLength]; | |
| 95 | ||
| 96 | 5 | for (int k = 0; k < wholeDataAreaLength; k++) { |
| 97 | 1 | wholeDataArea[k] = wholeMemoryDump[code.length + k]; |
| 98 | } | |
| 99 | ||
| 100 | ||
| 101 | 4 | LoadInfo retValue = new LoadInfo(code, |
| 102 | wholeDataArea, | |
| 103 | application.getSymbolTable(), | |
| 104 | SP, | |
| 105 | FP, | |
| 106 | new Message("Program loaded into memory. FP set to {0}" + | |
| 107 | " and SP to {1}.", | |
| 108 | messageParameters).toString()); | |
| 109 | ||
| 110 | 1 | processor.runInit(SP, FP); |
| 111 | ||
| 112 | 1 | return retValue; |
| 113 | } | |
| 114 | ||
| 115 | } | |
Mutations | ||
| 30 |
negated conditional : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 31 |
removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE removed call to java/lang/Class::getName : NO_COVERAGE |
|
| 34 |
removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE |
|
| 36 |
Removed assignment to member variable processor : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 37 |
removed call to fi/helsinki/cs/titokone/BinaryInterpreter::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Removed assignment to member variable binInterpreter : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 46 |
negated conditional : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 47 |
removed call to java/lang/Class::getName : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE |
|
| 50 |
removed call to java/lang/IllegalArgumentException::<init> : NO_COVERAGE |
|
| 52 |
Removed assignment to member variable application : SURVIVED |
|
| 62 |
Substituted 2 with 3 : SURVIVED Substituted 2 with 3 : SURVIVED |
|
| 63 |
negated conditional : SURVIVED |
|
| 64 |
mutated return of Object value for fi/helsinki/cs/titokone/Loader::loadApplication to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 67 |
removed call to fi/helsinki/cs/titokone/Application::getCode : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 68 |
removed call to fi/helsinki/cs/titokone/Application::getInitialData : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 70 |
Substituted 0 with 1 : SURVIVED negated conditional : SURVIVED Changed increment from 1 to -1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 0 with 1 : SURVIVED changed conditional boundary : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 71 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getSymbolic : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to java/lang/String::equals : SURVIVED negated conditional : SURVIVED |
|
| 72 |
removed call to fi/helsinki/cs/titokone/MemoryLine::getBinary : SURVIVED |
|
| 73 |
removed call to fi/helsinki/cs/titokone/MemoryLine::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to fi/helsinki/cs/titokone/BinaryInterpreter::binaryToString : SURVIVED |
|
| 77 |
Substituted 1 with 0 : SURVIVED Replaced integer subtraction with addition : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 1 with 0 : SURVIVED |
|
| 78 |
Replaced integer subtraction with addition : SURVIVED Replaced integer addition with subtraction : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 1 with 0 : SURVIVED Substituted 1 with 0 : SURVIVED |
|
| 81 |
Substituted 0 with 1 : SURVIVED Changed increment from 1 to -1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) changed conditional boundary : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 0 with 1 : SURVIVED negated conditional : SURVIVED |
|
| 82 |
removed call to fi/helsinki/cs/titokone/Processor::memoryInput : SURVIVED |
|
| 85 |
Substituted 0 with 1 : SURVIVED changed conditional boundary : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) negated conditional : SURVIVED Changed increment from 1 to -1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 0 with 1 : SURVIVED |
|
| 86 |
removed call to fi/helsinki/cs/titokone/Processor::memoryInput : SURVIVED Replaced integer addition with subtraction : SURVIVED |
|
| 89 |
Substituted 0 with 1 : SURVIVED removed call to java/lang/StringBuilder::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to java/lang/StringBuilder::append : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to java/lang/StringBuilder::toString : SURVIVED Substituted 0 with 1 : SURVIVED removed call to java/lang/StringBuilder::append : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 90 |
removed call to java/lang/StringBuilder::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to java/lang/StringBuilder::append : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 1 with 0 : SURVIVED removed call to java/lang/StringBuilder::toString : SURVIVED removed call to java/lang/StringBuilder::append : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 1 with 0 : SURVIVED |
|
| 92 |
removed call to fi/helsinki/cs/titokone/RandomAccessMemory::getMemoryLines : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to fi/helsinki/cs/titokone/Processor::getPhysicalMemory : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 93 |
Replaced integer subtraction with addition : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 96 |
changed conditional boundary : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) negated conditional : SURVIVED Substituted 0 with 1 : SURVIVED Changed increment from 1 to -1 : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) Substituted 0 with 1 : SURVIVED |
|
| 97 |
Replaced integer addition with subtraction : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) |
|
| 101 |
removed call to fi/helsinki/cs/titokone/Message::toString : SURVIVED removed call to fi/helsinki/cs/titokone/LoadInfo::<init> : SURVIVED removed call to fi/helsinki/cs/titokone/Message::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testLoad(fi.helsinki.cs.titokone.ControlTest) removed call to fi/helsinki/cs/titokone/Application::getSymbolTable : SURVIVED |
|
| 110 |
removed call to fi/helsinki/cs/titokone/Processor::runInit : SURVIVED |
|
| 112 |
mutated return of Object value for fi/helsinki/cs/titokone/Loader::loadApplication to ( if (x != null) null else throw new RuntimeException ) : SURVIVED |