From 6e2f2af9640a4cb6eca1521458ca8f30ea2e6e51 Mon Sep 17 00:00:00 2001 From: TuDatTr Date: Fri, 11 Dec 2020 21:16:54 +0100 Subject: [PATCH] Made all necessary data and commandline arguments --- src/csim.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/src/csim.c b/src/csim.c index 2b6c08c..6913410 100644 --- a/src/csim.c +++ b/src/csim.c @@ -1,13 +1,92 @@ +/** + * Groupmembers: + * 1. Anna Schlittenhardt + * 2. Tuan-Dat Tran + */ + +#include +#include +#include +#include +#include +#include #include "cachelab.h" struct cache_line { unsigned char v; unsigned int tag; - unsigned long timestamp; + unsigned int timestamp; }; -int main() -{ - printSummary(0, 0, 0); - return 0; +typedef struct cache_line cache_line_t; + +void print_help() { + printf("Usage: ./csim-ref [-hv] -s -E -b -t "); + printf(" -h: Optional help flag that prints usage info"); + printf(" -v: Optional verbose flag that displays trace info"); + printf(" -s : Number of set index bits (S = 2 s is the number of sets)"); + printf(" -E : Associativity (number of lines per set)"); + printf(" -b : Number of block bits (B = 2 b is the block size)"); + printf(" -t : Name of the valgrind trace to replay"); +} + +int main(int argc, char *argv[]) { + int c; + int v = -1, s = -1, E = -1, b = -1, S, B; + FILE *tracefile = NULL; + int hit = 0, miss = 0, eviction = 0; + + while ((c = getopt(argc, argv, "s:E:b:t:vh")) != -1) { + switch (c) { + case 'h': + print_help(); + exit(0); + break; + case 'v': + v = 1; + break; + case 'E': + E = atoi(optarg); + break; + case 'b': + b = atoi(optarg); + break; + case 't': + tracefile = fopen(optarg, "r"); + break; + } + } + + if (v == -1 || s == -1 || E == -1 || b == -1 || tracefile == NULL) { + print_help(); + exit(0); + } + + S = pow(2, s); + B = pow(2, b); + + cache_line_t **cache = malloc(S*sizeof(cache_line_t*)); + + for (int i = 0; i < (S * sizeof(cache_line_t*)); i++) { + cache_line_t *cache_set = malloc(E*sizeof(struct cache_line)); + cache[i] = cache_set; + for (int j = 0; j < E; j++) { + cache_set[j].v = '\0'; + cache_set[j].tag = 0; + cache_set[j].timestamp = 0; + } + } + + + char op; // I = instruction, L = data load, S = data store, M = data modify + unsigned address; + int size; + + while (fscanf(tracefile, "%c %x %d", &op, &address, &size) > 0 ) { + } + + fclose(tracefile); + free(cache); + printSummary(0, 0, 0); + return 0; }