-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.cpp
More file actions
100 lines (97 loc) · 2.7 KB
/
client.cpp
File metadata and controls
100 lines (97 loc) · 2.7 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
#include "cache_mapper_header.h"
int main()
{
cache_mock Cacher;
cout << "Cache-Mapper\n"
<< endl;
cout << "Input only compatible values (such as power of 2s, etc)\n"
<< endl;
long int d, c, m, b, s, l; // default meaning as in 'cache_mapper.cpp' constructor call;
long int address;
cout << "Enter 0 for Set-Associative, 1 for Direct-Map, 2 for Fully-Associative" << endl;
cin >> d;
cout << "Enter Cache-Size, Memory-Size, Block-Size in Bytes/Words (stick to one convention)" << endl;
cin >> c >> m >> b;
if (d != 1)
{
// There is no requirement of replacement techniques for direct mapped cache.
cout << "Enter 1 for Least-Recently-Used, 0 for First-In-First-Out Hierarchy" << endl;
cin >> l;
}
if (!d)
{
cout << "Enter X for X-way associative"<<endl;
cin >> s;
cache_mock temp(d, c, m, b, l, s);
Cacher.cache_mock_copy(temp);
}
else
{
cache_mock temp(d, c, m, b, l);
Cacher.cache_mock_copy(temp);
}
int flag = 1;
int val;
cout << "\n0 : Display\n1 : Load followed by address\n2 : Store followed by address" << endl;
cout << "3 : Refresh dirty_bits\n4 : Clear cache main_frame\n5 : Exit\n" << endl;
while (flag)
{
cout << "Input" << endl;
cin >> val;
switch (val)
{
case 0:
{
Cacher.container_display();
cout << endl;
break;
}
case 1:
{
cin >> address;
int addressFlag = Cacher.loader(address);
if (addressFlag == 1)
cout << "Hit" << endl;
else if(addressFlag == 0)
cout << "Miss" << endl;
else
{
cout << "Invalid address input" << endl;
}
break;
}
case 2:
{
cin >> address;
if (Cacher.storer(address))
cout << "Hit" << endl;
else
cout << "Miss" << endl;
break;
}
case 3:
{
Cacher.refresh_dirty();
break;
}
case 4:
{
Cacher.container_init();
cout << "Cache was cleared!" << endl;
break;
}
case 5:
{
flag--;
break;
}
default:
{
cout << "\n0 : Display\n1 : Load followed by address\n2 : Store followed by address" << endl;
cout << "3 : Refresh dirty_bits\n4 : Clear cache main_frame\n5 : Exit\n" << endl;
}
}
cout<<endl;
}
cout << "Simulation Terminated!" << endl;
}