-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParseInput.c
100 lines (90 loc) · 3.1 KB
/
ParseInput.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdlib.h>
#include <string.h>
//#include <stdio.h>
#include "ParseInput.h"
//Struct to hold arguments
//struct _ParsedArgs;
//above moved to header file
//returns null on error
ParsedArgs *parseInput(int argc, char **argv)
{
//5 bit number with each bit representing
int validCounter = 0;
int i, j, k;
ParsedArgs *myIns = (ParsedArgs *) malloc(sizeof(ParsedArgs));
if(argc != 10){
return NULL;
}
else{
//create ParsedArgs struct
// ParsedArgs myIns;
for( i = 0; i < 10; i+=2 )
{
if(strcmp(argv[i], "-f") == 0){
//trace file name
//get file name
for(j = 0; argv[i+1][j] != '\0'; ++j){}
char *traceName = (char *) malloc(sizeof(char)*j+2);
//copy file name
for(k = 0; k < j+2; k++){
traceName[k] = argv[i+1][k];
}
//add file name to myIns struct
myIns->traceFileName = traceName;
//set first bit of validCounter to 1
validCounter = validCounter | 1;
}
if(strcmp(argv[i], "-s") == 0){
//get cache size
myIns->cacheSize = -1;
myIns->cacheSize = atoi(argv[i+1]);
if(myIns->cacheSize > 8000 || myIns->cacheSize < 1){
break;
}
validCounter = validCounter | 2;
}
if(strcmp(argv[i], "-b") == 0){
//get block size
myIns->blockSize = -1;
myIns->blockSize = atoi(argv[i+1]);
if(myIns->blockSize < 4 || myIns->blockSize > 64){
break;
}
validCounter = validCounter | 4;
}
if(strcmp(argv[i], "-a") == 0){
//get associativeity
myIns->associativity = -1;
myIns->associativity = atoi(argv[i+1]);
if(myIns->associativity == 1 || myIns->associativity == 2 || myIns->associativity == 4 || myIns->associativity == 8 || myIns->associativity == 16){
validCounter = validCounter | 8;
}
else{
break;
}
}
if(strcmp(argv[i], "-r") == 0){
//get replacement policy
myIns->replacementVal = -1;
if(strcmp(argv[i+1], "RND") == 0)
{
myIns->replacementVal=0;
validCounter = validCounter | 16;
}
else if(strcmp(argv[i+1], "RR") == 0){
myIns->replacementVal = 1;
}
else{
break;
}
validCounter = validCounter | 16;
}
}
//check if valid bit true
if(validCounter != 31){
// printf("%d\n", validCounter);
return NULL;
}
return myIns;
}
}