Browse Source

Add basic file parsing

masstesting
Adam Goldsmith 6 years ago
parent
commit
4f09ea0249
  1. 24
      csim.c

24
csim.c

@ -62,6 +62,30 @@ int main(int argc, char* argv[]) @@ -62,6 +62,30 @@ int main(int argc, char* argv[])
/* End of argument parsing. */
printf("Arguments: %zd, %zd, %zd, %hd, %s\n", set_index_bits, lines, block_bits, VERBOSE, filename);
char buffer[20];
FILE* f = fopen(filename, "r");
if(!f)
{
printf("Invalid file name: %s", filename);
exit(-1);
}
while (fgets(buffer, 20, f))
{
if (buffer[0] == 'I')
continue;
char* end;
char op = buffer[1];
long address = strtol(buffer+3, &end, 16);
if (*end != ',' || !(op == 'S' || op == 'L' || op == 'M'))
{
printf("Invalid input file, last line:\n%s\n", buffer);
return -1;
}
printf("%c %ld\n", op, address);
}
printSummary(0, 0, 0);
return 0;
}