summaryrefslogtreecommitdiff
path: root/lib/assembler.c
diff options
context:
space:
mode:
authorPixel <>2001-04-16 14:25:48 +0000
committerPixel <>2001-04-16 14:25:48 +0000
commit47f363829678a02111423cd5d374e6739d8ea500 (patch)
tree5c288a8902492e1a91d87ba4ab1cca658e39cbfa /lib/assembler.c
parent27f796ab6a9f455bbd2a1c85088db5304cece75a (diff)
Linker + bugfixes
Diffstat (limited to 'lib/assembler.c')
-rw-r--r--lib/assembler.c146
1 files changed, 35 insertions, 111 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index c2802da..ea8b085 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -172,8 +172,6 @@ static bytestream_t *pushdword(unsigned long int d, expression_t * e)
exception(1, _("You have to be into the .text or the .data segment to define a value."));
}
- fprintf(stderr, "On pousse %i avec %p\n", d, e);
-
s = pushuninit(1);
s->Encoded = d;
if (e) {
@@ -207,6 +205,8 @@ static void pushstring(char *s)
{
char marker = *s, tstring[6];
int valid;
+
+ s++;
while ((*s) && (marker != *s)) {
if (*s == '\\') {
@@ -1231,24 +1231,15 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
if (!instructs->strings[i]) {
if (strcasecmp(instructs->names[i], i ? t->symbol : stringtolook)) {
go_out = 1;
- } else
- fprintf(stderr, "On a reconnu le mot %s au %i eme mot\n", t->symbol, i);
+ }
} else {
switch (instructs->strings[i][0]) {
case 'P':
if (!t->pattern) {
- fprintf(stderr,
- "On a une pattern sur le mot %i, mais pas dans l'instruction...\n",
- i);
go_out = 1;
} else {
- fprintf(stderr,
- "On a la pattern %s sur le mot %i, on la compare avec %s\n",
- instructs->strings[i] + 1, i, t->pattern->name);
if (strcasecmp(instructs->strings[i] + 1, t->pattern->name))
go_out = 1;
- else
- fprintf(stderr, "Ok, on ne sort pas.\n");
}
break;
case 'C':
@@ -1280,7 +1271,6 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
if (!(t = t->next) && ((i + 1) < instructs->nbexplicit)) {
go_out = 1;
- fprintf(stderr, "On sort quand même... (t = %p et i = %i)\n", t, i);
}
}
@@ -1289,38 +1279,6 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
}
- if (instructs) {
- fprintf(stderr, "Nous avons reconnu une instruction:\n");
- 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;
- }
- }
- } else {
- fprintf(stderr, "Nous n'avons pas reconnu l'instruction.\n");
- }
-
return instructs;
}
@@ -1334,24 +1292,19 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
exception(1, _("Pattern not matching..."));
}
- fprintf(stderr, "Evaluation de la pattern %s, index %i\n", e->pattern->name, e->index);
m = e->pattern->expr[e->index];
if (m->name) {
- fprintf(stderr, "La pattern a un nom\n");
if (m->string) {
- fprintf(stderr, "et une string associée\n");
if (m->type) {
if (strcmp(m->name, "I")) {
exception(1, _("Unknow constant type in the meta language"));
}
- fprintf(stderr, "On pousse une valeur (1)\n");
if (e->e_subtype == E_VALUE) {
pushdword(e->avalue, NULL);
} else {
pushdword(0, e);
}
} else {
- fprintf(stderr, "et n'est pas d'un type prédéfinit\n");
if (m->string) {
if (m->string[0] != 'P') {
exception(1,
@@ -1384,7 +1337,6 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
&& (e->child->next->child->e_subtype == E_VALUE)) {
tv = e->child->next->child->avalue;
}
- fprintf(stderr, "On pousse une valeur (2)\n");
pushdword(tv, e->child);
} else {
exception(1, _("Logical error in meta language"));
@@ -1459,18 +1411,15 @@ static int evaluate_field(_TableauVariable it, char *field, field_t * fields)
r = 0;
n = 0;
- fprintf(stderr, "Evaluation du champ %s\n", field);
for (i = 0; i < fields->nbr; i++) {
t = (expression_t *) NomVarToVar(fields->names[i], it, &trouve);
e = 0;
- fprintf(stderr, "On veut la variable %s pour le champ %i\n", fields->names[i], i);
if (trouve) {
if (t->e_subtype != E_VALUE) {
exception(1, _("Can't evaluate directly expression"));
}
e = t->avalue;
}
- fprintf(stderr, "Elle vaut %i\n", e);
n = fields->sizes[i];
if ((e & ((1 << n) - 1)) != e) {
exception(1, _("Value too large for field"));
@@ -1487,7 +1436,6 @@ void asm_eol(void)
expression_t *t;
int i;
char trouve;
- bytestream_t *pi;
_TableauVariable it;
switch (special) {
@@ -1503,9 +1451,6 @@ void asm_eol(void)
case 0: /* Cas normal */
/* C'est ici la bonne histoire... Il faut reconnaitre l'instruction */
- fprintf(stderr, "Fin de ligne sur:\n");
- debug_print_expression(e_line);
- fprintf(stderr, "-----\n");
e_current = e_line;
if (!(e_current))
break;
@@ -1547,7 +1492,6 @@ void asm_eol(void)
break;
switch (e_current->e_subtype) {
case E_VALUE:
- fprintf(stderr, "On pousse une valeur (3)\n");
pushdword(e_current->avalue, NULL);
break;
case E_STRING:
@@ -1558,7 +1502,6 @@ void asm_eol(void)
break;
case E_LABEL:
case E_OPERATION:
- fprintf(stderr, "On pousse une valeur (4)\n");
pushdword(0, e_current);
break;
default:
@@ -1620,9 +1563,8 @@ void asm_eol(void)
if (instr->strings[i]) {
switch (instr->strings[i][0]) {
case 'C':
- if (instr->etypes) {
+ if (instr->etypes[i]) {
if (!strcmp(instr->names[i], "I")) {
- fprintf(stderr, "On pousse une valeur (6)\n");
if (e_current->e_subtype == E_VALUE) {
pushdword(e_current->avalue, 0);
} else {
@@ -1639,7 +1581,6 @@ void asm_eol(void)
case 'O':
if (instr->etypes) {
if (!strcmp(instr->names[i], "I")) {
- fprintf(stderr, "On pousse une valeur (7)\n");
if (e_current->e_subtype == E_VALUE) {
pushdword(e_current->avalue, 0);
} else {
@@ -1658,8 +1599,6 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- fprintf(stderr, "Insertion de la variable %s, de valeur %i.\n",
- instr->names[i], t->avalue);
InsererVarDansTab(&it, CreerElement(instr->names[i], t));
evaluate_pattern(&it, e_current);
break;
@@ -1677,7 +1616,6 @@ void asm_eol(void)
for (i = 0; i < instr->nbimplicit; i++) {
switch (instr->itypes[i]) {
case 0: /* type direct */
- fprintf(stderr, "On cherche la variable %s\n", instr->istrings[i]);
t = (expression_t *) NomVarToVar(instr->istrings[i], it, &trouve);
if (!trouve) {
t = (expression_t *) Emalloc(sizeof(expression_t));
@@ -1686,8 +1624,6 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- fprintf(stderr, "Insertion de la variable %s, de valeur %i.\n",
- instr->istrings[i], t->avalue);
}
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
@@ -1715,9 +1651,6 @@ void asm_eol(void)
}
}
- fprintf(stderr, "Variables\n");
- AfficheTableau(it);
- fprintf(stderr, "On pousse une valeur (8)\n");
pushdword(evaluate_field(it, "FI", fields), NULL);
DetruitTab(&it);
break;
@@ -1754,7 +1687,6 @@ int s_text = 0, s_data = 0, s_bss = 0;
static void writeword(unsigned long int a, FILE * f, int n) {
int i;
- fprintf(stderr, "On écrit le mot %i\n", a);
if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) {
if (ferror(f)) {
pushcontext(strerror(errno));
@@ -1768,7 +1700,6 @@ static void writeword(unsigned long int a, FILE * f, int n) {
}
static void writestring(char * string, FILE * f) {
- fprintf(stderr, "On écrit la chaîne %s\n", string);
for (; *string; string++) {
writeword(*string, f, 1);
}
@@ -1815,12 +1746,10 @@ void asm_eof(FILE * f)
{
bytestream_t * t, * u;
FILE * f1, * f2;
- int nbsymbols = 0, a;
+ int nbsymbols = 0, a, nbi = 0, nbe = 0;
char errctx[BUFSIZ], trouve;
bytestream_t * ttext = text, * tdata = data, * tbss = bss;
- fprintf(stderr, "On a reçu une fin de fichier...\n");
-
pushcontext(_("Creating temporary files"));
if (!(f1 = fopen("__text__", "wb"))) {
pushcontext(strerror(errno));
@@ -1837,32 +1766,25 @@ 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);
- fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
a = 0;
if (ttext->Expr) {
- fprintf(stderr, "On a une sous-expression..\n");
switch(ttext->Expr->e_subtype) {
case E_VALUE:
- fprintf(stderr, "Type valeur.\n");
a = ttext->Expr->avalue;
break;
case E_LABEL:
- fprintf(stderr, "Type label.\n");
a = ttext->Expr->avalue;
nbsymbols++;
- writeword(0, f2, 1);
+ writeword(1, f2, 1);
writeword(ttext->offset, f2, 1);
writeword(strlen(ttext->Expr->symbol), f2, 1);
- writestring(ttext->Expr->symbol, f2);
+ writestring(ttext->Expr->symbol, f2);
+ nbe++;
break;
case E_OPERATION:
- fprintf(stderr, "Type operation.\n");
- fprintf(stderr, "Affichage de l'expression:\n");
- debug_print_expression(ttext->Expr);
- fprintf(stderr, "-----\n");
if (ttext->Expr->op == OP_DIRECT) {
if (ttext->Expr->child->e_subtype == E_VALUE) {
a = ttext->Expr->child->avalue;
@@ -1909,8 +1831,12 @@ void asm_eof(FILE * f)
nbsymbols++;
writeword(0, f2, 1);
writeword(ttext->offset, f2, 1);
+ if (ttext->Label[strlen(ttext->Label) - 1] == ':') {
+ ttext->Label[strlen(ttext->Label) - 1] = '\0';
+ }
writeword(strlen(ttext->Label), f2, 1);
writestring(ttext->Label, f2);
+ nbi++;
}
}
popcontext();
@@ -1920,35 +1846,28 @@ 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);
- fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
a = 0;
if (tdata->Expr) {
- fprintf(stderr, "On a une sous-expression..\n");
switch(tdata->Expr->e_subtype) {
case E_VALUE:
- fprintf(stderr, "Type valeur.\n");
a = tdata->Expr->avalue;
break;
case E_LABEL:
- fprintf(stderr, "Type label.\n");
a = tdata->Expr->avalue;
nbsymbols++;
- writeword(0, f2, 1);
+ writeword(3, f2, 1);
writeword(tdata->offset + s_text, f2, 1);
writeword(strlen(tdata->Expr->symbol), f2, 1);
- writestring(tdata->Expr->symbol, f2);
+ writestring(tdata->Expr->symbol, f2);
+ nbe++;
break;
case E_OPERATION:
- fprintf(stderr, "Type operation.\n");
- fprintf(stderr, "Affichage de l'expression:\n");
- debug_print_expression(tdata->Expr);
- fprintf(stderr, "-----\n");
- if (ttext->Expr->op == OP_DIRECT) {
- if (ttext->Expr->child->e_subtype == E_VALUE) {
- a = ttext->Expr->child->avalue;
+ if (tdata->Expr->op == OP_DIRECT) {
+ if (tdata->Expr->child->e_subtype == E_VALUE) {
+ a = tdata->Expr->child->avalue;
break;
}
}
@@ -1990,10 +1909,11 @@ void asm_eof(FILE * f)
} else {
if (tdata->Label) {
nbsymbols++;
- writeword(0, f2, 1);
+ writeword(2, f2, 1);
writeword(tdata->offset + s_text, f2, 1);
writeword(strlen(tdata->Label), f2, 1);
- writestring(tdata->Label, f2);
+ writestring(tdata->Label, f2);
+ nbi++;
}
}
popcontext();
@@ -2005,16 +1925,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);
- fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
if (!tbss->size) {
if (tbss->Label) {
nbsymbols++;
- writeword(0, f2, 1);
+ writeword(4, f2, 1);
writeword(tbss->offset + s_text + s_data, f2, 1);
writeword(strlen(tbss->Label), f2, 1);
- writestring(tbss->Label, f2);
+ writestring(tbss->Label, f2);
+ nbi++;
}
}
popcontext();
@@ -2022,14 +1942,8 @@ void asm_eof(FILE * f)
popcontext();
popcontext();
- fclose(f1);
-
- fprintf(stderr, "------\n");
-
writeword(0x4f424e4e, f, 1);
- fprintf(stderr, "Pointeur de f2: %i taille de data: %i taille de text: %i\n", ftell(f2), s_data, s_text);
writeword(ftell(f2) + s_data + s_text + 7, f, 1);
- fclose(f2);
t = (bytestream_t *) NomVarToVar("__start__", labels, &trouve);
if (trouve) {
writeword(t->offset, f, 1);
@@ -2037,12 +1951,21 @@ void asm_eof(FILE * f)
writeword(-1, f, 1);
}
+ writeword(s_text, f, 1);
+ writeword(s_data, f, 1);
+ writeword(s_bss, f, 1);
+ writeword(ftell(f2) + 1, f, 1);
+ fclose(f2);
+
+ writeword(nbsymbols, f, 1);
appendfile(f, "__symbols__");
appendfile(f, "__text__");
fclose(f);
unlink("__symbols__");
unlink("__text__");
+
+ fprintf(stderr, _("Statistics: %i words of text, %i words of data, and %i words reserved.\n%i symbols generated with %i internal and %i external.\n"), s_text, s_data, s_bss, nbsymbols, nbi, nbe);
}
static void delete_bytestream(bytestream_t * s)
@@ -2106,6 +2029,7 @@ void assemble_file(char *iname, char *oname)
{
FILE *f;
+ fprintf(stderr, _("Assembling file %s...\n"), iname);
pushcontext(_("Opening output file"));
if (!(f = fopen(oname, "wb"))) {
pushcontext(strerror(errno));
@@ -2116,7 +2040,7 @@ void assemble_file(char *iname, char *oname)
exception(1, _("Error reading file"));
}
pushcontext(_("Writing output file"));
+ fprintf(stderr, _("Generating output file %s...\n"), oname);
asm_eof(f);
- fclose(f);
popcontext();
}