-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructions.java
More file actions
181 lines (172 loc) · 4.82 KB
/
Instructions.java
File metadata and controls
181 lines (172 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package scoreboard;
import java.util.logging.Logger;
/**
*
* @author lovelinanand
*/
public class Instructions {
private static final Logger LOGGER = Logger.getGlobal();
private final String instruction;
private String operation;
private String Source1;
private String Source2;
private String Destination;
public int lineCount;
// 99 cannot be executed. 0 - ready, 1 - dispatched, 2 - issued, 3 - completed
private int instStatus;
private int cyclesLeft;
private int totalCycleRequired;
public Instructions(String instruction, int count){
this.instruction = instruction;
this.lineCount = count;
String[] parts = instruction.split("\\s+");
this.operation = parts[0];
this.instStatus = 0;
switch(this.operation){
case "DUMP":
this.Source1 = parts[1];
this.Source2 = parts[2];
this.instStatus = 99;
break;
case "ISSUEWIDTH":
this.Source1 = parts[1];
this.instStatus = 99;
break;
case "CACHEMISS":
this.Source1 = parts[1];
this.instStatus = 99;
break;
case "ST":
this.Source1 = parts[1];
this.Source2 = parts[3];
this.Destination = parts[2];
break;
default:
this.Destination = parts[1];
this.Source1 = parts[2];
this.Source2 = parts[3];
break;
}
LOGGER.info("Adding Instruction => "+ count +" = "+ instruction);
}
public String getStatusString(){
String status;
switch(this.instStatus){
case 0:
status="Waiting";
break;
case 1:
status="Dispatched";
break;
case 2:
if(this.totalCycleRequired == this.cyclesLeft ){
status="Issued";
}else{
status="Executing";
}
break;
case 3:
status="Completed";
break;
default:
status="-----";
break;
}
return status;
}
public String getSource1(){
if(this.Source1 != null){
return this.Source1;
}else{
return null;
}
}
public String getSource2(){
if(this.Source2 != null){
return this.Source2;
}else{
return null;
}
}
public String getDestination(){
if(this.Destination != null){
return this.Destination;
}else{
return null;
}
}
public Boolean canBeIssued(){
if(this.instStatus == 0){
return true;
}else{
return false;
}
}
public Boolean canBeDispatched(){
if(this.instStatus == 0){
return true;
}else{
return false;
}
}
public String getOperation(){
return this.operation;
}
public Boolean isCacheMiss(){
if(this.operation.equals("LDM")){
return true;
}else{
return false;
}
}
public void setIssued(int cycleLeft, int cacheMiss){
this.instStatus = 2;
int actualCyclesLeft;
if(this.isCacheMiss()){
actualCyclesLeft = cycleLeft + cacheMiss;
}else{
actualCyclesLeft = cycleLeft;
}
this.cyclesLeft = actualCyclesLeft;
this.totalCycleRequired = actualCyclesLeft;
System.out.println("Issue: " + this);
}
public void setDispatched(){
this.instStatus = 1;
System.out.println("Dispatch:" + this);
}
public int decrementCycle(){
if(this.cyclesLeft > 0){
this.cyclesLeft --;
}else{
LOGGER.fine("Cannot decrement cycle in instructions" + this.toString());
System.exit(0);
}
return this.cyclesLeft;
}
public void setCompleted(){
if(this.cyclesLeft == 0){
this.instStatus = 3;
System.out.println("complete: " + this);
}else{
LOGGER.warning(this + "Cannot set completed status , cycles still left " + this.cyclesLeft );
System.exit(0);
}
}
public boolean isCompleted(){
if(this.instStatus > 2){
return true;
}else{
return false;
}
}
@Override
public String toString(){
return this.instruction;
}
}