From 47f363829678a02111423cd5d374e6739d8ea500 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Mon, 16 Apr 2001 14:25:48 +0000 Subject: Linker + bugfixes --- lib/Makefile.am | 4 +- lib/assembler.c | 146 ++++++------------------ lib/instructions.txt | 3 + lib/linker.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 355 insertions(+), 112 deletions(-) create mode 100644 lib/linker.c (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index b760f64..352f089 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,12 +2,14 @@ localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ AM_CFLAGS = -O3 -Wall -Wstrict-prototypes $(CFLAGS) INCLUDES = -I. -I.. -I$(includedir) -I../include -lib_LTLIBRARIES = libCompilo.la libSimul.la +lib_LTLIBRARIES = libCompilo.la libSimul.la libLinker.la libCompilo_la_SOURCES = assembler.c parser.c meta.c numbers.c hash.c exceptions.c libSimul_la_SOURCES = alu.c simulator.c exceptions.c fpu.c interne.c memoire.c registre.c +libLinker_la_SOURCES = linker.c exceptions.c hash.c libCompilo_la_LDFLAGS = -version-info $(ProjetArchi_VERSION_INFO) libSimul_la_LFDLAGS = -version-info $(ProjetArchi_VERSION_INFO) +libLinker_la_LDFLAGS = -version-info $(ProjetArchi_VERSION_INFO) EXTRA_DIST = instructions.txt 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(); } diff --git a/lib/instructions.txt b/lib/instructions.txt index 8b04e1b..9b70685 100644 --- a/lib/instructions.txt +++ b/lib/instructions.txt @@ -115,3 +115,6 @@ I:JMP .I=.O;op=0x0c;e=0x2 I:HALT;op=0x7f I:RESET;op=0x7f;e=1 + +I:RET;op=0xc +I:RET c1=.C;op=0xc diff --git a/lib/linker.c b/lib/linker.c new file mode 100644 index 0000000..5fe1162 --- /dev/null +++ b/lib/linker.c @@ -0,0 +1,314 @@ +#include +#include +#include +#include +#include + +#include "config.h" +#include "linker.h" +#include "types.h" +#include "exceptions.h" +#include "hash.h" + +typedef struct object_t { + Uint32 s_text, s_data, s_bss, * text, * data, textstart, datastart, bssstart; +} object_t; + +typedef struct symbol_t { + char * name; + int objindex; + Uint32 offset; + int type; + struct symbol_t * next; +} symbol_t; + +Uint32 startpoint = -1, textsize = 0, datasize = 0, bsssize = 0; + +object_t ** objects; +symbol_t * symbols, * psymbols; +int objindex = 0, nbrsymbs = 0; + +_TableauVariable symbs; + +static FILE * openfilewriting(char * name) { + FILE * f; + + if (!(f = fopen(name, "wb"))) { + pushcontext(strerror(errno)); + exception(1, _("Error writing file")); + } + return f; +} + +static FILE * openfilereading(char * name) { + FILE * f; + + if (!(f = fopen(name, "rb"))) { + pushcontext(strerror(errno)); + exception(1, _("Error reading file")); + } + return f; +} + +static void writeword(Uint32 a, FILE * f) { + if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) { + if (ferror(f)) { + pushcontext(strerror(errno)); + } + exception(1, _("Error writing file")); + } +} + +static Uint32 readword(FILE * f) { + Uint32 a; + + if (fread(&a, sizeof(a), 1, f) != 1) { + exception(1, _("premature end of file")); + } + return a; +} + +static char * readstring(FILE * f) { + Uint32 s; + char * r; + int i; + + s = readword(f); + r = (char *) Emalloc(s + 1); + for (i = 0; i < s; i++) { + r[i] = readword(f); + } + r[i] = '\0'; + return r; +} + +static void addsymbol(char * name, int offset, int type) { + symbol_t * newsymbol; + + newsymbol = (symbol_t *) Emalloc(sizeof(symbol_t)); + newsymbol->next = NULL; + newsymbol->type = type; + newsymbol->offset = offset; + newsymbol->objindex = objindex; + newsymbol->name = name; + + psymbols->next = newsymbol; + psymbols = newsymbol; + + if (newsymbol->type & 1) { + nbrsymbs++; + } else { + InsererVarDansTab(&symbs, CreerElement(name, newsymbol)); + } +} + +void addfile(char * nom) { + FILE * f; + Uint32 start, nbsymbols, type, offset; + int i; + char * snom, errctx[BUFSIZ]; + + f = openfilereading(nom); + sprintf(errctx, _("Processing file %s"), nom); + pushcontext(errctx); + + if (readword(f) != 0x4f424e4e) { + exception(1, _("Bad signature")); + } + + readword(f); /* Taille du fichier */ + start = readword(f); + if ((startpoint != -1) && (start != -1)) { + exception(1, _("Startpoint already defined.")); + } + startpoint = start; + + objects[objindex]->s_text = readword(f); + objects[objindex]->s_data = readword(f); + objects[objindex]->s_bss = readword(f); + readword(f); /* Taille de la table des symboles */ + nbsymbols = readword(f); + + pushcontext(_("Reading symbols")); + for (i = 0; i < nbsymbols; i++) { + type = readword(f); + offset = readword(f); + snom = readstring(f); + addsymbol(snom, offset, type); + } + popcontext(); + + objects[objindex]->textstart = textsize; + objects[objindex]->datastart = datasize; + objects[objindex]->bssstart = bsssize; + + objects[objindex]->text = (Uint32 *) Emalloc(objects[objindex]->s_text * sizeof(Uint32)); + objects[objindex]->data = (Uint32 *) Emalloc(objects[objindex]->s_data * sizeof(Uint32)); + + pushcontext(_("Reading text and data segments")); + for (i = 0; i < objects[objindex]->s_text; i++) { + objects[objindex]->text[i] = readword(f); + } + + for (i = 0; i < objects[objindex]->s_data; i++) { + objects[objindex]->data[i] = readword(f); + } + popcontext(); + fclose(f); + + textsize += objects[objindex]->s_text; + datasize += objects[objindex]->s_data; + bsssize += objects[objindex]->s_bss; + + objindex++; + popcontext(); +} + +static void dumptab(Uint32 * tab, int s, FILE * f) { + int i; + + for (i = 0; i < s; i++) { + writeword(tab[i], f); + } +} + +static void dumptext(object_t * obj, FILE * f) { + dumptab(obj->text, obj->s_text, f); +} + +static void dumpdata(object_t * obj, FILE * f) { + dumptab(obj->data, obj->s_data, f); +} + +static void dumprelog(FILE * f) { + symbol_t * s = symbols, * t; + char trouve, err[BUFSIZ]; + + for (s = s->next; s; s = s->next) { + if (s->type & 1) { + t = (symbol_t *) NomVarToVar(s->name, symbs, &trouve); + if (!trouve) { + sprintf(err, _("Symbol %s not found"), s->name); + exception(1, err); + } + switch(s->type) { + case 1: /* text */ + switch(t->type) { + case 0: + objects[s->objindex]->text[s->offset] += objects[t->objindex]->textstart + t->offset; + break; + case 2: + objects[s->objindex]->text[s->offset] += textsize + objects[t->objindex]->datastart + t->offset; + break; + case 4: + objects[s->objindex]->text[s->offset] += textsize + datasize + objects[t->objindex]->bssstart + t->offset; + break; + default: + exception(1, _("Internal error")); + break; + } + writeword(objects[s->objindex]->textstart + s->offset, f); + break; + case 3: /* data */ + switch(t->type) { + case 0: + objects[s->objindex]->data[s->offset] += objects[t->objindex]->textstart + t->offset; + break; + case 2: + objects[s->objindex]->data[s->offset] += textsize + objects[t->objindex]->datastart + t->offset; + break; + case 4: + objects[s->objindex]->data[s->offset] += textsize + datasize + objects[t->objindex]->bssstart + t->offset; + break; + default: + exception(1, _("Internal error")); + break; + } + writeword(textsize + objects[s->objindex]->datastart + s->offset, f); + break; + default: + exception(1, _("Internal error")); + break; + } + } + } +} + +void dumpfile(char * nom) { + FILE * f; + int i; + + pushcontext(_("Writing output file")); + f = openfilewriting(nom); + + if (startpoint == -1) { + exception(1, _("No startpoint defined.")); + } + + pushcontext(_("Writing headers")); + writeword(0x58454e4e, f); + writeword(nbrsymbs + textsize + datasize + 7, f); + writeword(textsize, f); + writeword(datasize, f); + writeword(bsssize, f); + writeword(nbrsymbs, f); + popcontext(); + pushcontext(_("Writing relocating informations")); + dumprelog(f); + popcontext(); + pushcontext(_("Writing text segments")); + for (i = 0; i < objindex; i++) { + dumptext(objects[i], f); + } + popcontext(); + pushcontext(_("Writing data segments")); + for (i = 0; i < objindex; i++) { + dumpdata(objects[i], f); + } + popcontext(); + + popcontext(); + fprintf(stderr, _("Statistics: %i words of text, %i words of data and reserving %i words\n"), textsize, datasize, bsssize); + fprintf(stderr, _("Output file size: %i words containing %i relocating offsets.\n"), ftell(f), nbrsymbs); + fclose(f); +} + +void init(int n) { + int i; + + Initialise(&symbs); + + objects = (object_t **) Emalloc(n * sizeof(object_t *)); + psymbols = symbols = (symbol_t *) Emalloc(sizeof(symbol_t)); + + for (i = 0; i < n; i++) { + objects[i] = (object_t *) Emalloc(sizeof(object_t)); + objects[i]->s_text = objects[i]->s_data = objects[i]->s_bss = objects[i]->textstart = objects[i]->datastart = 0; + objects[i]->text = objects[i]->data = NULL; + } + + symbols->next = NULL; +} + +void free_symbol(symbol_t * s) { + if (s->next) + free_symbol(s); + + free(s->name); + free(s); +} + +void flush(void) { + int i; + + DetruitTab(&symbs); + + for (i = 0; i < objindex; i++) { + if (objects[i]->text) + free(objects[i]->text); + if (objects[i]->data); + free(objects[i]->data); + free(objects[i]); + } + free(objects); +} -- cgit v1.2.3