summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/assembler.c60
-rw-r--r--lib/parser.c2
2 files changed, 56 insertions, 6 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();
+}
diff --git a/lib/parser.c b/lib/parser.c
index 47cae8d..7cc242d 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -269,7 +269,7 @@ void parse_line(char *line)
}
} else if (((buffer[0] >= 'A') && (buffer[0] <= 'Z')) || ((buffer[0] >= 'a') && (buffer[0] <= 'z'))
|| ((buffer[0] >= '0') && (buffer[0] <= '9')) || (buffer[0] == '_') || (buffer[0] == '"')
- || (buffer[0] == '\'') || (buffer[0] == '.') || (buffer[0] == '#')) {
+ || (buffer[0] == '\'') || (buffer[0] == '.') || (buffer[0] == '#') || (buffer[0] == '?')) {
/* Dans tous les autres cas, on a reçu un symbole, on le pose sur la pile */
push_pile(buffer);
got_unary = 0;