diff options
Diffstat (limited to 'tools/d2c/coder.c')
-rw-r--r-- | tools/d2c/coder.c | 419 |
1 files changed, 405 insertions, 14 deletions
diff --git a/tools/d2c/coder.c b/tools/d2c/coder.c index 9977d22..eff35c2 100644 --- a/tools/d2c/coder.c +++ b/tools/d2c/coder.c @@ -116,9 +116,15 @@ static bool output_coder_format(const rented_coder *, const output_info *, const /* Initialise le contenu utile du fichier des identifiants. */ static void init_coder_identifiers_file(int, const output_info *); +/* Initialise le contenu utile du fichier des sous-identifiants. */ +static void init_coder_sub_identifiers_file(int, const output_info *); + /* Initialise le contenu utile du fichier des mots clefs. */ static void init_coder_keywords_file(int, const output_info *); +/* Initialise le contenu utile du fichier des décrochages. */ +static void init_coder_hooks_file(int, const output_info *); + /* Initialise le contenu utile du fichier des descriptions. */ static void init_coder_descriptions_file(int, const output_info *); @@ -1044,6 +1050,7 @@ bool output_coder_body(const rented_coder *coder, const output_info *info) break; case IOT_FORMAT: + assert(j == 0); assert(enc_name->dest == NULL); result = output_coder_format(coder, info, enc_name, coder->specs[j], header_fd, code_fd); break; @@ -1146,6 +1153,7 @@ static bool output_coder_raw(const rented_coder *coder, const output_info *info, coding_bits *bits; /* Gestionnaire de bits */ unsigned int wide; /* Taille des mots */ size_t maxlen; /* Taille à compléter */ + char *fullname; /* Désignation complète */ arch = strdup(info->arch_cn); make_string_lower(arch); @@ -1214,7 +1222,13 @@ static bool output_coder_raw(const rented_coder *coder, const output_info *info, dprintf(cfd, "{"); dprintf(cfd, "\n"); - result = write_encoding_spec_raw_disass(encoding, cfd, arch, coder->id, coder->pp); + make_string_upper(name); + + asprintf(&fullname, "%s_%s", info->id_prefix, name); + + result = write_encoding_spec_raw_disass(encoding, cfd, arch, fullname, coder->pp); + + free(fullname); dprintf(cfd, "}\n"); dprintf(cfd, "\n"); @@ -1397,6 +1411,7 @@ static bool output_coder_format(const rented_coder *coder, const output_info *in char *arch; /* Architecture à traiter */ char *name; /* Désignation à manipuler */ size_t maxlen; /* Taille à compléter */ + char *fullname; /* Désignation complète */ arch = strdup(info->arch_cn); make_string_lower(arch); @@ -1457,7 +1472,13 @@ static bool output_coder_format(const rented_coder *coder, const output_info *in dprintf(cfd, "{"); dprintf(cfd, "\n"); - result = write_encoding_spec_format_disass(encoding, cfd, arch, coder->id, info->fmt_prefix); + make_string_upper(name); + + asprintf(&fullname, "%s_%s", info->id_prefix, name); + + result = write_encoding_spec_format_disass(encoding, cfd, arch, fullname, info->fmt_prefix); + + free(fullname); dprintf(cfd, "}\n"); dprintf(cfd, "\n"); @@ -1679,6 +1700,142 @@ bool fini_coder_identifiers_file(const char *pathname, const output_info *info) * Paramètres : fd = flux ouvert en écriture mis à disposition. * * info = précisions quant à la génération. * * * +* Description : Initialise le contenu utile du fichier des sous-identifiants.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void init_coder_sub_identifiers_file(int fd, const output_info *info) +{ + dprintf(fd, "#ifndef _%s_SUBIDENTIFIERS_H\n", info->guard); + dprintf(fd, "#define _%s_SUBIDENTIFIERS_H\n", info->guard); + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + dprintf(fd, "/* Enumération de tous les opcodes */\n"); + dprintf(fd, "typedef enum _%sSyntax\n", info->arch_cn); + dprintf(fd, "{\n"); + +} + + +/****************************************************************************** +* * +* Paramètres : coder = gestion par la machine en remplacement de l'humain. * +* info = précisions quant à la génération. * +* * +* Description : Génère ou complète un fichier créant les sous-identifiants. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool output_coder_sub_identifier(const rented_coder *coder, const output_info *info) +{ + bool result; /* Bilan à retourner */ + bool created; /* Note une création */ + int fd; /* Flux ouvert en écriture */ + char *name; /* Désignation à manipuler */ + char *fullname; /* Désignation complète */ + size_t i; /* Boucle de parcours */ + + result = false; + + /* Ouverture de la destination */ + + fd = open_global_header_file(coder, info, "subidentifiers", &created); + if (fd == -1) goto ocsi_exit; + + if (created) + { + write_header_file_license(fd, info, "subidentifiers", "définition des sous-identifiants uniques pour"); + init_coder_sub_identifiers_file(fd, info); + } + + /* Impression des sous-identifiants */ + + name = get_coder_code_name(coder); + make_string_upper(name); + + asprintf(&fullname, "%s_%s", info->id_prefix, name); + + free(name); + + result = true; + + for (i = 0; i < coder->specs_count && result; i++) + result = write_encoding_spec_subid(coder->specs[i], fd, fullname); + + free(fullname); + + result = true; + + ocsi_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : pathname = chemin d'accès au fichier à traiter. * +* info = précisions quant à la génération. * +* * +* Description : Finalise le contenu utile du fichier des sous-identifiants. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool fini_coder_sub_identifiers_file(const char *pathname, const output_info *info) +{ + bool result; /* Bilan à retourner */ + int fd; /* Flux ouvert en écriture */ + + result = false; + + fd = open(pathname, O_WRONLY | O_APPEND, 0644); + if (fd == -1) + { + perror("open()"); + goto fcif_exit; + } + + dprintf(fd, "\n"); + dprintf(fd, " %s_ENC_COUNT\n", info->id_prefix); + dprintf(fd, "\n"); + + dprintf(fd, "} %sSyntax;\n", info->arch_cn); + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + dprintf(fd, "#endif /* _%s_SUBIDENTIFIERS_H */\n", info->guard); + + result = true; + + fcif_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : fd = flux ouvert en écriture mis à disposition. * +* info = précisions quant à la génération. * +* * * Description : Initialise le contenu utile du fichier des mots clefs. * * * * Retour : - * @@ -1696,7 +1853,23 @@ static void init_coder_keywords_file(int fd, const output_info *info) dprintf(fd, "\n"); dprintf(fd, "\n"); - dprintf(fd, "#include \"identifiers.h\"\n"); + + switch (info->type) + { + case IOT_UNDEFINED: + assert(false); + break; + + case IOT_RAW: + dprintf(fd, "#include \"subidentifiers.h\"\n"); + break; + + case IOT_FORMAT: + dprintf(fd, "#include \"identifiers.h\"\n"); + break; + + } + dprintf(fd, "\n"); dprintf(fd, "\n"); dprintf(fd, "\n"); @@ -1705,7 +1878,8 @@ static void init_coder_keywords_file(int fd, const output_info *info) make_string_lower(larch); dprintf(fd, "/* Enumération de tous les mots clefs */\n"); - dprintf(fd, "static char *_%s_keywords[%s_COUNT] = {\n", larch, info->id_prefix); + dprintf(fd, "static char *_%s_keywords[%s_%sCOUNT] = {\n", + larch, info->id_prefix, info->type == IOT_RAW ? "ENC_" : ""); dprintf(fd, "\n"); free(larch); @@ -1732,6 +1906,8 @@ bool output_coder_keyword(const rented_coder *coder, const output_info *info) bool created; /* Note une création */ int fd; /* Flux ouvert en écriture */ char *name; /* Désignation à manipuler */ + char *fullname; /* Désignation complète */ + size_t i; /* Boucle de parcours */ result = false; @@ -1754,24 +1930,49 @@ bool output_coder_keyword(const rented_coder *coder, const output_info *info) init_coder_keywords_file(fd, info); } - /* Impression de la colonne */ + /* Lancement des impressions */ name = get_coder_code_name(coder); make_string_upper(name); - dprintf(fd, "\t[%s_%s] = ", info->id_prefix, name); + asprintf(&fullname, "%s_%s", info->id_prefix, name); free(name); - /* Impression du mot clef */ + result = true; - name = get_coder_nominal_name(coder); + for (i = 0; i < coder->specs_count && result; i++) + switch (info->type) + { + case IOT_UNDEFINED: + assert(false); + result = false; + break; - dprintf(fd, "\"%s\",\n", name); + case IOT_RAW: + result = write_encoding_spec_keywords(coder->specs[i], fd, fullname); + break; - free(name); + case IOT_FORMAT: + assert(i == 0); - result = true; + /* Impression de la colonne */ + + dprintf(fd, "\t[%s] = ", fullname); + + /* Impression du mot clef */ + + name = get_coder_nominal_name(coder); + + dprintf(fd, "\"%s\",\n", name); + + free(name); + + break; + + } + + free(fullname); ock_exit: @@ -1830,6 +2031,194 @@ bool fini_coder_keywords_file(const char *pathname, const output_info *info) * Paramètres : fd = flux ouvert en écriture mis à disposition. * * info = précisions quant à la génération. * * * +* Description : Initialise le contenu utile du fichier des décrochages. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void init_coder_hooks_file(int fd, const output_info *info) +{ + char *larch; /* Architecture en minuscules */ + + dprintf(fd, "#ifndef _%s_HOOKS_H\n", info->guard); + dprintf(fd, "#define _%s_HOOKS_H\n", info->guard); + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + switch (info->type) + { + case IOT_UNDEFINED: + assert(false); + break; + + case IOT_RAW: + dprintf(fd, "#include \"subidentifiers.h\"\n"); + break; + + case IOT_FORMAT: + dprintf(fd, "#include \"identifiers.h\"\n"); + break; + + } + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + dprintf(fd, "##INCLUDES##\n"); + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + larch = strdup(info->arch_cn); + make_string_lower(larch); + + dprintf(fd, "/* Définitions des décrochages pour l'établissement d'instructions */\n"); + dprintf(fd, "static const instr_hook_fc _%s_hooks[%s_%sCOUNT][IPH_COUNT] = {\n", + larch, info->id_prefix, info->type == IOT_RAW ? "ENC_" : ""); + dprintf(fd, "\n"); + + free(larch); + +} + + +/****************************************************************************** +* * +* Paramètres : coder = gestion par la machine en remplacement de l'humain. * +* info = précisions quant à la génération. * +* * +* Description : Génère ou complète un fichier constituant les décrochages. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool output_coder_hooks(const rented_coder *coder, const output_info *info) +{ + bool result; /* Bilan à retourner */ + bool created; /* Note une création */ + int fd; /* Flux ouvert en écriture */ + char *name; /* Désignation à manipuler */ + char *fullname; /* Désignation complète */ + size_t i; /* Boucle de parcours */ + + result = false; + + /* S'il n'y a pas lieu de traiter l'instruction */ + + if (coder->useless) + { + result = true; + goto och_exit; + } + + /* Ouverture de la destination */ + + fd = open_global_header_file(coder, info, "hooks", &created); + if (fd == -1) goto och_exit; + + if (created) + { + write_header_file_license(fd, info, "hooks", "définition des décrochages pour instructions"); + init_coder_hooks_file(fd, info); + } + + /* Lancement des impressions */ + + name = get_coder_code_name(coder); + make_string_upper(name); + + asprintf(&fullname, "%s_%s", info->id_prefix, name); + + free(name); + + result = true; + + for (i = 0; i < coder->specs_count && result; i++) + switch (info->type) + { + case IOT_UNDEFINED: + assert(false); + result = false; + break; + + case IOT_RAW: + result = write_encoding_spec_hooks(coder->specs[i], fd, fullname, true); + break; + + case IOT_FORMAT: + assert(i == 0); + result = write_encoding_spec_hooks(coder->specs[i], fd, fullname, false); + break; + + } + + free(fullname); + + och_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : pathname = chemin d'accès au fichier à traiter. * +* info = précisions quant à la génération. * +* * +* Description : Finalise le contenu utile du fichier des décrochages. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool fini_coder_hooks_file(const char *pathname, const output_info *info) +{ + bool result; /* Bilan à retourner */ + int fd; /* Flux ouvert en écriture */ + + result = false; + + fd = open(pathname, O_WRONLY | O_APPEND, 0644); + if (fd == -1) + { + perror("open()"); + goto fchf_exit; + } + + dprintf(fd, "\n"); + dprintf(fd, "};\n"); + + dprintf(fd, "\n"); + dprintf(fd, "\n"); + dprintf(fd, "\n"); + + dprintf(fd, "#endif /* _%s_HOOKS_H */\n", info->guard); + + result = true; + + fchf_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : fd = flux ouvert en écriture mis à disposition. * +* info = précisions quant à la génération. * +* * * Description : Initialise le contenu utile du fichier des descriptions. * * * * Retour : - * @@ -1847,7 +2236,9 @@ static void init_coder_descriptions_file(int fd, const output_info *info) dprintf(fd, "\n"); dprintf(fd, "\n"); + dprintf(fd, "#include \"identifiers.h\"\n"); + dprintf(fd, "\n"); dprintf(fd, "\n"); dprintf(fd, "\n"); @@ -1891,13 +2282,13 @@ bool output_coder_description(const rented_coder *coder, const output_info *info if (coder->useless) { result = true; - goto ock_exit; + goto ocd_exit; } /* Ouverture de la destination */ fd = open_global_header_file(coder, info, "descriptions", &created); - if (fd == -1) goto ock_exit; + if (fd == -1) goto ocd_exit; if (created) { @@ -1928,7 +2319,7 @@ bool output_coder_description(const rented_coder *coder, const output_info *info result = true; - ock_exit: + ocd_exit: return result; |