diff --git a/.gitignore b/.gitignore index ddbd27a..d31d8a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *.o -lex.yy.c +lex.yy.* as.tab.* -output.asm -output_bin.txt +*.asm +!input.asm +*.txt cross_assembleur + diff --git a/as.y b/as.y index dd72bf1..dd2a42c 100644 --- a/as.y +++ b/as.y @@ -62,13 +62,31 @@ Instruction : tCPY tNB tNB {increment_time(); %% -int main(void) { - file = fopen("output.asm", "w"); - file2 = fopen("output_bin.txt", "w"); +#include + +int main(int argc, char *argv[]) { + char *output_filename = "output_cross"; + + if (argc >= 2) { + output_filename = argv[1]; + } + + char *asm_filename = malloc(strlen(output_filename) + 5); + char *bin_filename = malloc(strlen(output_filename) + 9); + strcpy(asm_filename, output_filename); + strcpy(bin_filename, output_filename); + strcat(asm_filename, ".asm"); + strcat(bin_filename, "_bin.txt"); + + file = fopen(asm_filename, "w"); + file2 = fopen(bin_filename, "w"); init(); - yyparse(); + yyparse(); flush_and_init(); - write_asm(file); - write_code_machine(file2); - return 0; + write_asm(file); + write_code_machine(file2); + + free(asm_filename); + free(bin_filename); + return 0; }