This repository has been archived on 2020-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
cs2011-cachelab/csim.c

69 lines
1.4 KiB
C
Raw Normal View History

2016-04-25 17:07:24 -04:00
#include <stdlib.h>
#include <stdio.h>
2016-04-24 20:07:46 -04:00
#include "cachelab.h"
2016-04-26 10:30:54 -04:00
int VERBOSE = 0;
2016-04-25 17:07:24 -04:00
void print_usage()
2016-04-24 20:07:46 -04:00
{
2016-04-25 17:45:52 -04:00
printf("Usage: ./csim [-hv] -s <number> -E <number> -b <number> -t <file>\n"
"Options:\n"
" -h Print this help.\n"
" -v Display trace info.\n"
" -s <number> The number of sets is the base-2 logarithm of this argument.\n"
" -E <number> Associativity (lines per set).\n"
" -b <number> Block size in bits is the base-2 logarithm of this argument.\n"
" -t <file> Name of the file to read a valgrind trace from.");
2016-04-25 17:07:24 -04:00
exit(0);
}
int parse_int_arg(char* arg)
{
2016-04-26 10:22:34 -04:00
char* end;
int i = strtol(arg, &end, 0);
if (!i || *end != '\0')
{
printf("Invalid argument \"%s\"\n", arg);
print_usage();
}
return i;
2016-04-25 17:07:24 -04:00
}
int main(int argc, char* argv[])
{
2016-04-26 10:30:54 -04:00
int set_bits = 0, lines = 0, block_bits = 0;
2016-04-25 17:07:24 -04:00
char* filename;
int ii;
for (ii = 0; ii < argc; ii++)
{
switch (argv[ii][1])
{
case 'h':
//print_usage();
break;
case 'v':
2016-04-26 10:30:54 -04:00
VERBOSE = 1;
2016-04-25 17:07:24 -04:00
break;
case 's':
set_bits = parse_int_arg(argv[ii+1]);
break;
case 'E':
lines = parse_int_arg(argv[ii+1]);
break;
case 'b':
block_bits = parse_int_arg(argv[ii+1]);
break;
case 't':
filename = argv[ii+1];
break;
}
}
2016-04-26 10:30:54 -04:00
printf("Arguments: %d, %d, %d, %d, %s\n", set_bits, lines, block_bits, VERBOSE, filename);
2016-04-25 17:07:24 -04:00
if(!set_bits|| !lines || !block_bits || !filename)
print_usage();
2016-04-24 20:07:46 -04:00
printSummary(0, 0, 0);
return 0;
}