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:
parent
4f09ea0249
commit
3b97949150
49
csim.c
49
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 <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include "cachelab.h"
|
#include "cachelab.h"
|
||||||
|
|
||||||
#define mprintf(...) if (VERBOSE) printf(__VA_ARGS__)
|
/* Typedefs and structs */
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
void print_usage();
|
/* UNSURE. As defined in conference. */
|
||||||
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. */
|
|
||||||
struct line_s {
|
struct line_s {
|
||||||
int8_t validity;
|
uint8_t validity;
|
||||||
int tag;
|
int tag;
|
||||||
};
|
};
|
||||||
typedef struct line_s line;
|
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[])
|
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;
|
char *filename = NULL;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
while ((opt=getopt(argc, argv, "hvs:E:b:t:")) != -1) {
|
||||||
|
Reference in New Issue
Block a user