diff options
Diffstat (limited to 'com.c')
-rw-r--r-- | com.c | 44 |
1 files changed, 33 insertions, 11 deletions
@@ -458,8 +458,14 @@ int main(int argc, char **argv) { S->do_disasm = false; S->do_trace = false; + char *infile_names[16]; + int infile_name_n = 0; for (int i = 1; i < argc; i++) { - if (argv[i][0] != '-') break; + if (argv[i][0] != '-') { + infile_names[infile_name_n++] = argv[i]; + CHECK(infile_name_n < 16, "input file count exceeded"); + continue; + } switch (argv[i][1]) { case 'D': CHECK(strlen(argv[i]) > 1, "unknown option a"); @@ -473,21 +479,37 @@ int main(int argc, char **argv) { } } - Compiler com = (Compiler){ 0 }; com.S = S; com.ch = &ch; + if (infile_name_n == 0) infile_names[infile_name_n++] = "-"; + + for (int i = 0; i < infile_name_n; i++) { + char *fname = infile_names[i]; + FILE *infile = NULL; + if (0 == strcmp(fname, "-")) + infile = stdin; + else + infile = fopen(fname, "r"); + + if (infile == NULL) { + perror("fopen"); + exit(1); + } + + AstNode an; + memset(&an, 0, sizeof an); + pcc_context_t *parser = pcc_create(infile); + int rv; + do { + astnode_free(&an); + rv = pcc_parse(parser, &an); + compile_node(&com, an); + } while (rv != 0); + pcc_destroy(parser); + } - AstNode an; - memset(&an, 0, sizeof an); - pcc_context_t *parser = pcc_create(NULL); - int rv; - do { - rv = pcc_parse(parser, &an); - compile_node(&com, an); - } while (rv != 0); - pcc_destroy(parser); compile_opcode(&com, OP_PUTS); compile_opcode(&com, OP_HALT); |