Add basic file parsing
This commit is contained in:
parent
8d8568fce1
commit
4f09ea0249
24
csim.c
24
csim.c
@ -62,6 +62,30 @@ int main(int argc, char* argv[])
|
|||||||
/* End of argument parsing. */
|
/* End of argument parsing. */
|
||||||
printf("Arguments: %zd, %zd, %zd, %hd, %s\n", set_index_bits, lines, block_bits, VERBOSE, filename);
|
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);
|
printSummary(0, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user