-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
53 lines (44 loc) · 1.42 KB
/
main.cpp
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
#include <iostream>
#include <cmath>
#include "Cache.h"
using namespace std;
// Driver program:
int main() {
// Parameter definitions:
int sets;
int blocks;
int bytes;
int repPolicy;
string traceName;
// Parameter collection and checking:
cout << "Number of sets in the cache: ";
cin >> sets;
if (log2(sets) != floor(log2(sets))) {
throw invalid_argument("Number of sets must be a positive power of 2!");
}
cout << "Number of blocks in each set: ";
cin >> blocks;
if (log2(blocks) != floor(log2(blocks))) {
throw invalid_argument("Number of blocks must be a positive power of 2!");
}
cout << "Number of bytes per block: ";
cin >> bytes;
if (log2(bytes) != floor(log2(bytes)) || bytes < 4) {
throw invalid_argument("Number of bytes must be a positive power of 2 and be greater than 4!");
}
cout << "Replacement policy:" << endl;
cout << "1 - LRU" << endl;
cout << "2 - FIFO" << endl;
cin >> repPolicy;
if (repPolicy != 1 && repPolicy != 2) {
throw invalid_argument("Please enter either 1 or 2 for the cache's replacement policy!");
}
cout << "Trace file name: (in ./Traces directory, including extension): ";
cin >> traceName;
traceName = "Traces/" + traceName;
cout << endl;
// Run the simulation:
Cache cache(sets, blocks, bytes, repPolicy);
cache.Simulate(traceName);
return 0;
}