-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicroGui.java
618 lines (585 loc) · 25.9 KB
/
MicroGui.java
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class MicroGui extends JFrame {
/**
* Creates new form MicroGui
*/
public MicroGui() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
fileChooser = new javax.swing.JFileChooser();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
cache_level = new JTextField();
spec_cache = new JTextField();
ins_cache_level = new JTextField();
spec_ins_cache_level = new JTextField();
spec_hrd_org = new JTextField();
st_addr = new JTextField();
Browse_ins_btn = new JButton();
run_prog_btn = new JButton();
jScrollPane1 = new JScrollPane();
textarea = new JTextArea();
jLabel7 = new JLabel();
mem_data_req = new JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Micro Program");
jLabel1.setText("The number of cache level to simulate:");
jLabel2.setText("specifications for the cache :");
jLabel3.setText("the number of instruction cache levels to simulate:");
jLabel4.setText("specifications for the instruction cache:");
jLabel5.setText("specifications for the hardware organization:");
jLabel6.setText("the start address:");
Browse_ins_btn.setText("Instructions file");
Browse_ins_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Browse_ins_btnActionPerformed(evt);
}
});
run_prog_btn.setText("Run");
run_prog_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
run_prog_btnActionPerformed(evt);
}
});
textarea.setColumns(20);
textarea.setRows(5);
jScrollPane1.setViewportView(textarea);
jLabel7.setText("the memory data required:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cache_level, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(spec_cache)
.addComponent(ins_cache_level)
.addComponent(spec_ins_cache_level)
.addComponent(spec_hrd_org)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(st_addr, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mem_data_req, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(Browse_ins_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(run_prog_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(128, 128, 128)))))
.addContainerGap())
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cache_level, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spec_cache, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(4, 4, 4)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ins_cache_level, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spec_ins_cache_level, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spec_hrd_org, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(st_addr, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(mem_data_req, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Browse_ins_btn)
.addComponent(run_prog_btn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
);
pack();
}
private void run_prog_btnActionPerformed(ActionEvent evt) {
int cacheLevels=Integer.parseInt(cache_level.getText());
switch(cacheLevels){
case 1:
System.out.println("Please Enter your specifications for the cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "first level memory access time (in cycles)");
cacheSpecifications = spec_cache.getText().split(",");
cache = new Cache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]), 0, 0, 0, 0, 0,0,
Integer.parseInt(cacheSpecifications[5]), 0,0,
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),0, 0,0,0, cacheLevels, memory);
break;
case 2:
System.out.println("Please Enter your specifications for the cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "memory access time (in cycles),"
+ "second level s,l,m, "
+ "second level hit_policy (1=write_throught 2=write_back),"
+ "second level miss policy (1=write allocate 2=write around),"
+ "second level cycles to access data");
cacheSpecifications = spec_cache.getText().split(",");
cache = new Cache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]),
Integer.parseInt(cacheSpecifications[7]),
Integer.parseInt(cacheSpecifications[8]),
Integer.parseInt(cacheSpecifications[9]), 0, 0,0,
Integer.parseInt(cacheSpecifications[5]),
Integer.parseInt(cacheSpecifications[12]),0,
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),
Integer.parseInt(cacheSpecifications[10]),
Integer.parseInt(cacheSpecifications[11]),0,0, cacheLevels, memory);
break;
case 3:
System.out.println("Please Enter your specifications for the cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "memory access time (in cycles),"
+ "second level s,l,m, "
+ "second level hit_policy (1=write_throught 2=write_back),"
+ "second level miss policy (1=write allocate 2=write around),"
+ "second level cycles to access data,"
+ "third level s,l,m, "
+ "third level hit_policy (1=write_throught 2=write_back),"
+ "third level miss policy (1=write allocate 2=write around),"
+ "third level cycles to access data");
cacheSpecifications = spec_cache.getText().split(",");
cache = new Cache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]),
Integer.parseInt(cacheSpecifications[7]),
Integer.parseInt(cacheSpecifications[8]),
Integer.parseInt(cacheSpecifications[9]),
Integer.parseInt(cacheSpecifications[13]),
Integer.parseInt(cacheSpecifications[14]),
Integer.parseInt(cacheSpecifications[15]),
Integer.parseInt(cacheSpecifications[5]),
Integer.parseInt(cacheSpecifications[12]),
Integer.parseInt(cacheSpecifications[18]),
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),
Integer.parseInt(cacheSpecifications[10]),
Integer.parseInt(cacheSpecifications[11]),
Integer.parseInt(cacheSpecifications[16]),
Integer.parseInt(cacheSpecifications[17]), cacheLevels, memory);
break;
}
System.out.println("Please Enter the number of instruction cache levels you want to simulate.");
int icacheLevels = Integer.parseInt(ins_cache_level.getText());
switch(icacheLevels){
case 1:
System.out.println("Please Enter your specifications for the instruction cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "first level memory access time (in cycles)");
cacheSpecifications = spec_ins_cache_level.getText().split(",");
icache = new ICache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]), 0, 0, 0, 0, 0,0,
Integer.parseInt(cacheSpecifications[5]), 0,0,
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),0, 0,0,0, cacheLevels, memory);
break;
case 2:
System.out.println("Please Enter your specifications for the instruction cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "memory access time (in cycles),"
+ "second level s,l,m, "
+ "second level hit_policy (1=write_throught 2=write_back),"
+ "second level miss policy (1=write allocate 2=write around),"
+ "second level cycles to access data");
cacheSpecifications = spec_ins_cache_level.getText().split(",");
icache = new ICache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]),
Integer.parseInt(cacheSpecifications[7]),
Integer.parseInt(cacheSpecifications[8]),
Integer.parseInt(cacheSpecifications[9]), 0, 0,0,
Integer.parseInt(cacheSpecifications[5]),
Integer.parseInt(cacheSpecifications[12]),0,
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),
Integer.parseInt(cacheSpecifications[10]),
Integer.parseInt(cacheSpecifications[11]),0,0, cacheLevels, memory);
break;
case 3:
System.out.println("Please Enter your specifications for the instruction cache in the following format: "
+ "first level s,l,m, "
+ "first level hit_policy (1=write_throught 2=write_back),"
+ "first level miss policy (1=write allocate 2=write around),"
+ "first level cycles to access data,"
+ "memory access time (in cycles),"
+ "second level s,l,m, "
+ "second level hit_policy (1=write_throught 2=write_back),"
+ "second level miss policy (1=write allocate 2=write around),"
+ "second level cycles to access data,"
+ "third level s,l,m, "
+ "third level hit_policy (1=write_throught 2=write_back),"
+ "third level miss policy (1=write allocate 2=write around),"
+ "third level cycles to access data");
cacheSpecifications = spec_ins_cache_level.getText().split(",");
icache = new ICache(Integer.parseInt(cacheSpecifications[0]),
Integer.parseInt(cacheSpecifications[1]),
Integer.parseInt(cacheSpecifications[2]),
Integer.parseInt(cacheSpecifications[7]),
Integer.parseInt(cacheSpecifications[8]),
Integer.parseInt(cacheSpecifications[9]),
Integer.parseInt(cacheSpecifications[13]),
Integer.parseInt(cacheSpecifications[14]),
Integer.parseInt(cacheSpecifications[15]),
Integer.parseInt(cacheSpecifications[5]),
Integer.parseInt(cacheSpecifications[12]),
Integer.parseInt(cacheSpecifications[18]),
Integer.parseInt(cacheSpecifications[6]),
Integer.parseInt(cacheSpecifications[3]),
Integer.parseInt(cacheSpecifications[4]),
Integer.parseInt(cacheSpecifications[10]),
Integer.parseInt(cacheSpecifications[11]),
Integer.parseInt(cacheSpecifications[16]),
Integer.parseInt(cacheSpecifications[17]), cacheLevels, memory);
break;
}
System.out.println("Please Enter your specifications for the hardware organization in the following format: "
+ "instruction buffer size, "
+ "number of load/store reservation stations,"
+ "number of add/sub reservation stations,"
+ "number of nand reservation stations,"
+ "number of mul reservation stations,"
+ "number of addi reservation stations,"
+ "number of ROB entries,"
+ "load/store cycles,"
+ "add/sub cycles,"
+ "nand cycles,"
+ "mul cycles,"
+ "addi cycles");
String[] tomasuloSpecifications = spec_hrd_org.getText().split(",");
tomasulo = new TomasuloAlg(Integer.parseInt(tomasuloSpecifications[0]),
Integer.parseInt(tomasuloSpecifications[1]),
Integer.parseInt(tomasuloSpecifications[2]),
Integer.parseInt(tomasuloSpecifications[3]),
Integer.parseInt(tomasuloSpecifications[4]),
Integer.parseInt(tomasuloSpecifications[5]),
Integer.parseInt(tomasuloSpecifications[6]),
Integer.parseInt(tomasuloSpecifications[7]),
Integer.parseInt(tomasuloSpecifications[8]),
Integer.parseInt(tomasuloSpecifications[9]),
Integer.parseInt(tomasuloSpecifications[10]),
Integer.parseInt(tomasuloSpecifications[11]),
Integer.parseInt(tomasuloSpecifications[12]),
Integer.parseInt(tomasuloSpecifications[13]),
Integer.parseInt(tomasuloSpecifications[14]),
Integer.parseInt(tomasuloSpecifications[15]),
Integer.parseInt(tomasuloSpecifications[16]));
System.out.println("Please enter the start address then write your program in the file.");
startAddress =Integer.parseInt(st_addr.getText());
instructions = assembler.assemble(file);
for(int i=0; i<instructions.length; i++){
memory.writeData(Integer.toString(startAddress),instructions[i]);
startAddress+=2;
}
for (int q=0; q< assembler.returnRegisters().size(); q++){
if(!registers.contains(assembler.returnRegisters().get(q))){
Register r = new Register(assembler.returnRegisters().get(q), -1);
registers.add(r);
}
}
System.out.println("Please enter the memory data required for your program in the form (value, address), if no data, enter (no data).");
String[] memData = mem_data_req.getText().split(",");
if(!memData[0].equals("nodata")){
for(int d=0; d<memData.length; d+=2){
memory.writeData(memData[d+1], memData[d]);
}
}
pc.setValue(pc.getValue()-2);
tomasulo.start(registers, icache, cache, memory, pc);
textarea.append("the number of cycles is : "+tomasulo.cycles);
System.out.println(tomasulo.cycles);
double ipc = (instructions.length*1.00 / tomasulo.cycles*1.00);
System.err.println("IPC: " + ipc +" " + instructions.length);
textarea.append("\n");
textarea.append("IPC : "+ipc);
textarea.append("\n");
double perc;
switch (cacheLevels) {
case 1:
try {
perc = 100*(cache.hit*1.00 / 1.00*(cache.hit + cache.miss));
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
break;
case 2:
textarea.append("Cache Hit ratio :");
try {
perc = 100*(cache.hit*1.00 / (cache.hit + cache.miss)*1.00);
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(cache.hit2*1.00 / (cache.hit2 + cache.miss2)*1.00);
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
break;
case 3:
textarea.append("Cache Hit ratio :");
try {
perc = 100*(cache.hit*1.00 / (cache.hit + cache.miss)*1.00);
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(cache.hit2*1.00 / (cache.hit2 + cache.miss2)*1.00);
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(cache.hit3*1.00 / (cache.hit3 + cache.miss3)*1.00);
System.out.println("Cache Hit ratio: "
+ perc+"%");
textarea.append("Cache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("Cache Hit ratio: 0%");
textarea.append("\n");
}
break;
}
switch (icacheLevels) {
case 1:
try {
perc = 100*(icache.hit*1.00 / (icache.hit + icache.miss)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
break;
case 2:
textarea.append("ICache Hit ratio :");
textarea.append("\n");
try {
perc = 100*(icache.hit*1.00 / (icache.hit + icache.miss)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(icache.hit2*1.00 / (icache.hit2 + icache.miss2)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
break;
case 3:
textarea.append("ICache Hit ratio :");
textarea.append("\n");
try {
perc = 100*(icache.hit*1.00 / (icache.hit + icache.miss)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(icache.hit2*1.00 / (icache.hit2 + icache.miss2)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
try {
perc = 100*(icache.hit3*1.00 / (icache.hit3 + icache.miss3)*1.00);
System.out.println("ICache Hit ratio: "
+ perc+"%");
textarea.append("ICache Hit ratio: "+perc+"%");
textarea.append("\n");
} catch (ArithmeticException e) {
textarea.append("ICache Hit ratio: 0%");
textarea.append("\n");
}
break;
}
}
private void Browse_ins_btnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_Browse_ins_btnActionPerformed
// TODO add your handling code here:
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
System.out.println(file.getAbsolutePath());
try {
textarea.read( new FileReader( file.getAbsolutePath() ), null );
} catch (IOException ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled by user.");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MicroGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MicroGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MicroGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MicroGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MicroGui().setVisible(true);
}
});
}
public File file;
static int startAddress;
static String[] instructions;
static ArrayList<Register> registers = new ArrayList<Register>();
static String[] cacheSpecifications;
static Cache cache;
static Memory memory = new Memory();
static ICache icache;
static TomasuloAlg tomasulo;
static Assembler assembler = new Assembler();
static Register pc = new Register("pc", 0);
private JButton Browse_ins_btn;
private JTextField cache_level;
private JFileChooser fileChooser;
private JTextField ins_cache_level;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JLabel jLabel7;
private JScrollPane jScrollPane1;
private JTextField mem_data_req;
private JButton run_prog_btn;
private JTextField spec_cache;
private JTextField spec_hrd_org;
private JTextField spec_ins_cache_level;
private JTextField st_addr;
private JTextArea textarea;
}