-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionsList.java
More file actions
121 lines (113 loc) · 3.95 KB
/
InstructionsList.java
File metadata and controls
121 lines (113 loc) · 3.95 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
/*
* 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.Hashtable;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.logging.Logger;
/**
*
* @author lovelinanand
*/
public class InstructionsList {
private static final Logger LOGGER = Logger.getGlobal();
private LinkedHashMap<Integer, Instructions> InstructionTable;
public int instructionCount;
public final String orderType;
public InstructionsList(String orderType){
this.InstructionTable = new LinkedHashMap<Integer, Instructions>();
this.instructionCount = 0;
this.orderType = orderType;
}
public Instructions add(String inst, Integer count){
Instructions temp = new Instructions(inst, count);
this.InstructionTable.put(count, temp);
this.instructionCount ++;
return temp;
}
public Instructions get(Integer lineNo){
return this.InstructionTable.get(lineNo);
}
public Set<Integer> keyList(){
return this.InstructionTable.keySet();
}
public Instructions next(){
Instructions nextIns = null;
for(Integer key : this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if(temp.canBeIssued()){
nextIns = temp;
break;
}
}
return nextIns;
}
public Instructions nextDispatch(){
Instructions nextIns = null;
for(Integer key : this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if(temp.canBeDispatched()){
nextIns = temp;
break;
}
}
return nextIns;
}
public boolean isCompleted(){
boolean isCompleted = true;
for(Integer key: this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if(!temp.isCompleted()){
isCompleted = false;
break;
}
}
return isCompleted;
}
public void dump(){
String leftAlignFormat = "| %-15s | %-10s |%n";
System.out.println("Instruction List Status");
System.out.format("+-----------------+------------+%n");
System.out.format("| Instruction | Status |%n");
System.out.format("+-----------------+------------+%n");
for(Integer key : this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
System.out.format(leftAlignFormat, temp, temp.getStatusString());
}
System.out.format("+-----------------+------------+%n");
}
public int getCacheMiss(){
int cacheMiss = 0;
for(Integer key: this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if("CACHEMISS".equals(temp.getOperation())){
cacheMiss = Integer.parseInt(temp.getSource1());
}
}
return cacheMiss;
}
public int getIssueWidth(){
int issueWidth = 1;
for(Integer key: this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if("ISSUEWIDTH".equals(temp.getOperation())){
issueWidth = Integer.parseInt(temp.getSource1());
}
}
return issueWidth;
}
public Integer[] getDump(){
Integer[] dumpCycles = { -1, -1};
for(Integer key: this.InstructionTable.keySet()){
Instructions temp = this.InstructionTable.get(key);
if("DUMP".equals(temp.getOperation())){
dumpCycles[0] = Integer.parseInt(temp.getSource1());
dumpCycles[1] = Integer.parseInt(temp.getSource2());
}
}
return dumpCycles;
}
}