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.
This commit is contained in:
Jacob 2016-04-27 13:40:58 -04:00
parent 4f09ea0249
commit 3b97949150

49
csim.c
View File

@ -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"
#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) {