Made all necessary data and commandline arguments

master
TuDatTr 2020-12-11 21:16:54 +01:00
parent 3789bbf2b6
commit 6e2f2af964
1 changed files with 84 additions and 5 deletions

View File

@ -1,13 +1,92 @@
/**
* Groupmembers:
* 1. Anna Schlittenhardt
* 2. Tuan-Dat Tran
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include "cachelab.h" #include "cachelab.h"
struct cache_line { struct cache_line {
unsigned char v; unsigned char v;
unsigned int tag; unsigned int tag;
unsigned long timestamp; unsigned int timestamp;
}; };
int main() typedef struct cache_line cache_line_t;
{
printSummary(0, 0, 0); void print_help() {
return 0; printf("Usage: ./csim-ref [-hv] -s <s> -E <E> -b <b> -t <tracefile>");
printf(" -h: Optional help flag that prints usage info");
printf(" -v: Optional verbose flag that displays trace info");
printf(" -s <s>: Number of set index bits (S = 2 s is the number of sets)");
printf(" -E <E>: Associativity (number of lines per set)");
printf(" -b <b>: Number of block bits (B = 2 b is the block size)");
printf(" -t <tracefile>: 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;
} }