diff --git a/csim.c b/csim.c index 7346b64..cb3f4bb 100644 --- a/csim.c +++ b/csim.c @@ -1,11 +1,12 @@ +/* asgoldsmith-jikomissar */ /** @file csim.c @author Adam Goldsmith @author Jacob Komissar @date 2016-04-25, 2016-04-26, 2016-04-27 - -@TODO ADD CORRECT NAME COMMENT AT TOP OF FILE - + + @TODO ADD CORRECT NAME COMMENT AT TOP OF FILE + Exit statuses: 0 - success 1 - usage error @@ -37,14 +38,16 @@ size_t parse_int_arg(char *arg, char opt); size_t bits_to_size(uint8_t bits); /* Global variables */ -uint8_t VERBOSE = 0; // If nonzero, mprintf will not print. Set in main() if -v flag is given. +uint8_t VERBOSE = 0; /**< If nonzero, mprintf will not print. Set in main() if -v flag is given. */ int main(int argc, char* argv[]) { + int hits, misses, evictions; + uint8_t set_index_bits = 0, block_bits = 0; // Not-useful input variables. - size_t set_indices = 0, lines = 0, block_size = 0; //Useful variables + size_t set_indices = 0, num_lines = 0, block_size = 0; //Useful variables char *filename = NULL; int opt = 0; while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) { @@ -58,7 +61,7 @@ int main(int argc, char* argv[]) set_indices = bits_to_size(set_index_bits); break; case 'E': // associativity - lines per set - lines = parse_int_arg(optarg, 'E'); + num_lines = parse_int_arg(optarg, 'E'); break; case 'b': // 2^b = block size block_bits = (uint8_t)parse_int_arg(optarg, 'b'); @@ -75,11 +78,11 @@ int main(int argc, char* argv[]) } } /* If any required arguments were not provided. (argflags != 0b1111) */ - if (!set_indices || !lines || !block_size || !filename) { + if (!set_indices || !num_lines || !block_size || !filename) { bad_usage_error(); } /* End of argument parsing. */ - printf("Arguments: s=%hhu, E=%zu, b=%hhu, t=%s, v=%hhu, 2^s=%zd, 2^b=%zu\n", set_index_bits, lines, block_bits, filename, VERBOSE, set_indices, block_size); + //printf("Arguments: s=%hhu, E=%zu, b=%hhu, t=%s, v=%hhu, 2^s=%zd, 2^b=%zu\n", set_index_bits, num_lines, block_bits, filename, VERBOSE, set_indices, block_size); /* FILE READING */ @@ -90,24 +93,21 @@ int main(int argc, char* argv[]) printf("Invalid file name: %s", filename); exit(-1); } - - while (fgets(buffer, 20, f)) - { + + while (fgets(buffer, 20, f)) { if (buffer[0] == 'I') continue; char* end; char op = buffer[1]; - long address = strtol(buffer+3, &end, 16); - if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M')) - { + void* address = strtol(buffer+3, &end, 16); + if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M')) { printf("Invalid input file, last line:\n%s\n", buffer); return -1; } printf("%c %ld\n", op, address); } - printSummary(0, 0, 0); return 0; } @@ -119,11 +119,12 @@ void print_usage(void) "Options:\n" " -h Print this help.\n" " -v Display trace info.\n" - " -s The number of set index bits. Must be a positive integer.\n" - " -E Associativity (lines per set). Must be a positive integer.\n" - " -b The number of block bits. Must be a positive integer.\n" - " -t Name of the file to read a valgrind trace from."); + " -s The number of set index bits. Must be a positive integer.\n" + " -E Associativity (lines per set). Must be a positive integer.\n" + " -b The number of block bits. Must be a positive integer.\n" + " -t Name of the file to read a valgrind trace from."); } + /** Prints the summarized usage and exits with status 1. */