Use struct for score, add function to increment from char
This commit is contained in:
parent
a31fde98e4
commit
60fc5d1f0a
22
csim.c
22
csim.c
@ -31,6 +31,12 @@ struct linked_line_s {
|
||||
linked_line* older;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int hits;
|
||||
int misses;
|
||||
int evictions;
|
||||
} results;
|
||||
|
||||
|
||||
/* Macros */
|
||||
#define mprintf(...) if (VERBOSE) printf(__VA_ARGS__)
|
||||
@ -53,12 +59,17 @@ uint8_t VERBOSE = 0; /**< If nonzero, mprintf will not print. Set in main() if -
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int hits = 0, misses = 0, evictions = 0;
|
||||
results score;
|
||||
char buffer[20];
|
||||
int set_index_bits = 0, block_bits = 0; // Not-useful input variables.
|
||||
long set_indices = 0, num_lines = 0, block_size = 0; //Useful variables
|
||||
char *filename = NULL;
|
||||
int opt = 0;
|
||||
|
||||
score.hits = 0;
|
||||
score.misses = 0;
|
||||
score.evictions = 0;
|
||||
|
||||
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
||||
switch (opt) {
|
||||
/* TODO: maybe add checking for optarg swallowing actual arguments. */
|
||||
@ -120,7 +131,7 @@ int main(int argc, char* argv[])
|
||||
printf("%c %ld\n", op, address);
|
||||
}
|
||||
|
||||
printSummary(hits, misses, evictions);
|
||||
printSummary(score.hits, score.misses, score.evictions);
|
||||
|
||||
fclose(f);
|
||||
free_cache(cache, set_index_bits);
|
||||
@ -128,7 +139,12 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void increment_result_counters(char result, results* score)
|
||||
{
|
||||
score->hits += (result == 'H');
|
||||
score->misses += (result == 'M' || result == 'E');
|
||||
score->evictions += (result == 'E');
|
||||
}
|
||||
|
||||
|
||||
linked_line** make_cache(long set_indices, long num_lines)
|
||||
|
Reference in New Issue
Block a user