From 43124616c4c055c80f4cd9fc4e0afcbe2b733928 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Mon, 16 Apr 2001 14:56:10 +0000 Subject: Commentaires --- lib/assembler.c | 130 +++++++++++++++++++++++++++++++++----------------------- lib/linker.c | 20 +++++++++ 2 files changed, 98 insertions(+), 52 deletions(-) (limited to 'lib') diff --git a/lib/assembler.c b/lib/assembler.c index ea8b085..affbdda 100644 --- a/lib/assembler.c +++ b/lib/assembler.c @@ -18,6 +18,8 @@ static int process_file(char *); +/* Les differentes structures de données nécessaires au traitement */ + typedef struct expression_t { int e_type; int e_subtype; @@ -57,6 +59,7 @@ enum { E_INSTRUCT }; +/* Nos variables globales */ int wc = 0; expression_t *e_current = NULL, *e_line = NULL; int segment = -1; @@ -69,6 +72,8 @@ int nestedinc = 0; bytestream_t *text, *data, *bss, *p_text, *p_data, *p_bss; int s_text = 0, s_data = 0, s_bss = 0; +/* Cette fonction affiche une expression à l'écran. Elle n'est utile que pour des raisons de deboggage */ + static void debug_print_expression(expression_t * e) { if (!e) @@ -121,6 +126,8 @@ static void debug_print_expression(expression_t * e) static expression_t *copy_expression(expression_t * e); +/* Les fonctions push* qui suivent rajoutent des mots dans le segment en cours */ + static bytestream_t *pushuninit(int size) { bytestream_t *s; @@ -263,6 +270,8 @@ static void pushstart(void) pushlabel("__start__"); } +/* Nous recherchons si une string est une pattern "simple" (pas composée) */ + static void look4pattern(pattern_t * patterns, expression_t * expression) { int i; @@ -281,6 +290,8 @@ static void look4pattern(pattern_t * patterns, expression_t * expression) } } +/* Nous vérifions rapidement si la string en cours fait partie des instructions recensées */ + static void look4instr(phon_t * phons, instruct_t * instructs, expression_t * e) { char *stringtolook = e->symbol; @@ -300,6 +311,8 @@ static void look4instr(phon_t * phons, instruct_t * instructs, expression_t * e) } } +/* Libère récursivement une expression */ + static void free_expr(expression_t * e) { if (e->child) { @@ -317,6 +330,8 @@ static void free_expr(expression_t * e) free(e); } +/* Copie récursivement une expression */ + static expression_t *copy_expression(expression_t * e) { expression_t *t, *e_t; @@ -354,6 +369,8 @@ static expression_t *copy_expression(expression_t * e) return t; } +/* Cette fonction est appelée par le parseur. Elle rajoute un symbole sur la pile des expressions pour la ligne en cours */ + void push_pile(char *a) { int valid, number; @@ -579,22 +596,7 @@ void push_pile(char *a) wc++; } - -/* - {',', 0, OP_NEST}, - {'+', 2, OP_PLUS}, - {'-', 2, OP_MOINS}, - {'*', 3, OP_MUL}, - {'/', 3, OP_DIV}, - {'%', 3, OP_MOD}, - {'+' + 128, 4, OP_PLUS_UNARY}, - {'-' + 128, 4, OP_MOINS_UNARY}, - {'(', 5, OP_FUNC_CALL}, - {'(' + 128, 5, OP_LPAREN}, - {'[', 5, OP_DECAL}, - {'[' + 128, 5, OP_DIRECT}, - {255, -1, -1} -*/ +/* Cette fonction évalue l'expression en cours. */ static void evaluate(expression_t * e) { @@ -1008,6 +1010,8 @@ static void evaluate(expression_t * e) } } +/* Cette fonction est appelée depuis le parseur. Elle ajit sur la pile en effectuant une opération */ + void act_pile(int o) { expression_t *e, *e1, *e2; @@ -1110,6 +1114,8 @@ void act_pile(int o) evaluate(e_current); } +/* Fonction d'initialisation de l'assembleur */ + int assembler_init(void) { Initialise(&defines); @@ -1132,6 +1138,8 @@ int assembler_init(void) return 0; } +/* Nous vérifions si l'expression peut correspondre à une pattern "complexe" (composée) */ + static void super_pattern(pattern_t * patterns, expression_t * e) { int i; @@ -1184,6 +1192,8 @@ static void super_pattern(pattern_t * patterns, expression_t * e) } } +/* Ces deux fonctions récursives croisées nous servent à déterminer su une expression est un label */ + static int islabel(expression_t *); static int islabel2(expression_t * e) @@ -1206,6 +1216,8 @@ static int islabel(expression_t * e) return 0; } +/* Cette fonction cherche une instruction pouvant correspondre à l'expression. */ + static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_t * e) { char *stringtolook = e->symbol; @@ -1282,6 +1294,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_ return instructs; } +/* Cette fonction va évaluer une pattern et rajouter les variable dans la table de hachage correspondante */ + static void evaluate_pattern(_TableauVariable * it, expression_t * e) { metaexpr_t *m, *n; @@ -1393,6 +1407,8 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e) } } +/* Cette fonction va évaluer un champ et en renvoyer la valeur, à l'aide de la table de hachage passée en argument */ + static int evaluate_field(_TableauVariable it, char *field, field_t * fields) { int i, r, e, n; @@ -1430,6 +1446,8 @@ static int evaluate_field(_TableauVariable it, char *field, field_t * fields) return r; } +/* Fonction servant à effectuer une fin de ligne. Force l'évaluation complète de la ligne */ + void asm_eol(void) { instruct_t *instr; @@ -1480,9 +1498,9 @@ void asm_eol(void) switch (e_current->e_subtype) { case E_INTERNAL: switch (e_current->op) { - case 1: - case 2: - case 3: + case 1: /* DB */ + case 2: /* DW */ + case 3: /* DD */ do { e_line = e_current->next; e_current->next = NULL; @@ -1509,7 +1527,7 @@ void asm_eol(void) } } while (1); break; - case 4: + case 4: /* DS */ do { e_line = e_current->next; e_current->next = NULL; @@ -1526,7 +1544,7 @@ void asm_eol(void) } } while (1); break; - case 5: + case 5: /* DR */ do { e_line = e_current->next; e_current->next = NULL; @@ -1667,22 +1685,7 @@ void asm_eol(void) e_current = e_line = NULL; } -/* -typedef struct bytestream_t { - unsigned long int Encoded; - int offset, segment, size; - char *Label; - expression_t *Expr; - - struct bytestream_t *next; - - int line; - char *filename; -} bytestream_t; - -bytestream_t *text, *data, *bss, *p_text, *p_data, *p_bss; -int s_text = 0, s_data = 0, s_bss = 0; -*/ +/* Ecrit un ou plusieurs mots dans le fichier spécifié, avec traitement des erreurs */ static void writeword(unsigned long int a, FILE * f, int n) { int i; @@ -1699,27 +1702,34 @@ static void writeword(unsigned long int a, FILE * f, int n) { } } +/* Ecrit une chaine dans le fichier spécifié, avec traitement des erreurs */ + static void writestring(char * string, FILE * f) { for (; *string; string++) { writeword(*string, f, 1); } } -/* - /\ - / \ - / ++ \ - / ++ \ - / \ - |~~~~~~~~~~| - | +-+ +-+ | - | +-+ +-+ | - | | - | +--+ | - | | .| | - +---+--+---+ - -*/ +/****************\ +| | +| Private Joke | +| | +| /\ | +| / \ | +| / ++ \ | +| / ++ \ | +| / \ | +| |~~~~~~~~~~| | +| | +-+ +-+ | | +| | +-+ +-+ | | +| | | | +| | +--+ | | +| | | .| | | +| +---+--+---+ | +| | +\****************/ + +/* Cette fonction ajoute un fichier à un autre */ void appendfile(FILE * f, char * name) { unsigned long int a; @@ -1742,6 +1752,9 @@ void appendfile(FILE * f, char * name) { fclose(g); } +/* Cette fonction est appelée pour signaler la fin du fichier. Elle va écrire tous les segments dans le fichier de sortie, + et tenter d'évaluer les dernières expressions restantes */ + void asm_eof(FILE * f) { bytestream_t * t, * u; @@ -1762,6 +1775,9 @@ void asm_eof(FILE * f) popcontext(); pushcontext(_("Dumping memory into object file")); + + + /* Segment de texte */ pushcontext(_("Dumping text segment")); for (ttext = ttext->next; ttext; ttext = ttext->next) { @@ -1842,6 +1858,8 @@ void asm_eof(FILE * f) popcontext(); } popcontext(); + + /* Segment de data */ pushcontext(_("Dumping data segment")); for (tdata = tdata->next; tdata; tdata = tdata->next) { @@ -1921,6 +1939,8 @@ void asm_eof(FILE * f) popcontext(); fclose(f1); + + /* Segment bss */ pushcontext(_("Dumping bss segment")); for (tbss = tbss->next; tbss; tbss = tbss->next) { @@ -1968,6 +1988,8 @@ void asm_eof(FILE * f) 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); } +/* Diverses fonctions pour faire plein de free() partout */ + static void delete_bytestream(bytestream_t * s) { if (s->next) @@ -1986,6 +2008,8 @@ void assembler_flush(void) delete_bytestream(bss); } +/* Fonction générique qui va traiter un fichier entier */ + static int process_file(char *name) { FILE *f; @@ -2025,6 +2049,8 @@ static int process_file(char *name) return 0; } +/* Fonction d'api pour assembler un fichier d'entrée */ + void assemble_file(char *iname, char *oname) { FILE *f; diff --git a/lib/linker.c b/lib/linker.c index 5fe1162..f28bc0f 100644 --- a/lib/linker.c +++ b/lib/linker.c @@ -10,6 +10,8 @@ #include "exceptions.h" #include "hash.h" +/* Les quelques structures de données utiles */ + typedef struct object_t { Uint32 s_text, s_data, s_bss, * text, * data, textstart, datastart, bssstart; } object_t; @@ -22,6 +24,8 @@ typedef struct symbol_t { struct symbol_t * next; } symbol_t; +/* Et les variables globales */ + Uint32 startpoint = -1, textsize = 0, datasize = 0, bsssize = 0; object_t ** objects; @@ -30,6 +34,8 @@ int objindex = 0, nbrsymbs = 0; _TableauVariable symbs; +/* Quelques fonctions pour nous simplifier la vie... */ + static FILE * openfilewriting(char * name) { FILE * f; @@ -82,6 +88,8 @@ static char * readstring(FILE * f) { return r; } +/* Rajoute un symbole dans la pile */ + static void addsymbol(char * name, int offset, int type) { symbol_t * newsymbol; @@ -102,6 +110,8 @@ static void addsymbol(char * name, int offset, int type) { } } +/* Rajoute un fichier dans les structures */ + void addfile(char * nom) { FILE * f; Uint32 start, nbsymbols, type, offset; @@ -164,6 +174,8 @@ void addfile(char * nom) { popcontext(); } +/* Simplification de vie... */ + static void dumptab(Uint32 * tab, int s, FILE * f) { int i; @@ -172,6 +184,8 @@ static void dumptab(Uint32 * tab, int s, FILE * f) { } } +/* Nous dumpons la mémoire dans le fichier */ + static void dumptext(object_t * obj, FILE * f) { dumptab(obj->text, obj->s_text, f); } @@ -180,6 +194,8 @@ static void dumpdata(object_t * obj, FILE * f) { dumptab(obj->data, obj->s_data, f); } +/* Cette fonction va calculer les quelques relogements statiques et dynamiques que nous a laissé l'assembleur */ + static void dumprelog(FILE * f) { symbol_t * s = symbols, * t; char trouve, err[BUFSIZ]; @@ -234,6 +250,8 @@ static void dumprelog(FILE * f) { } } +/* Cette fonction sert à écrire le fichier de sortie. */ + void dumpfile(char * nom) { FILE * f; int i; @@ -273,6 +291,8 @@ void dumpfile(char * nom) { fclose(f); } +/* Fonctions d'initialisations et de libération de mémoire */ + void init(int n) { int i; -- cgit v1.2.3