diff options
author | Pixel <> | 2001-04-15 15:15:48 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-15 15:15:48 +0000 |
commit | 9e39a9d01a90080114a4cb7521b00184a586b31f (patch) | |
tree | b5f714fdce019603850cfaa4ce85dded6ba3f113 /lib/assembler.c | |
parent | 4d1b1a16faa7406d028eded8334dfcbc5e44df92 (diff) |
Assembleur...
Diffstat (limited to 'lib/assembler.c')
-rw-r--r-- | lib/assembler.c | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/lib/assembler.c b/lib/assembler.c index 34ee48a..bd10954 100644 --- a/lib/assembler.c +++ b/lib/assembler.c @@ -131,7 +131,7 @@ static bytestream_t *pushuninit(int size) s->Expr = NULL; s->line = line; - s->filename = filenames[nestedinc]; + s->filename = filenames[nestedinc - 1]; switch (segment) { @@ -475,7 +475,7 @@ void push_pile(char *a) e->e_subtype = E_LABEL; } - /* Cas des pseudos instructions {DB, DW, DD, DS} */ + /* Cas des pseudos instructions {DB, DW, DD, DS, DR} */ if (wc <= 1) { trouve = 0; @@ -486,13 +486,19 @@ void push_pile(char *a) switch (downcase(*(a + 1))) { case 'b': e->op = 1; + break; case 'w': e->op = 2; + break; case 'd': e->op = 3; + break; case 's': e->op = 4; break; + case 'r' + e->op = 5; + break; default: trouve = 0; } @@ -522,7 +528,7 @@ void push_pile(char *a) /* Dans tous les autres cas, nous considerons qu'il s'agit d'une référence à un label... */ if (e->e_subtype == E_STRING) { - if ((e->symbol[0] != '\"') && (e->symbol[0] != '\'')) { + if (((e->symbol[0] != '\"') && (e->symbol[0] != '\'')) && (strcmp(e->symbol, "?"))) { e->e_subtype = E_LABEL; } } @@ -545,7 +551,9 @@ void push_pile(char *a) } sprintf(err, _("Including file at line %i"), line); pushcontext(err); - process_file(a); + if (process_file(a)) { + exception(1, _("Error reading include file")); + } popcontext(); break; } @@ -1512,6 +1520,12 @@ void asm_eol(void) case E_VALUE: pushdword(e_current->avalue, NULL); break; + case E_STRING: + if (!strcmp(e_current->symbol, "?")) { + exception(1, _("Unknow constant")); + } + pushuninit(1); + break; case E_LABEL: case E_OPERATION: pushdword(0, e_current); @@ -1538,6 +1552,23 @@ void asm_eol(void) } } while (1); break; + case 5: + do { + e_line = e_current->next; + e_current->next = NULL; + free_expr(e_current); + e_current = e_line; + if (!e_current) + break; + switch (e_current->e_subtype) { + case E_VALUE: + pushuninit(e_current->avalue); + break; + default: + exception(1, _("Bad array size")); + } + } while (1); + break; } break; case E_INSTRUCT: @@ -1649,6 +1680,7 @@ void asm_eol(void) void asm_eof(void) { + } static void delete_bytestream(bytestream_t * s) @@ -1667,7 +1699,7 @@ void assembler_flush(void) delete_bytestream(bss); } -int process_file(char *name) +static int process_file(char *name) { FILE *f; char buf[BUFSIZ], errctx[BUFSIZ], *p; @@ -1705,3 +1737,21 @@ int process_file(char *name) fclose(f); return 0; } + +void assemble_file(char * iname, char * oname) { + FILE * f; + + pushcontext(_("Opening output file")); + if (!(f = fopen(oname, "wb"))) { + pushcontext(stderror(errno)); + exception(1, _("Error writing output file")); + } + popcontext(); + if (!process_file(iname)) { + exception(1, _("Error reading file")); + } + pushcontext(_("Writing output file")); + asm_eof(f); + fclose(f); + popocontext(); +} |