forked from raselashraf21/Tomasulo-Web-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1503 lines (1222 loc) · 57.2 KB
/
index.html
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#009578">
<title>Tomasulo-Simulator</title>
<link rel="stylesheet" href="resources/css/intro.css" />
<link rel="stylesheet" href="resources/css/main.css" />
<link rel="stylesheet" href="resources/css/table.css" />
<link rel="stylesheet" href="resources/css/layout.css" />
<link rel="stylesheet" href="resources/css/modal.css" />
<link rel="stylesheet" href="resources/css/inputWindow.css" />
<script src="resources/jsLibrary/loadash.js"></script>
<script src="resources/jsLibrary/intro.js"></script>
<script src="resources/js/utils.js"></script>
<script src="resources/js/inputs.js"></script>
<script src="resources/js/settings.js"></script>
<script src="resources/js/reservation.js"></script>
<script src="resources/js/funits.js"></script>
<script src="resources/js/registers.js"></script>
<!-- <script src="resources/js/controller.js"></script> -->
<script src="resources/js/Annotation.js"></script>
<script src="resources/js/antNode.js"></script>
<script src="resources/js/annotationTree.js"></script>
<script src="resources/js/instruction.js"></script>
<script src="resources/js/state.js"></script>
<script src="resources/js/resourceManager.js"></script>
<script src="resources/js/processManager.js"></script>
<script src="resources/js/diagram.js"></script>
</head>
<body onload="ShowComponents()">
<div class="cMainWrapper">
<div id="container">
<div id="hdrContainer" class="cHeadrContainer">
<h2>Tomasulo-Simulator</h2>
</div>
<div id="modalTop" class="modal">
<button onclick="closeModal()" class="close" title="Close Modal"><img class="closeBtn"
src="resources/images/icons/close.png"></button>
<div class="modalFormContent">
</div>
</div>
<!--modal end-->
<div id="lContainer" class="cLContainer">
<div id="inputContainer" class="cInputContainer">
<div class="cInputContainerTab cTab">
<button class="cInputContainerTabItem cTabButton" id="Instruction"
style="background-color: rgb(235, 190, 142);"
onclick="TabSelection('InstructionsInput','Instruction')">Instruction</button>
<button class="cInputContainerTabItem cTabButton " id="Funits"
onclick="TabSelection('FUnitsInput','Funits')">FUnits</button>
<button class="cInputContainerTabItem cTabButton" id="Workloads"
onclick="TabSelection('Workload','Workloads')">Workload</button>
</div>
<div id="InstructionsInput" class="cInstructionsInput cInputBody">
<table id="insInputTable" class="cIinsInputTable">
<tbody id="insInputTBody" class="cInsInputTBody">
</tbody>
</table>
<div id="InstructionInputActionButton" class="cInstructionInputActionButton cInputActionButton">
<button class="cInstructionActionButton cNextButton"
onclick="ShowFunitSettings()">Next</button>
<button class="cInstructionActionButton cLeftInputButton"
onclick="LoadTestCase_2()">Test-01</button>
<button class="cInstructionActionButton cLeftInputButton"
onclick="LoopTestCase_1()">Test-02</button>
<button type="button" for='file' class="cInstructionActionButton cLeftInputButton"
onclick="LoadFromFile(this)">
<!-- <img id="importimg" src="resources/images/icons/import.png"> -->
load
<input id="file" type="file" name="name" style="display:none;" />
</button>
</div>
</div>
<div id="FUnitsInput" class="cFUnitsInput cInputBody " style="display:none">
<div class="cCycleSettings">
<table id="FUnitsCycleTable" class="cFUnitSettingsTable">
<thead>
<tr>
<th>OP</th>
<th>EX Cycles</th>
</tr>
</thead>
<tbody id="FUnitSettingsTableBody">
<tr>
<td>Load C.Miss</td>
<td>
<input type="text" id="cCyclesFormText" name="ld_miss" value="8">
</td>
</tr>
<tr>
<td>Load C.Hit</td>
<td>
<input type="text" id="cCyclesFormText" name="ld_hit" value="1">
</td>
</tr>
<tr>
<td>store</td>
<td>
<input type="text" id="cCyclesFormText" name="sd" value="3">
</td>
</tr>
<tr>
<td>Add</td>
<td>
<input type="text" id="cCyclesFormText" name="add" value="2">
</td>
</tr>
<tr>
<td>Sub</td>
<td>
<input type="text" id="cCyclesFormText" name="sub" value="2">
</td>
</tr>
<tr>
<td>Mul</td>
<td>
<input type="text" id="cCyclesFormText" name="mul" value="4">
</td>
</tr>
<tr>
<td>Div</td>
<td>
<input type="text" id="cCyclesFormText" name="div" value="40">
</td>
</tr>
</tbody>
</table>
</div>
<div class="cFUnitSettings">
<table id="FUnitsCycleTable" class="cFUnitSettingsTable">
<thead>
<tr>
<th>F.Unit</th>
<th>Number</th>
</tr>
</thead>
<tbody id="FUnitSettingsTableBody">
<tr>
<td>Load/Store</td>
<td>
<input type="text" id="cUnitsFormText" name="FPLd" value="6">
</td>
</tr>
<tr>
<td>Integer</td>
<td>
<input type="text" id="cUnitsFormText" name="FPAdd" value="4">
</td>
</tr>
<tr>
<td>Multiplier</td>
<td>
<input type="text" id="cUnitsFormText" name="FPMul" value="2">
</td>
</tr>
</tbody>
</table>
</div>
<!-- <div class="cCacheSettings">
<table id="cacheCycleTable" class="cFUnitSettingsTable">
<thead>
<tr>
<th>OP (Cache)</th>
<th>Miss Cycle</th>
<th>Hit Cycle</th>
</tr>
</thead>
<tbody id="CacheSettingsTableBody">
<tr>
<td>Load</td>
<td>
<input type="text" id="cCacheFormText" name="cacheMiss" value="2">
</td>
<td>
<input type="text" id="cCacheFormText" name="cacheHit" value="0">
</td>
</tr>
</tbody>
</table>
</div> -->
<div id="FUnitsInputActionButton" class="cFUnitsInputActionButton cInputActionButton">
<button class="cInstructionActionButton cNextButton" onclick="submitInput()">Submit</button>
</div>
</div>
<div id="Workload" class="cWorkload cInputBody" style="display:none" data-intro='Hello step one!'>
<canvas id="wLoadAntBox" style="display:none"></canvas>
<table id="WLoadTable" class="cWLoadTable">
<tbody id="WLoadTBody" class="cWLoadTBody">
</tbody>
</table>
</div>
</div>
<div id="dataContainer" class="cDataContainer">
<div class="cDataContainerTab cTab">
<button class="cDataContainerTabItem cTabButton cDataTab cDataTabShow"
onclick="showStatistics(event,'InEditor')">Dependency Graph</button>
</div>
<div id="statistics" class="cStatistics cDataBody">
<canvas id="graphCanvas" style="display:none"></canvas>
<button class="cDependendencyBtn" style="background-color: #e49d6a;"
onclick="showWAW()">WAW</button>
<button class="cDependendencyBtn" style="background-color: #c2da2c;"
onclick="showWAR()">WAR</button>
<button class="cDependendencyBtn" style="background-color: #cc5875; "
onclick="showRAW()">RAW</button>
</div>
</div>
</div> <!-- Left container end-->
<div id="cContainer" class="cCContainer">
<div id="cReservationContainer" class="cReservationContainer">
<div class="cReservationContainerTab cTab">
<button class="cReservationContainerTabItem cTabButton" onclick="placeholder()">Reservations
Units</button>
</div>
<div id="reservation" class="cReservation cReservationBody">
<canvas id="rsAntBox" style="display:none"></canvas>
<table id="RSTable" class="cRSTable">
<tbody id="RSTBody" class="cRSTBody">
</tbody>
</table>
</div>
</div>
<div id="archContainer" class="cArchContainer">
<div class="cArchContainerTab cTab">
<button class="cArchContainerTabItem cTabButton" onclick="placeholder()">Architectural
Diagram</button>
</div>
<div id="architecture" class="cArchBody">
<canvas id="blockCanvas"></canvas>
</div>
</div>
</div>
<!-- Center container end-->
<div id="rContainer" class="cRContainer">
<div id="cycle" class="cCycle">
</div>
<div id="jmpCycle" class="cJmpCycle">
<select id="jmpCycleSelection">
</select>
</div>
<div id="antCycles" class="cAntCycles">
</div>
<div id="ratContainer" class="cRatContainer">
<div class="cRatContainerTab cTab">
<button class="cRatContainerTabItem cTabButton cRatTab cRatTabShow"
onclick="placeholder()">RAT</button>
</div>
<div id="rat" class="cRatBody">
<canvas id="ratAntBox" style="display:none"></canvas>
<table id="RATable" class="cRATable">
<tbody id="RATBody" class="cRATBody">
</tbody>
</table>
</div>
<div id="scalerRat" class="cScalerRatBody">
<canvas id="scalerRatAntBox" style="display:none"></canvas>
<table id="scalerRATable" class="cScalerRATable">
<tbody id="scalerRATBody" class="cScalerRATBody">
</tbody>
</table>
</div>
</div>
</div>
<!-- Right container end-->
<div id="ftrContainer" class="cFooterContainer">
<div id="actionButtonGroup" class="cActionButtonGroup">
<button type="button" id='intro' class="cActionBtn" onclick="ActivateIntro()">
<img src="resources/images/icons/intro.png">
</button>
<button type="button" id='stepBack' class="cActionBtn" onclick="executeStepBy(1)">
<img src="resources/images/icons/icons8-double-left-48.png">
</button>
<button type="button" id='stepAntBack' class="cActionBtn" onclick="execAnnotation(1)">
<img src="resources/images/icons/icons8-back-48.png">
</button>
<button type="button" id='stepAntForward' class="cActionBtn" onclick="execAnnotation(0)">
<img src="resources/images/icons/icons8-forward-48.png">
</button>
<button type="button" id='stepForward' class="cActionBtn" onclick="executeStepBy(0)">
<img src="resources/images/icons/icons8-double-right-48.png">
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
const Direction = {
"Forward": 0,
"Backward": 1
};
Object.freeze(Direction);
var mgtCtr = undefined;
var GAnnotationCOunter = 0;
function ShowComponents() {
showInputTable();
showRSView();
showRAT();
showWorkLoad();
showCycle(0);
showCycleSelection();
}
function ActivateIntro() {
introJs().setOptions({
steps: [
{
title: 'Welcome To Tomasulo Web Simulator',
intro: 'A web simulation tool to implement out-of-order dynamic scheduling algorithm',
position: 'right'
},
{
element: document.querySelector('#stepForward'),
intro: 'Execute to next instruction cycle',
position: 'top'
},
{
element: document.querySelector('#stepBack'),
intro: 'Execute to previous instruction cycle',
position: 'top'
},
{
element: document.querySelector('#stepAntForward'),
intro: 'Information shows what is happening in between cycle in forward fashion',
position: 'top'
},
{
element: document.querySelector('.cInputContainer'),
intro: 'Input window for instruction loading, configuration for functional units and cycle number ',
position: 'right'
},
{
element: document.querySelector('.cInputBody'),
intro: 'RISC-V instruction can be created by clocking \'+\' icon. ' +
'Instruction can be deleted by clicking delete icon. At this moment ' +
'Add, Sub, Mul, Div, Ld, Sd operations are supported.',
position: 'right'
},
{
element: document.querySelector('.cInputBody'),
intro: 'Load: reads input from file. ' +
'Test-*: predefined instruction input. ' +
'Next: settings window',
position: 'right'
},
{
element: document.querySelector('.cDataContainer'),
intro: 'This window used for many purpose. Dependency graph, loop or branching instruction also place in this window',
position: 'right'
},
{
element: document.querySelector('.cReservationBody'),
intro: 'Algorithm execution window. ' +
'\"Time\": Remaining execution cycle ' +
'\"Busy\": Yes, if FU is occupied by an active instruction ' +
'\"OP\": Operation to perfume in the FU ' +
'\"Vj and Vk\": values of source operand ' +
'\"Qj and Qk\": Reservation station units that produce source values Vj and Vk ' +
'\"Busy\": Yes, if FU is occupied by an active instruction ' +
"\"Address\": offset for load or store operation",
position: 'bottom'
},
{
element: document.querySelector('.cCycle'),
intro: 'Cycle Number',
position: 'left'
},
{
element: document.querySelector('.cAntCycles'),
intro: 'circle shows number of step remain till next cycle',
position: 'left'
},
{
element: document.querySelector('.cRatContainer'),
intro: 'Register address table; value denotes which FU will write to which register ',
position: 'left'
},]
}).start();
}
function addLevelOption(id) {
var selectList = document.createElement("select");
selectList.id = id;
var OPList = ["", "L1", "L2", "L3", "Jmp_L1", "Jmp_L2", "Jmp_L3"]
for (var i = 0; i < OPList.length; i++) {
var option = document.createElement("option");
option.value = id + OPList[i];
option.text = OPList[i];
selectList.appendChild(option);
}
return selectList;
}
function markInstruction(id) {
var elem = document.getElementById(id);
var value = elem.options[elem.selectedIndex].text - 1;
var inputTable = document.getElementById("insInputTable");
var tBody = inputTable.tBodies[0];
var rows = tBody.rows;
for (let indx = 0; indx < rows.length; ++indx) {
rows[indx].cells[0].style.backgroundColor = "";
}
rows[value].cells[0].style.backgroundColor = "#FF7F50";
}
function addRegSelectOption(id, opClass = "") {
var selectList = document.createElement("select");
selectList.id = id;
var operandType = id.split("-")[0];
var regIntValue = Array(32).fill('S').map((x, y) => (x + y));
var regFloatValue = Array(32).fill('F').map((x, y) => (x + y));
var numValues = [...Array(32).fill('+').map((x, y) => (x + y)),
...Array(32).fill('-').map((x, y) => (x + y))];
var insCounter = Array(128).fill().map((x, y) => y);
var regValueList = [...regFloatValue, ...regIntValue];
var RegIntAndNumber = [...regIntValue, ...numValues];
var regallValues = [...regValueList, ...numValues, ...insCounter];
for (var i = 0; i < regallValues.length; i++) {
var option = document.createElement("option");
option.value = id + regallValues[i];
option.text = regallValues[i];
if (opClass == "Loader") {
if ((operandType == "Src2")) {
option.value = id + RegIntAndNumber[i];
option.text = RegIntAndNumber[i];
}
}
else if (opClass == "Branch") {
if ((operandType == "Dest") || (operandType == "Src1")) {
option.value = id + RegIntAndNumber[i];
option.text = RegIntAndNumber[i];
}
else if (operandType == "Src2") {
option.value = id + insCounter[i];
option.text = insCounter[i];
selectList.addEventListener('change', function () {
markInstruction(id);
}, false);
}
}
selectList.appendChild(option);
}
return selectList;
}
function addOPSelectOption(id, rowElem) {
var selectList = document.createElement("select");
selectList.id = id;
selectList.addEventListener('change', function () {
updateInputTableOperand(id, rowElem);
}, false);
var OPList = ["ADD", "SUB", "MUL", "DIV", "LD", "SD", "BNEQ"]
for (var i = 0; i < OPList.length; i++) {
var option = document.createElement("option");
option.value = id + OPList[i];
option.text = OPList[i];
selectList.appendChild(option);
}
return selectList;
}
function createInputRow(tableElem) {
var rowCount = tableElem.rows.length;
if (rowCount > 0) {
tableElem.deleteRow(rowCount - 1);
}
let row = document.createElement("tr");
let rIndx = rowCount;
for (let indx = 0; indx < 6; ++indx) {
let cell = document.createElement("td");
let value = undefined;
switch (indx) {
case 0:
value = document.createTextNode(rIndx);
break;
case 1:
value = addOPSelectOption(("OP" + "-" + rIndx), row);
break;
case 2:
value = addRegSelectOption(("Dest" + "-" + rIndx));
break;
case 3:
value = addRegSelectOption(("Src1" + "-" + rIndx));
break;
case 4:
value = addRegSelectOption(("Src2" + "-" + rIndx));
break;
case 5:
value = document.createElement("button");
value.id = "rowButton";
value.innerHTML = '<img src="resources/images/icons/delete.png">';
value.addEventListener('click', function () {
tableElem.deleteRow(row.rowIndex - 1);
}, false);
break;
}
cell.appendChild(value);
row.appendChild(cell);
}
tableElem.appendChild(row);
createBtnsRow(tableElem);
return row;
}
function createBtnsRow(tableElem) {
let cell;
let row = document.createElement("tr");
for (let indx = 0; indx < 5; ++indx) {
cell = document.createElement("td");
row.appendChild(cell);
}
let btn = document.createElement("button");
btn.id = "rowButton"
btn.innerHTML = '<img src="resources/images/icons/add.png">';
btn.addEventListener('click', function () {
createInputRow(tableElem);
}, false);
cell = document.createElement("td");
cell.appendChild(btn);
row.appendChild(cell);
tableElem.appendChild(row);
}
function selectOptionInCell(elem, value) {
let options = elem.childNodes;
for (let indx = 0; indx < options.length; ++indx) {
if (options[indx].innerHTML.toLowerCase() == value) {
elem.selectedIndex = indx;
break;
}
}
}
function updateInputTableOperand(id, rowElem) {
var elem = document.getElementById(id);
var opName = elem.options[elem.selectedIndex].text;
var opClass = getOPClass(opName);
for (let indx = 0; indx < 3; ++indx) {
var cell = rowElem.cells[2 + indx];
var childNode = cell.childNodes[0];
var operandID = childNode.id;
cell.removeChild(childNode);
var optionsElem = addRegSelectOption(operandID, opClass);
cell.appendChild(optionsElem);
}
// selectOptionInCell(elem, opName);
}
function showAutoSelectionTable(instructions) {
var inputTable = document.getElementById("insInputTable");
var tBody = inputTable.tBodies[0];
createBtnsRow(tBody); //maintenance only
var rows = tBody.rows;
while (rows.length > 1) {
inputTable.deleteRow(1);
}
instructions.forEach(function (ins, indx) {
let row = createInputRow(tBody);
let cells = row.cells;
let elem = undefined;
let id = undefined;
let opName = getUniqueOPName(ins.OP);
for (let indx = 0; indx < 4; ++indx) {
switch (indx) {
case 0:
id = cells[1].childNodes[0].id;
elem = document.getElementById(id);
selectOptionInCell(elem, opName);
break;
case 1:
id = cells[2].childNodes[0].id;
elem = document.getElementById(id);
selectOptionInCell(elem, ins.Dest);
break;
case 2:
id = cells[3].childNodes[0].id;
elem = document.getElementById(id);
selectOptionInCell(elem, ins.Src1);
break;
case 3:
id = cells[4].childNodes[0].id;
elem = document.getElementById(id);
selectOptionInCell(elem, ins.Src2);
if (getOPClass(ins.OP) == "Branch") {
markInstruction(id);
document.getElementById(id).addEventListener('change', function () {
markInstruction(id);
}, false);
}
break;
}
}
});
}
function addHeader(hdrElem, hdrList) {
if (hdrList == undefined) {
console.error("headers of " + hdrElem + "Empty");
return;
}
let hdrRow = document.createElement("tr");
hdrList.forEach(hdrElem => {
let th = document.createElement("th");
let thTxt = document.createTextNode(hdrElem);
th.appendChild(thTxt);
hdrRow.appendChild(th);
});
hdrElem.appendChild(hdrRow);
}
function completeTableCreation(tableId, hdrList) {
var tableElem = document.getElementById(tableId);
var tHead = tableElem.tHead;
var tBody = tableElem.tBodies[0];
if (tHead == null) {
tHead = document.createElement('thead');
addHeader(tHead, hdrList);
tableElem.appendChild(tHead);
}
if (tBody == null) {
tBody = document.createElement('tbody');
tableElem.appendChild(tBody);
}
}
function handleMouseOver(rowId, color) {
console.log(rowId);
if (rowId.length == 0) {
return;
}
var elements = document.querySelectorAll(("#" + rowId));
elements.forEach(element => {
element.style.backgroundColor = color;
});
}
function handleMouseOut(rowId) {
if (rowId.length == 0) {
return;
}
var elements = document.querySelectorAll(("#" + rowId));
elements.forEach(element => {
element.style.backgroundColor = "";
});
}
function addTableRow(tBodyElem, cellsContentList, color = "", rowId = "") {
var row = document.createElement("tr");
row.id = rowId;
cellsContentList.forEach(function (cellcontext, indx) {
let cell = document.createElement("td");
if (indx == 1) {
cell.style.backgroundColor = color;
}
let cellTxt = document.createTextNode(cellcontext);
cell.appendChild(cellTxt);
row.appendChild(cell);
});
row.addEventListener('mouseover', () => handleMouseOver(rowId, color));
row.addEventListener('mouseout', () => handleMouseOut(rowId));
tBodyElem.appendChild(row);
return row;
}
function displayContents(contents) {
var element = document.getElementById('file-content');
element.textContent = contents;
}
function showRAW() {
var wloadContent = mgtCtr.getWLoadContent();
var dependencyList = mgtCtr.calculateDependency();
drawDependencyGraph(dependencyList, "raw");
}
function showWAW() {
var wloadContent = mgtCtr.getWLoadContent();
var dependencyList = mgtCtr.calculateDependency();
drawDependencyGraph(dependencyList, "waw");
}
function showWAR() {
var wloadContent = mgtCtr.getWLoadContent();
var dependencyList = mgtCtr.calculateDependency();
drawDependencyGraph(dependencyList, "war");
}
function drawDependencyGraph(dependencyList, dependencyType = "") {
var domElement = document.getElementById("statistics");
var theCanvas = document.getElementById("graphCanvas");
//theCanvas.style.display = "none";
theCanvas.width = domElement.offsetWidth;
theCanvas.height = domElement.offsetHeight;
drawDependency(theCanvas, dependencyList, dependencyType);
theCanvas.style.display = "block";
theCanvas.style.position = "absolute";
theCanvas.style.zIndex = 10;
}
function generateENV(instructions, execCycles, unitsSize) {
mgtCtr = new ProcessManager();
mgtCtr.setProcessEnv(instructions, execCycles, unitsSize);
updateWLoad();
updateRAT();
updateScalerRAT();
updateRSView();
showCycle(0);
mgtCtr.setTotalCycle();
showCycleSelection();
}
function getScalerOperandValue(src1Ctx, src2Ctx) {
closeModal();
mgtCtr.updateScalerReg(src1Ctx[0], src1Ctx[1]);
mgtCtr.updateScalerReg(src2Ctx[0], src2Ctx[1]);
updateScalerRAT();
}
function popupModal(text) {
document.getElementById('modalTop').style.display = "block";
var modalForm = document.querySelector(".modalFormContent");
modalForm.style.display = "block";
modalForm.innerHTML = "";
var divElem = document.createElement("div");
divElem.setAttribute("id", "popTextDiv");
var textNode = document.createTextNode(text);
divElem.appendChild(textNode);
modalForm.appendChild(divElem);
}
function updateScalerRegister(modalForm, selectList, src1, src2) {
// Create a form dynamically
var removeElem = document.getElementById("input4Reg");
if (removeElem != null) {
removeElem.remove();
}
var submitBtn = document.createElement("button");
submitBtn.id = "input4Reg";
submitBtn.innerHTML = "submit";
submitBtn.addEventListener("click", (event) => {
let src1 = document.getElementById("scalerRegSrc_1");
let src2 = document.getElementById("scalerRegSrc_2");
getScalerOperandValue([src1.getAttribute("name"), src1.value], [src2.getAttribute("name"), src2.value]);
});
let value = selectList.options[selectList.selectedIndex].value;
removeElem = document.getElementById("scalerRegSrc_1");
if (removeElem != null) {
removeElem.remove();
}
// Create an input element for Full Name
var elemSrc1 = document.createElement("input");
elemSrc1.id = "scalerRegSrc_1";
elemSrc1.className = "scalerRegister";
elemSrc1.value = 80;
elemSrc1.setAttribute("name", src1);
elemSrc1.setAttribute("type", "text");
elemSrc1.setAttribute("placeholder", src1);
removeElem = document.getElementById("scalerRegSrc_2");
if (removeElem != null) {
removeElem.remove();
}
var elemSrc2 = document.createElement("input");
elemSrc2.setAttribute("id", "scalerRegSrc_2");
elemSrc2.className = "scalerRegister";
elemSrc2.value = (80 - value * 8);
elemSrc2.setAttribute("name", src2);
elemSrc2.setAttribute("type", "text");
elemSrc2.setAttribute("placeholder", src2);
modalForm.appendChild(elemSrc1);
modalForm.appendChild(elemSrc2);
modalForm.appendChild(submitBtn);
}
function popupForScalerRegister(instruction) {
document.getElementById('modalTop').style.display = "block";
var modalForm = document.querySelector(".modalFormContent");
modalForm.style.display = "block";
modalForm.innerHTML = "";
var src1 = instruction.Dest;
var src2 = instruction.Src1;
if (!isScalerRegister(src1) || !isScalerRegister(src2)) {
popupModal(("No Scaler register or value for operands : " + src1 + " Or " + src2));
return 0;
}
popupModal("System has detected a branch instruction. Please enter number of iteration.");
var itrLabel = document.createElement("Label");
itrLabel.setAttribute("for", "itrLabel");
itrLabel.innerHTML = "Iteration Count: ";
modalForm.appendChild(itrLabel);
var selectList = document.createElement("select");
selectList.id = "itrLabel";
selectList.addEventListener('change', function () {
updateScalerRegister(modalForm, selectList, src1, src2);
}, false);
for (var i = 0; i <= 10; i++) {
var option = document.createElement("option");
option.value = i;
option.text = i;
selectList.appendChild(option);
}
modalForm.appendChild(selectList);
}
function closeModal() {
document.getElementById('modalTop').style.display = 'none';
}
function checkForBranch(instruction) {
for (let indx = 0; indx < instruction.length; ++indx) {
if (getOPClass(instruction[indx].OP) == "Branch") {
if (indx == 0) {
popupModal("First Instruction can not be branch");
}
return indx;
}
}
return 0;
}
function submitInput() {
document.getElementById("wLoadAntBox").style.display = "none";
document.getElementById("rsAntBox").style.display = "none";
document.getElementById("ratAntBox").style.display = "none";
var depBtns = document.querySelectorAll(".cDependendencyBtn");
depBtns.forEach(element => {
element.style.display = "block";
});
var instructions = collectInstructionsFromUI();
var branchIndx = checkForBranch(instructions);
if (branchIndx) {
popupForScalerRegister(instructions[branchIndx]);
}
var execCycles = collectExecCycleFromUI();
var unitsSize = collectUnitsSizeFromUI();
if (((instructions == undefined) || (instructions.length == 0))
||
((execCycles == undefined) || (execCycles.length == 0))
||
((unitsSize == undefined) || (unitsSize.length == 0))
) {
popupModal("Can not proceed because of input instruction or configuration empty");
return;
}