Add cache allocation and free functions
This commit is contained in:
parent
d16bf870f6
commit
2fc771d08e
22
csim.c
22
csim.c
@ -36,6 +36,8 @@ void print_usage(void);
|
|||||||
void bad_usage_error(void);
|
void bad_usage_error(void);
|
||||||
size_t parse_int_arg(char *arg, char opt);
|
size_t parse_int_arg(char *arg, char opt);
|
||||||
size_t bits_to_size(uint8_t bits);
|
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 */
|
/* Global variables */
|
||||||
uint8_t VERBOSE = 0; /**< If nonzero, mprintf will not print. Set in main() if -v flag is given. */
|
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. */
|
/* 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);
|
//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 */
|
/* FILE READING */
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
@ -109,9 +113,27 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
printSummary(0, 0, 0);
|
printSummary(0, 0, 0);
|
||||||
|
free_cache(cache, num_lines);
|
||||||
|
|
||||||
return 0;
|
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)
|
void print_usage(void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user