summaryrefslogtreecommitdiff
path: root/tools/d2c/hooks/manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/hooks/manager.c')
-rw-r--r--tools/d2c/hooks/manager.c90
1 files changed, 81 insertions, 9 deletions
diff --git a/tools/d2c/hooks/manager.c b/tools/d2c/hooks/manager.c
index 67c09f8..2db4bbc 100644
--- a/tools/d2c/hooks/manager.c
+++ b/tools/d2c/hooks/manager.c
@@ -137,7 +137,7 @@ void register_hook_function(instr_hooks *hooks, char *type, char *name)
* top = indique si l'écriture se réalise au plus haut niveau.*
* fd = descripteur d'un flux ouvert en écriture. *
* *
-* Description : Associe dans le code des fonctions à une instruction. *
+* Description : Déclare des opérations complémentaires pour une instruction. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -145,29 +145,101 @@ void register_hook_function(instr_hooks *hooks, char *type, char *name)
* *
******************************************************************************/
-bool write_hook_functions(const instr_hooks *hooks, bool top, int fd)
+bool declare_hook_functions(const instr_hooks *hooks, bool top, int fd)
{
bool result; /* Bilan à retourner */
- size_t i; /* Boucle de parcours */
- instr_func *func; /* Nouvelle prise en compte */
+ size_t i; /* Boucle de parcours #1 */
+ const instr_func *func; /* Nouvelle prise en compte */
+
+ static const char *hook_types[] = {
+ "FETCH",
+ "LINK",
+ "POST"
+ };
+
+ const instr_func *find_hook_by_name(const instr_hooks *list, const char *type)
+ {
+ const instr_func *hook; /* Trouvaille à retourner */
+ size_t k; /* Boucle de parcours #2 */
+
+ hook = NULL;
+
+ for (k = 0; k < list->func_count && hook == NULL; k++)
+ if (strcmp(list->funcs[k].type, type) == 0)
+ hook = &list->funcs[k];
+
+ return hook;
+
+ }
result = true;
- for (i = 0; i < hooks->func_count && result; i++)
+ if (hooks->func_count > 0)
{
- func = &hooks->funcs[i];
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\tstatic const instr_hook_fc hooks[IPH_COUNT] = {\n\n");
+
+ for (i = 0; i < (sizeof(hook_types) / sizeof(hook_types[0])); i++)
+ {
+ func = find_hook_by_name(hooks, hook_types[i]);
+
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t\t[IPH_%s] = (instr_hook_fc)%s,\n", hook_types[i], func != NULL ? func->name : "NULL");
+
+ }
+
+ dprintf(fd, "\n");
if (!top)
dprintf(fd, "\t");
- dprintf(fd, "\tg_arch_instruction_set_hook(%s, IPH_%s, (instr_hook_fc)%s);\n",
- top ? "result" : "instr", func->type, func->name);
+ dprintf(fd, "\t};\n");
+
+ dprintf(fd, "\n");
}
- if (hooks->func_count > 0 && result)
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : hooks = gestionnaire d'un ensemble de fonctions associées. *
+* top = indique si l'écriture se réalise au plus haut niveau.*
+* fd = descripteur d'un flux ouvert en écriture. *
+* *
+* Description : Associe dans le code des fonctions à une instruction. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool write_hook_functions(const instr_hooks *hooks, bool top, int fd)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ if (hooks->func_count > 0)
+ {
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\tg_arch_instruction_set_hooks(%s, hooks);\n",
+ top ? "result" : "instr");
+
dprintf(fd, "\n");
+ }
+
return result;
}