Add cache allocation and free functions

This commit is contained in:
Adam Goldsmith 2016-04-27 16:13:27 -04:00
parent d16bf870f6
commit 2fc771d08e

22
csim.c
View File

@ -36,6 +36,8 @@ 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);
line** make_cache(size_t set_indices, size_t lines);
void free_cache(line** cache, size_t lines);
/* Global variables */
uint8_t VERBOSE = 0; /**< If nonzero, mprintf will not print. Set in main() if -v flag is given. */
@ -84,6 +86,8 @@ int main(int argc, char* argv[])
/* End of argument parsing. */
//printf("Arguments: s=%hhu, E=%zu, b=%hhu, t=%s, v=%hhu, 2^s=%zd, 2^b=%zu\n", set_index_bits, num_lines, block_bits, filename, VERBOSE, set_indices, block_size);
line** cache = make_cache(set_indices, num_lines);
/* FILE READING */
char buffer[20];
@ -109,9 +113,27 @@ int main(int argc, char* argv[])
}
printSummary(0, 0, 0);
free_cache(cache, num_lines);
return 0;
}
line** make_cache(size_t set_indices, size_t lines)
{
line** cache = calloc(set_indices, sizeof(line*));
int ii;
for (ii = 0; ii < lines; ii++)
cache[ii] = calloc(lines, sizeof(line));
return cache;
}
void free_cache(line** cache, size_t lines)
{
int ii;
for (ii = 0; ii < lines; ii++)
free(cache[ii]);
free(cache);
}
void print_usage(void)
{