From 60fc5d1f0ab72ee7fee0a7410d28fb8169ea4c00 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 28 Apr 2016 01:40:54 -0400 Subject: [PATCH] Use struct for score, add function to increment from char --- csim.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/csim.c b/csim.c index 08ff657..8823c95 100644 --- a/csim.c +++ b/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)