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

67 lines
1.4 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include "cachelab.h"
void print_usage()
{
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.");
exit(0);
}
int parse_int_arg(char* arg)
{
char* end;
int i = strtol(arg, &end, 0);
if (!i || *end != '\0')
{
printf("Invalid argument \"%s\"\n", arg);
print_usage();
}
return i;
}
int main(int argc, char* argv[])
{
int set_bits = 0, lines = 0, block_bits = 0, verbose = 0;
char* filename;
int ii;
for (ii = 0; ii < argc; ii++)
{
switch (argv[ii][1])
{
case 'h':
//print_usage();
break;
case 'v':
verbose = 1;
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;
}
}
printf("Arguments: %d, %d, %d, %d, %s\n", set_bits, lines, block_bits, verbose, filename);
if(!set_bits|| !lines || !block_bits || !filename)
print_usage();
printSummary(0, 0, 0);
return 0;
}