Add function to print cache

This commit is contained in:
Adam Goldsmith 2016-04-27 22:16:16 -04:00
parent c26d27db9d
commit 92ae2a0a2b

20
csim.c
View File

@ -44,6 +44,8 @@ linked_line** make_cache(long set_indices, long num_lines);
linked_line* make_set(linked_line* newer, long num_lines);
void free_cache(linked_line** cache, long num_sets);
void free_set(linked_line* line);
void print_cache(linked_line** cache, long num_sets);
void print_set(linked_line* line);
/* Global variables */
uint8_t VERBOSE = 0; /**< If nonzero, mprintf will not print. Set in main() if -v flag is given. */
@ -93,6 +95,8 @@ int main(int argc, char* argv[])
linked_line** cache = make_cache(set_indices, num_lines);
print_cache(cache, set_indices);
/* FILE READING */
FILE* f = fopen(filename, "r");
if(!f)
@ -177,6 +181,22 @@ void free_set(linked_line* line) {
}
}
void print_cache(linked_line** cache, long num_sets)
{
int ii;
for (ii = 0; ii < num_sets; ii++) {
print_set(cache[ii]);
}
}
void print_set(linked_line* line)
{
if (line != NULL) {
print_set(line->older);
printf("%p %x.%lx %p:%p\n", (void *) line, line->validity, line->tag, (void *) line->newer, (void *) line->older);
}
}
void print_usage(void)
{
printf("Usage: ./csim [-hv] -s <number> -E <number> -b <number> -t <file>\n"