summaryrefslogtreecommitdiff
path: root/lib/assembler.c
diff options
context:
space:
mode:
authorPixel <>2001-04-16 22:47:34 +0000
committerPixel <>2001-04-16 22:47:34 +0000
commitb77b22b3bd99c03b032cbd47465b1cbe34821120 (patch)
tree7ae93778e189d7f67ee9f72fb3a813883558647a /lib/assembler.c
parentcb850755d0ca7c625fe418ef6b9770876c3308f2 (diff)
Blouarf
Diffstat (limited to 'lib/assembler.c')
-rw-r--r--lib/assembler.c114
1 files changed, 76 insertions, 38 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index edf6aed..64eafb9 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -1235,6 +1235,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
break;
}
}
+
+ debug_print_expression(e);
for (instructs = instructs->next; instructs; instructs = instructs->next) {
t = e;
@@ -1255,22 +1257,22 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
break;
case 'C':
- if ((t->e_subtype != E_VALUE) && (t->e_subtype != E_LABEL)
- && (t->e_subtype != E_OPERATION)) {
+ if ((t->e_subtype != E_VALUE) && (t->e_subtype != E_LABEL)) {
go_out = 1;
- if (t->e_subtype == E_OPERATION) {
- if (t->op == OP_FUNC_CALL)
- go_out = 0;
- }
}
- if ((t->e_subtype == E_OPERATION) && (!(((t->child->e_subtype == E_LABEL)
- && (t->child->next->e_subtype ==
- E_VALUE))
- || ((t->child->e_subtype == E_VALUE)
- && (t->child->next->e_subtype ==
- E_LABEL))))) {
- go_out = 1;
+ if ((t->e_subtype == E_OPERATION)
+ && ((t->op == OP_PLUS) || (t->op == OP_MOINS))) {
+ if (((t->child->e_subtype == E_LABEL)
+ && (t->child->next->e_subtype == E_VALUE))
+ || ((t->child->e_subtype == E_VALUE)
+ && (t->child->next->e_subtype == E_LABEL))) {
+ go_out = 0;
+ }
+ }
+
+ if ((t->e_subtype == E_OPERATION) && (t->op == OP_FUNC_CALL)) {
+ go_out = 0;
}
break;
@@ -1292,6 +1294,34 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
}
+ if (instructs) {
+ fprintf(stderr, " o Instruction contenant %i champs explicites et %i champs implicites.\n",
+ instructs->nbexplicit, instructs->nbimplicit);
+ fprintf(stderr, " => Champs explicites.\n");
+ for (i = 0; i < instructs->nbexplicit; i++) {
+ fprintf(stderr, " + %s <= %s (type %s)\n",
+ instructs->names[i],
+ instructs->strings[i] ? instructs->strings[i] : "Pas de chaîne associée",
+ instructs->etypes[i] ? "prédéfinit" : "direct");
+ }
+ fprintf(stderr, " => Champs implicites.\n");
+ for (i = 0; i < instructs->nbimplicit; i++) {
+ switch (instructs->itypes[i]) {
+ case 0:
+ fprintf(stderr, " + %s <= %s (type direct)\n", instructs->implicits[i],
+ instructs->istrings[i]);
+ break;
+ case 1:
+ fprintf(stderr, " + %s <= %s (type prédéfinit)\n", instructs->implicits[i],
+ instructs->istrings[i]);
+ break;
+ case 2:
+ fprintf(stderr, " + %s <= %i (type valeur)\n", instructs->implicits[i],
+ instructs->ivalues[i]);
+ break;
+ }
+ }
+ }
return instructs;
}
@@ -1421,7 +1451,6 @@ static int evaluate_field(_TableauVariable it, char *field, field_t * fields)
break;
}
}
-
if (!(fields)) {
exception(1, _("Unknow field in metalanguage"));
}
@@ -1456,7 +1485,7 @@ void asm_eol(void)
int i;
char trouve;
_TableauVariable it;
- bytestream_t * pi;
+ bytestream_t *pi;
switch (special) {
case 2: /* Cas de #define */
@@ -1470,7 +1499,6 @@ void asm_eol(void)
break;
case 0: /* Cas normal */
/* C'est ici la bonne histoire... Il faut reconnaitre l'instruction */
-
e_current = e_line;
if (!(e_current))
break;
@@ -1577,7 +1605,7 @@ void asm_eol(void)
/* Operation cruciale: nous avons l'instruction qui correspond le mieux à notre
expression, on va tenter de l'évaluer */
-
+
pi = pushuninit(1);
Initialise(&it);
@@ -1672,7 +1700,7 @@ void asm_eol(void)
break;
}
}
-
+
pi->Encoded = evaluate_field(it, "FI", fields);
DetruitTab(&it);
break;
@@ -1694,7 +1722,7 @@ void asm_eol(void)
static void writeword(unsigned long int a, FILE * f, int n)
{
int i;
-
+
fprintf(stderr, "ÉCriture de %08lX sur %i\n", a, fileno(f));
if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) {
@@ -1735,10 +1763,7 @@ static void writestring(char *string, FILE * f)
| | | .| | |
| +---+--+---+ |
| |
-\****************/
-
-/* Cette fonction ajoute un fichier à un autre */
-
+\****************//* Cette fonction ajoute un fichier à un autre */
void appendfile(FILE * f, char *name)
{
unsigned long int a;
@@ -1790,8 +1815,8 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping text segment"));
for (ttext = ttext->next; ttext; ttext = ttext->next) {
- sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), ttext->offset,
- ttext->line, ttext->filename);
+ sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."),
+ ttext->offset, ttext->line, ttext->filename);
fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
@@ -1803,6 +1828,7 @@ void asm_eof(FILE * f)
a = ttext->Expr->avalue;
break;
case E_LABEL:
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->symbol);
a = ttext->Expr->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1819,7 +1845,9 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op == OP_DECAL) {
- if ((ttext->Expr->child->e_subtype == E_LABEL) && (ttext->Expr->child->next->e_subtype == E_VALUE)) {
+ if ((ttext->Expr->child->e_subtype == E_LABEL)
+ && (ttext->Expr->child->next->e_subtype == E_VALUE)) {
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1831,8 +1859,13 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op == OP_PLUS) {
- if (((ttext->Expr->child->e_subtype == E_LABEL) && (ttext->Expr->child->next->e_subtype == E_VALUE)) || ((ttext->Expr->child->e_subtype == E_VALUE) && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
+ if (((ttext->Expr->child->e_subtype == E_LABEL)
+ && (ttext->Expr->child->next->e_subtype == E_VALUE))
+ || ((ttext->Expr->child->e_subtype == E_VALUE)
+ && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
if (ttext->Expr->child->e_subtype == E_LABEL) {
+ fprintf(stderr, "Symbole externe %s\n",
+ ttext->Expr->child->symbol);
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1841,6 +1874,8 @@ void asm_eof(FILE * f)
writestring(ttext->Expr->child->symbol, f2);
nbe++;
} else {
+ fprintf(stderr, "Symbole externe %s\n",
+ ttext->Expr->child->next->symbol);
a = ttext->Expr->child->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1891,6 +1926,7 @@ void asm_eof(FILE * f)
} else {
if (ttext->Label) {
nbsymbols++;
+ fprintf(stderr, "Symbole interne %s\n", ttext->Label);
writeword(0, f2, 1);
writeword(ttext->offset, f2, 1);
if (ttext->Label[strlen(ttext->Label) - 1] == ':') {
@@ -1909,8 +1945,8 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping data segment"));
for (tdata = tdata->next; tdata; tdata = tdata->next) {
- sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), tdata->offset,
- tdata->line, tdata->filename);
+ sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."),
+ tdata->offset, tdata->line, tdata->filename);
fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
@@ -1923,9 +1959,10 @@ void asm_eof(FILE * f)
break;
case E_LABEL:
a = tdata->Expr->avalue;
+ fprintf(stderr, "Symbole externe %s\n", tdata->Expr->child->symbol);
nbsymbols++;
writeword(3, f2, 1);
- writeword(tdata->offset + s_text, f2, 1);
+ writeword(tdata->offset, f2, 1);
writeword(strlen(tdata->Expr->symbol), f2, 1);
writestring(tdata->Expr->symbol, f2);
nbe++;
@@ -1970,8 +2007,9 @@ void asm_eof(FILE * f)
} else {
if (tdata->Label) {
nbsymbols++;
+ fprintf(stderr, "Symbole interne %s\n", tdata->Label);
writeword(2, f2, 1);
- writeword(tdata->offset + s_text, f2, 1);
+ writeword(tdata->offset, f2, 1);
writeword(strlen(tdata->Label), f2, 1);
writestring(tdata->Label, f2);
nbi++;
@@ -1987,15 +2025,16 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping bss segment"));
for (tbss = tbss->next; tbss; tbss = tbss->next) {
- sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), tbss->offset,
- tbss->line, tbss->filename);
+ sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."),
+ tbss->offset, tbss->line, tbss->filename);
pushcontext(errctx);
if (!tbss->size) {
if (tbss->Label) {
nbsymbols++;
writeword(4, f2, 1);
- writeword(tbss->offset + s_text + s_data, f2, 1);
+ fprintf(stderr, "Symbole interne %s\n", tbss->Label);
+ writeword(tbss->offset, f2, 1);
writeword(strlen(tbss->Label), f2, 1);
writestring(tbss->Label, f2);
nbi++;
@@ -2054,10 +2093,7 @@ void assembler_flush(void)
delete_bytestream(data);
delete_bytestream(bss);
}
-
-/* Fonction générique qui va traiter un fichier entier */
-
-static int process_file(char *name)
+/* Fonction générique qui va traiter un fichier entier */ static int process_file(char *name)
{
FILE *f;
char buf[BUFSIZ], errctx[BUFSIZ], *p;
@@ -2072,6 +2108,7 @@ static int process_file(char *name)
return 1;
}
popcontext();
+
pushcontext(_("Reading file"));
while (fgets(buf, BUFSIZ, f)) {
sprintf(errctx, _("Reading line %i"), line = ++i);
@@ -2109,6 +2146,7 @@ void assemble_file(char *iname, char *oname)
exception(1, _("Error writing output file"));
}
popcontext();
+
if (process_file(iname)) {
exception(1, _("Error reading file"));
}