summaryrefslogtreecommitdiff
path: root/lib/assembler.c
diff options
context:
space:
mode:
authorPixel <>2001-04-17 06:55:02 +0000
committerPixel <>2001-04-17 06:55:02 +0000
commita7bc5cfa7399926941a3754e3cbdc671f24b4b3d (patch)
tree6527baa45482798b61777cae9bf84eccb44075db /lib/assembler.c
parent502e0cd237a9a474b224ab9a741fe4d91ecdec36 (diff)
Pout
Diffstat (limited to 'lib/assembler.c')
-rw-r--r--lib/assembler.c234
1 files changed, 68 insertions, 166 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index 0beb2df..0acf738 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -176,9 +176,7 @@ static bytestream_t *pushdword(unsigned long int d, expression_t * e)
bytestream_t *s;
if ((segment < 0) || (segment > 1)) {
- exception(1,
- _
- ("You have to be into the .text or the .data segment to define a value."));
+ exception(1, _("You have to be into the .text or the .data segment to define a value."));
}
s = pushuninit(1);
@@ -267,9 +265,7 @@ static void pushstring(char *s)
static void pushstart(void)
{
if (segment != SEG_TEXT) {
- exception(1,
- _
- ("You can't have the startpoint elsewhere than the .text segment"));
+ exception(1, _("You can't have the startpoint elsewhere than the .text segment"));
}
pushlabel("__start__");
}
@@ -282,9 +278,7 @@ static void look4pattern(pattern_t * patterns, expression_t * expression)
for (patterns = patterns->next; patterns; patterns = patterns->next) {
for (i = 0; i < patterns->nbr; i++) {
- if (!
- (patterns->expr[i]->type
- || patterns->expr[i]->string || !patterns->expr[i]->name)) {
+ if (!(patterns->expr[i]->type || patterns->expr[i]->string || !patterns->expr[i]->name)) {
if (!strcasecmp(patterns->expr[i]->name, expression->symbol)) {
expression->e_subtype = E_PATTERN;
expression->pattern = patterns;
@@ -661,8 +655,7 @@ static void evaluate(expression_t * e)
if (!e->child->e_subtype == E_VALUE) {
exception(1, _("Error: unable to compute the immediate value"));
}
- e->avalue =
- (e->op == OP_MOINS_UNARY) ? -e->child->avalue : e->child->avalue;
+ e->avalue = (e->op == OP_MOINS_UNARY) ? -e->child->avalue : e->child->avalue;
free(e->child);
e->child = NULL;
e->e_type = e->e_subtype = E_VALUE;
@@ -696,8 +689,7 @@ static void evaluate(expression_t * e)
if (e->child->next->child->e_subtype == E_LABEL) {
exception(1, _("Addresses operations not allowed"));
}
- if (e->child->next->child->e_subtype ==
- e->child->next->child->next->e_subtype) {
+ if (e->child->next->child->e_subtype == e->child->next->child->next->e_subtype) {
exception(1, _("Expression too complex or invalid"));
}
/* On veut obtenir quelque chose sous la forme LABEL[VALUE + PATTERN] */
@@ -808,9 +800,7 @@ static void evaluate(expression_t * e)
et si c'est le cas, il ne faut pas que ce soit - C. Sinon nous ne devons
pas avoir de labels pour B ou C */
- if (
- (e->child->child->next->child->next->e_subtype ==
- E_PATTERN)
+ if ((e->child->child->next->child->next->e_subtype == E_PATTERN)
&& (e->child->child->next->op == OP_MOINS)) {
exception(1, _("Address type not supported"));
}
@@ -823,18 +813,14 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
est correcte.... Enfin j'espère :) Je vais modifier l'expression de sorte a ce
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_PATTERN) {
+ if ((t = e->child->child->next->child)->e_subtype == E_PATTERN) {
t->prev = t->next;
t->next = NULL;
t->prev->next = t;
@@ -851,15 +837,12 @@ static void evaluate(expression_t * e)
et si c'est le cas, il ne faut pas que ce soit - C. Sinon nous ne devons
pas avoir de patterns pour B ou C. */
- if (
- (e->child->child->next->child->next->e_subtype ==
- E_LABEL)
+ if ((e->child->child->next->child->next->e_subtype == E_LABEL)
&& (e->child->child->next->op == OP_MOINS)) {
exception(1, _("Address type not supported"));
}
- if (e->child->child->next->child->e_subtype ==
- E_PATTERN) {
+ if (e->child->child->next->child->e_subtype == E_PATTERN) {
exception(1, _("Expression invalid"));
}
@@ -867,8 +850,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
@@ -876,10 +858,7 @@ static void evaluate(expression_t * e)
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
/* Pas mal de boulot ici... */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_LABEL) {
+ if ((t = e->child->child->next->child)->e_subtype == E_LABEL) {
/* Nous avons [PATTERN + (LABEL +- VALEUR)], on inverse LABEL et VALEUR */
t->prev = t->next;
t->next = NULL;
@@ -918,8 +897,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->op == OP_MOINS) {
exception(1, _("Expression invalid"));
}
- e->child->child->avalue +=
- e->child->child->next->child->avalue;
+ e->child->child->avalue += e->child->child->next->child->avalue;
t = e->child->child->next;
e->child->child->next = t->child->next;
free_expr(t);
@@ -927,15 +905,12 @@ static void evaluate(expression_t * e)
On va pas s'embeter, on va réévaluer la chose :) */
evaluate(e);
return;
- } else if (e->child->child->next->child->
- next->e_subtype == E_VALUE) {
+ } else if (e->child->child->next->child->next->e_subtype == E_VALUE) {
/* Quasiment la même chose qu'au dessus... */
if (e->child->child->next->op == OP_MOINS) {
- e->child->child->avalue
- -= e->child->child->next->child->avalue;
+ e->child->child->avalue -= e->child->child->next->child->avalue;
} else {
- e->child->child->avalue
- += e->child->child->next->child->avalue;
+ e->child->child->avalue += e->child->child->next->child->avalue;
}
t = e->child->child->next;
e->child->child->next = t->child;
@@ -947,9 +922,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _
- ("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
@@ -957,10 +930,7 @@ static void evaluate(expression_t * e)
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
/* Pas mal de boulot ici... */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_PATTERN) {
+ if ((t = e->child->child->next->child)->e_subtype == E_PATTERN) {
/* Nous avons [VALEUR + (PATTERN + LABEL)], on inverse LABEL et PATTERN */
t->prev = t->next;
t->next = NULL;
@@ -1254,8 +1224,7 @@ static int islabel(expression_t * e)
/* Cette fonction cherche une instruction pouvant correspondre à l'expression. */
-static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
- expression_t * e)
+static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_t * e)
{
char *stringtolook = e->symbol;
expression_t *t;
@@ -1281,8 +1250,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
go_out = 0;
for (i = 0; (!go_out) && (i < instructs->nbexplicit); i++) {
if (!instructs->strings[i]) {
- if (strcasecmp
- (instructs->names[i], i ? t->symbol : stringtolook)) {
+ if (strcasecmp(instructs->names[i], i ? t->symbol : stringtolook)) {
go_out = 1;
}
} else {
@@ -1291,9 +1259,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
if (!t->pattern) {
go_out = 1;
} else {
- if (strcasecmp
- (instructs->strings[i] + 1,
- t->pattern->name)) go_out = 1;
+ if (strcasecmp(instructs->strings[i] + 1, t->pattern->name))
+ go_out = 1;
}
break;
case 'C':
@@ -1323,9 +1290,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
/* C'est le cas le plus simple ou presque, il suffit de tout prendre */
break;
default:
- exception(1,
- _
- ("Unknow predefined string into the meta language"));
+ exception(1, _("Unknow predefined string into the meta language"));
}
}
@@ -1347,10 +1312,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
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");
+ 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++) {
@@ -1394,8 +1357,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
if (m->string) {
if (m->type) {
if (strcmp(m->name, "I")) {
- exception(1,
- _("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
if (e->e_subtype == E_VALUE) {
pushdword(e->avalue, NULL);
@@ -1428,9 +1390,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
if (m->type) {
if (strcmp(m->name, "I")
|| strcmp(m->string, "O")) {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
tv = 0;
if (e->child->next->e_subtype == E_VALUE) {
@@ -1660,9 +1620,7 @@ void asm_eol(void)
if (!e_current)
break;
if (segment != SEG_TEXT) {
- exception(1,
- _
- ("You can only have an instruction into a .text segment"));
+ exception(1, _("You can only have an instruction into a .text segment"));
}
if (!(instr = e_match_i(phons, instructs, e_current))) {
exception(1, _("Unmatched instruction"));
@@ -1686,14 +1644,10 @@ void asm_eol(void)
pushdword(0, e_current);
}
} else {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
} else {
- InsererVarDansTab(&it,
- CreerElement
- (instr->names[i], e_current));
+ InsererVarDansTab(&it, CreerElement(instr->names[i], e_current));
}
break;
case 'O':
@@ -1705,9 +1659,7 @@ void asm_eol(void)
pushdword(0, e_current);
}
} else {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
}
break;
@@ -1719,19 +1671,14 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- InsererVarDansTab(&it,
- CreerElement(instr->names[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->names[i], t));
#ifdef DEBUG
- fprintf(stderr,
- "On a %s qui vaut %i\n",
- instr->names[i], e_current->index);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->names[i], e_current->index);
#endif
evaluate_pattern(&it, e_current);
break;
default:
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
}
@@ -1756,11 +1703,9 @@ void asm_eol(void)
t->symbol = NULL;
}
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 1: /* type prédéfinit */
t = (expression_t *)
@@ -1774,11 +1719,9 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 2: /* type valeur */
t = (expression_t *)
@@ -1789,11 +1732,9 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
}
}
@@ -1952,9 +1893,7 @@ void asm_eof(FILE * f)
if ((ttext->Expr->child->e_subtype == E_LABEL)
&& (ttext->Expr->child->next->e_subtype == E_VALUE)) {
#ifdef DEBUG
- fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
@@ -1970,35 +1909,28 @@ void asm_eof(FILE * f)
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))) {
+ && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
if (ttext->Expr->child->e_subtype == E_LABEL) {
#ifdef DEBUG
- fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
writeword(ttext->offset, f2, 1);
- writeword(strlen
- (ttext->Expr->child->symbol), f2, 1);
+ writeword(strlen(ttext->Expr->child->symbol), f2, 1);
writestring(ttext->Expr->child->symbol, f2);
nbe++;
} else {
#ifdef DEBUG
fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->next->symbol);
+ "Symbole externe %s\n", ttext->Expr->child->next->symbol);
#endif
a = ttext->Expr->child->avalue;
nbsymbols++;
writeword(1, f2, 1);
writeword(ttext->offset, f2, 1);
- writeword(strlen
- (ttext->Expr->child->next->symbol), f2,
- 1);
+ writeword(strlen(ttext->Expr->child->next->symbol), f2, 1);
writestring(ttext->Expr->child->next->symbol, f2);
nbe++;
}
@@ -2006,42 +1938,28 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op != OP_FUNC_CALL) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if (strcmp(ttext->Expr->symbol, "diff")) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if ((ttext->Expr->child->e_subtype != E_LABEL)
|| (ttext->Expr->child->next->e_subtype != E_LABEL)) {
- exception(1,
- _
- ("Can only use the diff() function onto labels"));
+ exception(1, _("Can only use the diff() function onto labels"));
}
- t =
- (bytestream_t *) NomVarToVar(ttext->Expr->child->symbol,
- labels, &trouve);
+ t = (bytestream_t *) NomVarToVar(ttext->Expr->child->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
- u =
- (bytestream_t *)
- NomVarToVar(ttext->Expr->child->next->symbol, labels,
- &trouve);
+ u = (bytestream_t *)
+ NomVarToVar(ttext->Expr->child->next->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
if (t->segment != u->segment) {
- exception(1,
- _
- ("Can only evaluate a diff on symbols from the same segment"));
+ exception(1, _("Can only evaluate a diff on symbols from the same segment"));
}
a = t->offset - u->offset;
@@ -2099,8 +2017,7 @@ void asm_eof(FILE * f)
case E_LABEL:
a = tdata->Expr->avalue;
#ifdef DEBUG
- fprintf(stderr, "Symbole externe %s\n",
- tdata->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", tdata->Expr->child->symbol);
#endif
nbsymbols++;
writeword(3, f2, 1);
@@ -2111,42 +2028,28 @@ void asm_eof(FILE * f)
break;
case E_OPERATION:
if (tdata->Expr->op != OP_FUNC_CALL) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if (strcmp(tdata->Expr->symbol, "diff")) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if ((tdata->Expr->child->e_subtype != E_LABEL)
|| (tdata->Expr->child->next->e_subtype != E_LABEL)) {
- exception(1,
- _
- ("Can only use the diff() function onto labels"));
+ exception(1, _("Can only use the diff() function onto labels"));
}
- t =
- (bytestream_t *) NomVarToVar(tdata->Expr->child->symbol,
- labels, &trouve);
+ t = (bytestream_t *) NomVarToVar(tdata->Expr->child->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
- u =
- (bytestream_t *)
- NomVarToVar(tdata->Expr->child->next->symbol, labels,
- &trouve);
+ u = (bytestream_t *)
+ NomVarToVar(tdata->Expr->child->next->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
if (t->segment != u->segment) {
- exception(1,
- _
- ("Can only evaluate a diff on symbols from the same segment"));
+ exception(1, _("Can only evaluate a diff on symbols from the same segment"));
}
a = t->offset - u->offset;
@@ -2209,7 +2112,7 @@ void asm_eof(FILE * f)
popcontext();
writeword(0x4f424e4e, f, 1);
- writeword(ftell(f2) + s_data + s_text + 7, f, 1);
+ writeword((ftell(f2) >> 2)+ s_data + s_text + 7, f, 1);
t = (bytestream_t *) NomVarToVar("__start__", labels, &trouve);
if (trouve) {
writeword(t->offset, f, 1);
@@ -2220,7 +2123,7 @@ void asm_eof(FILE * f)
writeword(s_text, f, 1);
writeword(s_data, f, 1);
writeword(s_bss, f, 1);
- writeword(ftell(f2) + 1, f, 1);
+ writeword((ftell(f2) >> 2) + 1, f, 1);
fclose(f2);
writeword(nbsymbols, f, 1);
@@ -2256,8 +2159,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;