From 3b979491501cb501b2007ab78c7a5fd0e7c776bd Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 27 Apr 2016 13:40:58 -0400 Subject: [PATCH] Implemented size calculation. Various minor changes. Replaced repeated "printf(...);exit(1)" with bad_usage_error(). Added bits_to_size(). Reorganized code above main(). Added file doc comment. Expanded argument-printing statement for better testing. --- csim.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/csim.c b/csim.c index 9ac1d73..b57e0de 100644 --- a/csim.c +++ b/csim.c @@ -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 #include #include -#include #include "cachelab.h" -#define mprintf(...) if (VERBOSE) printf(__VA_ARGS__) - -void print_usage(); -size_t parse_int_arg(char *arg, char opt); - -/** - If VERBOSE is non-zero, mprintf will not print. Otherwise, it will. - Set in main(). - */ -int8_t VERBOSE = 0; - -/* USURE. As defined in conference. */ +/* Typedefs and structs */ +typedef unsigned char uint8_t; +/* UNSURE. As defined in conference. */ struct line_s { - int8_t validity; + uint8_t validity; int tag; }; typedef struct line_s line; +/* Macros */ +#define mprintf(...) if (VERBOSE) printf(__VA_ARGS__) + +/* 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); + +/* Global variables */ +uint8_t VERBOSE = 0; // If nonzero, mprintf will not print. Set in main() if -v flag is given. + + 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) {