Various minor changes.

Renamed lines to num_lines.
Removed trailing whitespaces.
Fixed some indentation and comments.
Fixed usage string.
This commit is contained in:
Jacob 2016-04-27 15:55:27 -04:00
parent 50ee8769fa
commit fb6c9e3a27

23
csim.c
View File

@ -1,3 +1,4 @@
/* asgoldsmith-jikomissar */
/**
@file csim.c
@author Adam Goldsmith
@ -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 */
@ -91,23 +94,20 @@ int main(int argc, char* argv[])
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;
}
@ -124,6 +124,7 @@ void print_usage(void)
" -b <number> The number of block bits. Must be a positive integer.\n"
" -t <file> Name of the file to read a valgrind trace from.");
}
/**
Prints the summarized usage and exits with status 1.
*/