Verified Commit b273851e authored by Camil Staps's avatar Camil Staps 🙂

Only allow one ABC file as input to bytecode generator

More than one file as input leads to an incorrect symbol table. This is
because enter_label overwrites labels from the previously seen module,
which means the old labels (from the previously seen module) are never
printed.

This was not a problem for the old bytecode generator by John (which did
not output a symbol table), but it has been a problem ever since we added
proper relocations.
parent 81f446dc
Pipeline #43759 failed with stages
in 8 minutes and 53 seconds
......@@ -22,29 +22,13 @@ void parse_file(FILE *file) {
free(line);
}
void parse_files(FILE **abc_files, unsigned int nr_abc_files) {
init_parser();
init_instruction_table();
load_instruction_table();
// Parse every file
unsigned int i;
for(i = 0; i < nr_abc_files; i++) {
parse_file(abc_files[i]);
fclose(abc_files[i]);
}
free_instruction_table();
}
int main (int argc, char *argv[]) {
if(argc < 2) {
fprintf(stderr, "Error: No ABC file specified\n");
return -1;
}
FILE **input_files = safe_malloc(sizeof(FILE*) * (argc-1));
unsigned int nr_abc_files = 0;
FILE *input_file=NULL;
FILE *output_file = NULL;
int i;
......@@ -59,23 +43,27 @@ int main (int argc, char *argv[]) {
}
i++;
} else {
if((input_files[i-1] = fopen(argv[i], "r")) == NULL) {
fprintf(stderr, "Error: Could not open abc file: %s\n", argv[i]);
if (input_file!=NULL){
fprintf (stderr,"Error: At most one ABC file can be specified\n");
return -1;
} else if((input_file=fopen (argv[i],"r"))==NULL) {
fprintf (stderr,"Error: Could not open abc file: %s\n",argv[i]);
return -1;
}
nr_abc_files++;
}
}
if (!output_file) {
fprintf(stderr, "Usage: %s ABC [ABC ...] -o OUTPUT\n", argv[0]);
fprintf(stderr, "Usage: %s ABC -o OUTPUT\n", argv[0]);
return -1;
}
// List of lines per file
initialize_code();
parse_files(input_files, nr_abc_files);
init_parser();
init_instruction_table();
load_instruction_table();
parse_file (input_file);
free_instruction_table();
add_add_arg_labels();
write_program(output_file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment