|
|
|
@ -1,31 +1,50 @@
@@ -1,31 +1,50 @@
|
|
|
|
|
/**
|
|
|
|
|
@file csim.c |
|
|
|
|
@author Adam Goldsmith |
|
|
|
|
@author Jacob Komissar |
|
|
|
|
@date 2016-04-25, 2016-04-26, 2016-04-27 |
|
|
|
|
|
|
|
|
|
@TODO ADD CORRECT NAME COMMENT AT TOP OF FILE |
|
|
|
|
|
|
|
|
|
Exit statuses: |
|
|
|
|
0 - success |
|
|
|
|
1 - usage error |
|
|
|
|
-1 - file error |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
/* Headers */ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <getopt.h> |
|
|
|
|
#include <stdint.h> |
|
|
|
|
#include "cachelab.h" |
|
|
|
|
|
|
|
|
|
/* Typedefs and structs */ |
|
|
|
|
typedef unsigned char uint8_t; |
|
|
|
|
/* UNSURE. As defined in conference. */ |
|
|
|
|
struct line_s { |
|
|
|
|
uint8_t validity; |
|
|
|
|
int tag; |
|
|
|
|
}; |
|
|
|
|
typedef struct line_s line; |
|
|
|
|
|
|
|
|
|
/* Macros */ |
|
|
|
|
#define mprintf(...) if (VERBOSE) printf(__VA_ARGS__) |
|
|
|
|
|
|
|
|
|
void print_usage(); |
|
|
|
|
/* Prototypes */ |
|
|
|
|
void print_usage(void); |
|
|
|
|
void bad_usage_error(void); |
|
|
|
|
size_t parse_int_arg(char *arg, char opt); |
|
|
|
|
size_t bits_to_size(uint8_t bits); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
If VERBOSE is non-zero, mprintf will not print. Otherwise, it will. |
|
|
|
|
Set in main(). |
|
|
|
|
*/ |
|
|
|
|
int8_t VERBOSE = 0; |
|
|
|
|
/* Global variables */ |
|
|
|
|
uint8_t VERBOSE = 0; // If nonzero, mprintf will not print. Set in main() if -v flag is given.
|
|
|
|
|
|
|
|
|
|
/* USURE. As defined in conference. */ |
|
|
|
|
struct line_s { |
|
|
|
|
int8_t validity; |
|
|
|
|
int tag; |
|
|
|
|
}; |
|
|
|
|
typedef struct line_s line; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) |
|
|
|
|
{ |
|
|
|
|
size_t set_index_bits = 0, lines = 0, block_bits = 0; // Useful variables.
|
|
|
|
|
uint8_t set_index_bits = 0, block_bits = 0; // Not-useful input variables.
|
|
|
|
|
size_t set_indices = 0, lines = 0, block_size = 0; //Useful variables
|
|
|
|
|
char *filename = NULL; |
|
|
|
|
int opt = 0; |
|
|
|
|
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) { |
|
|
|
|