Various minor changes.
Renamed lines to num_lines. Removed trailing whitespaces. Fixed some indentation and comments. Fixed usage string.
This commit is contained in:
parent
50ee8769fa
commit
fb6c9e3a27
25
csim.c
25
csim.c
@ -1,10 +1,11 @@
|
|||||||
|
/* asgoldsmith-jikomissar */
|
||||||
/**
|
/**
|
||||||
@file csim.c
|
@file csim.c
|
||||||
@author Adam Goldsmith
|
@author Adam Goldsmith
|
||||||
@author Jacob Komissar
|
@author Jacob Komissar
|
||||||
@date 2016-04-25, 2016-04-26, 2016-04-27
|
@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:
|
Exit statuses:
|
||||||
0 - success
|
0 - success
|
||||||
@ -37,14 +38,16 @@ size_t parse_int_arg(char *arg, char opt);
|
|||||||
size_t bits_to_size(uint8_t bits);
|
size_t bits_to_size(uint8_t bits);
|
||||||
|
|
||||||
/* Global variables */
|
/* 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 main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
int hits, misses, evictions;
|
||||||
|
|
||||||
uint8_t set_index_bits = 0, block_bits = 0; // Not-useful input variables.
|
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;
|
char *filename = NULL;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
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);
|
set_indices = bits_to_size(set_index_bits);
|
||||||
break;
|
break;
|
||||||
case 'E': // associativity - lines per set
|
case 'E': // associativity - lines per set
|
||||||
lines = parse_int_arg(optarg, 'E');
|
num_lines = parse_int_arg(optarg, 'E');
|
||||||
break;
|
break;
|
||||||
case 'b': // 2^b = block size
|
case 'b': // 2^b = block size
|
||||||
block_bits = (uint8_t)parse_int_arg(optarg, 'b');
|
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 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();
|
bad_usage_error();
|
||||||
}
|
}
|
||||||
/* End of argument parsing. */
|
/* 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 */
|
/* FILE READING */
|
||||||
@ -91,23 +94,20 @@ int main(int argc, char* argv[])
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(buffer, 20, f))
|
while (fgets(buffer, 20, f)) {
|
||||||
{
|
|
||||||
if (buffer[0] == 'I')
|
if (buffer[0] == 'I')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char* end;
|
char* end;
|
||||||
char op = buffer[1];
|
char op = buffer[1];
|
||||||
long address = strtol(buffer+3, &end, 16);
|
void* address = strtol(buffer+3, &end, 16);
|
||||||
if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M'))
|
if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M')) {
|
||||||
{
|
|
||||||
printf("Invalid input file, last line:\n%s\n", buffer);
|
printf("Invalid input file, last line:\n%s\n", buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("%c %ld\n", op, address);
|
printf("%c %ld\n", op, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printSummary(0, 0, 0);
|
printSummary(0, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -124,6 +124,7 @@ void print_usage(void)
|
|||||||
" -b <number> The number of block bits. Must be a positive integer.\n"
|
" -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.");
|
" -t <file> Name of the file to read a valgrind trace from.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Prints the summarized usage and exits with status 1.
|
Prints the summarized usage and exits with status 1.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user