-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
96 lines (74 loc) · 2.59 KB
/
main.c
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
/* ***************************************************************** */
/* */
/* */
/* ***************************************************************** */
/* A program to simulate cache behaviour on a valgrind memory trace. */
/* The input is a description of a set of caches, and a memory trace.
We run the memory trace on each of the caches, and report statistics. */
#include "global.h"
#include "caches.h"
Boolean debug = FALSE;
/* ***************************************************************** */
/* */
/* */
/* ***************************************************************** */
void usage(void)
{
fprintf (stderr,"usage: caches [-d] cache-descriptions-file memory-trace-file\n");
}
void scanargs(String s)
{
/* check each character of the option list for
its meaning. */
while (*++s != '\0')
switch (*s)
{
case 'd': /* debug option */
debug = TRUE;
if (debug)
{
debug_file = fopen("DEBUG_LOG", "w");
if (debug_file == NULL)
{
fprintf(stderr, "Cannot open DEBUG_LOG\n");
debug = FALSE;
}
}
break;
default:
fprintf (stderr,"caches: Bad option %c\n", *s);
usage();
exit(1);
}
}
/* ***************************************************************** */
/* */
/* */
/* ***************************************************************** */
int main(int argc, String *argv)
{
/* main driver program. There are two input
files.
1. defines the caches
2. defines the memory trace
*/
/* Process all arguments. */
/* skip program name */
argc--, argv++;
while ((argc > 1) && (**argv == '-'))
{
scanargs(*argv);
argc--, argv++;
}
if (argc != 2)
{
usage();
exit(-1);
}
Read_Cache_Descriptions(argv[0]);
Init_Caches();
Simulate_Caches(argv[1]);
Print_Cache_Statistics();
Delete_Caches();
exit(0);
}