summaryrefslogtreecommitdiff
path: root/tools/d2c/encoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/encoding.c')
-rw-r--r--tools/d2c/encoding.c218
1 files changed, 194 insertions, 24 deletions
diff --git a/tools/d2c/encoding.c b/tools/d2c/encoding.c
index 95dca46..9ed4663 100644
--- a/tools/d2c/encoding.c
+++ b/tools/d2c/encoding.c
@@ -188,6 +188,8 @@ char *build_encoding_spec_prefix(const encoding_spec *spec)
{
char *result; /* Chaîne à retourner */
+ assert(spec->lprefix);
+
asprintf(&result, "%s%u", spec->lprefix, spec->index);
return result;
@@ -308,7 +310,7 @@ encoding_syntax *get_current_encoding_syntax(const encoding_spec *spec)
* Paramètres : spec = spécification servant de base à l'opération. *
* fd = descripteur d'un flux ouvert en écriture. *
* arch = architecture visée par l'opération. *
-* id = identifiant unique attribué à l'instruction. *
+* id = désignation de l'identifiant d'instruction. *
* pp = pré-processeur pour les échanges de chaînes. *
* *
* Description : Traduit en code une sous-fonction de désassemblage. *
@@ -319,11 +321,13 @@ encoding_syntax *get_current_encoding_syntax(const encoding_spec *spec)
* *
******************************************************************************/
-bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const char *arch, const instr_id *id, const pre_processor *pp)
+bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const char *arch, const char *id, const pre_processor *pp)
{
bool result; /* Bilan à retourner */
bool openbar; /* Syntaxe unique par défaut ? */
disass_assert *dassert; /* Eventuelles conditions */
+ char *suffix; /* Complément d'identifiant */
+ char *sid; /* Base de sous-identifiant */
size_t i; /* Boucle de parcours */
bool op_decl; /* Suivi des déclaration #1 */
bool imm_decl; /* Suivi des déclaration #2 */
@@ -384,9 +388,6 @@ bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const cha
dprintf(fd, "\n");
- result = declare_hook_functions(spec->hooks, fd);
- if (!result) goto wesrd_exit;
-
/* Vérification que le décodage est possible */
result &= check_bits_correctness(spec->bits, fd);
@@ -407,8 +408,17 @@ bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const cha
result = define_used_bits_fields(spec->bits, fd);
if (!result) goto wesrd_exit;
+ suffix = build_encoding_spec_prefix(spec);
+ make_string_upper(suffix);
+
+ asprintf(&sid, "%s_%s", id, suffix);
+
+ free(suffix);
+
for (i = 0; i < spec->syntax_count && result; i++)
- result = write_encoding_syntax(spec->syntaxes[i], fd, arch, spec->bits, openbar, &bad_exit);
+ result = write_encoding_syntax(spec->syntaxes[i], fd, arch, spec->bits, openbar, id, sid, i, &bad_exit);
+
+ free(sid);
if (!result)
goto wesrd_exit;
@@ -430,11 +440,6 @@ bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const cha
dprintf(fd, "\n");
- /* Inscriptions des éventuelles fonctions ou propriété à lier */
-
- result = write_hook_functions(spec->hooks, fd);
- if (!result) goto wesrd_exit;
-
/* Conclusion globale */
dprintf(fd, "\treturn result;\n");
@@ -476,10 +481,9 @@ bool write_encoding_spec_raw_disass(const encoding_spec *spec, int fd, const cha
* *
******************************************************************************/
-bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const char *arch, const instr_id *id, const char *prefix)
+bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const char *arch, const char *id, const char *prefix)
{
bool result; /* Bilan à retourner */
- unsigned int iid; /* Identifiant unique attribué */
bool bad_exit; /* Ajout d'une sortie d'échec ?*/
conv_list *conversions; /* Conversions de la syntaxe */
decoding_rules *rules; /* Règles de la syntaxe */
@@ -491,22 +495,12 @@ bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const
dprintf(fd, "\n");
- result = declare_hook_functions(spec->hooks, fd);
- if (!result) goto wesfd_exit;
-
/* Création de l'instruction en elle-même */
- iid = get_instruction_id_value(id);
-
- dprintf(fd, "\tresult = g_%s_instruction_new(0x%x);\n", arch, iid);
+ dprintf(fd, "\tresult = g_%s_instruction_new(%s);\n", arch, id);
dprintf(fd, "\n");
- /* Inscriptions des éventuelles fonctions ou propriété à lier */
-
- result = write_hook_functions(spec->hooks, fd);
- if (!result) goto wesfd_exit;
-
bad_exit = false;
assert(spec->syntax_count <= 1);
@@ -558,3 +552,179 @@ bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : spec = spécification servant de base à l'opération. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* name = désignation de l'identifiant d'instruction. *
+* *
+* Description : Imprime les mots clefs de chaque syntaxe. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool write_encoding_spec_keywords(const encoding_spec *spec, int fd, const char *name)
+{
+ bool result; /* Bilan à retourner */
+ char *suffix; /* Complément d'identifiant */
+ size_t i; /* Boucle de parcours */
+ asm_pattern *pattern; /* Définition d'assemblage */
+ const char *keyword; /* Mot clef principal */
+
+ result = true;
+
+ suffix = build_encoding_spec_prefix(spec);
+ make_string_upper(suffix);
+
+ for (i = 0; i < spec->syntax_count; i++)
+ {
+ /* Impression de la colonne */
+
+ if (spec->syntax_count == 1)
+ dprintf(fd, "\t[%s_%s]", name, suffix);
+ else
+ dprintf(fd, "\t[%s_%s_%zu]", name, suffix, i);
+
+ /* Impression des décrochages */
+
+ pattern = get_asm_pattern_in_encoding_syntax(spec->syntaxes[i]);
+
+ keyword = get_keyword_from_asm_pattern(pattern);
+
+ dprintf(fd, " = \"%s\",\n", keyword);
+
+ }
+
+ free(suffix);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : spec = spécification servant de base à l'opération. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* name = désignation de l'identifiant d'instruction. *
+* *
+* Description : Imprime la définition d'un sous-identifiant pour un encodage.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool write_encoding_spec_subid(const encoding_spec *spec, int fd, const char *name)
+{
+ bool result; /* Bilan à retourner */
+ char *suffix; /* Complément d'identifiant */
+ size_t i; /* Boucle de parcours */
+ instr_id *subid; /* Sous-identifiant de syntaxe */
+ unsigned int idval; /* Identifiant unique attribué */
+
+ result = true;
+
+ suffix = build_encoding_spec_prefix(spec);
+ make_string_upper(suffix);
+
+ for (i = 0; i < spec->syntax_count; i++)
+ {
+ subid = get_encoding_syntax_subid(spec->syntaxes[i]);
+ idval = get_instruction_id_value(subid);
+
+ if (spec->syntax_count == 1)
+ dprintf(fd, "\t%s_%s = %u,\n", name, suffix, idval);
+ else
+ dprintf(fd, "\t%s_%s_%zu = %u,\n", name, suffix, i, idval);
+
+ }
+
+ free(suffix);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : spec = spécification servant de base à l'opération. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* name = désignation de l'identifiant d'instruction. *
+* refine = utilisation d'un identifiant plus précis ? *
+* *
+* Description : Imprime d'éventuels décrochages spécifiés pour un encodage. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool write_encoding_spec_hooks(const encoding_spec *spec, int fd, const char *name, bool refine)
+{
+ bool result; /* Bilan à retourner */
+ char *suffix; /* Complément d'identifiant */
+ size_t i; /* Boucle de parcours */
+
+ if (!has_hook_functions(spec->hooks))
+ result = true;
+
+ else
+ {
+ if (refine)
+ {
+ suffix = build_encoding_spec_prefix(spec);
+ make_string_upper(suffix);
+
+ for (i = 0; i < spec->syntax_count; i++)
+ {
+ /* Impression de la colonne */
+
+ if (spec->syntax_count == 1)
+ dprintf(fd, "\t[%s_%s]", name, suffix);
+ else
+ dprintf(fd, "\t[%s_%s_%zu]", name, suffix, i);
+
+ /* Impression des décrochages */
+
+ dprintf(fd, " = {\n", name);
+
+ result = write_hook_functions(spec->hooks, fd);
+
+ dprintf(fd, "\t},\n", name);
+
+ }
+
+ free(suffix);
+
+ }
+
+ else
+ {
+ /* Impression de la colonne */
+
+ dprintf(fd, "\t[%s]", name);
+
+ /* Impression des décrochages */
+
+ dprintf(fd, " = {\n", name);
+
+ result = write_hook_functions(spec->hooks, fd);
+
+ dprintf(fd, "\t},\n", name);
+
+ }
+
+ }
+
+ return result;
+
+}