summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-04-24 18:43:54 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-04-24 18:43:54 (GMT)
commit9d04b66153bd0b354c0fb5c097b9face61a649db (patch)
tree54a507c720287597e7a70808e64ad36b37ed41b8 /tools
parenta5758a42acdfaf0ac20c4cfb9cf162a9b4440e39 (diff)
Handled hooks and rules in Dalvik opcodes definitions.
Diffstat (limited to 'tools')
-rw-r--r--tools/d2c/conv/manager.c2
-rw-r--r--tools/d2c/hooks/manager.c10
-rw-r--r--tools/d2c/hooks/manager.h2
-rw-r--r--tools/d2c/qckcall.c36
-rw-r--r--tools/d2c/qckcall.h4
-rw-r--r--tools/d2c/rules/manager.c33
-rw-r--r--tools/d2c/rules/manager.h2
-rw-r--r--tools/d2c/spec.c27
8 files changed, 83 insertions, 33 deletions
diff --git a/tools/d2c/conv/manager.c b/tools/d2c/conv/manager.c
index c04a49e..fca9ce0 100644
--- a/tools/d2c/conv/manager.c
+++ b/tools/d2c/conv/manager.c
@@ -358,7 +358,7 @@ bool define_conv_func(conv_func *func, bool last, bool internal, int fd, const c
{
/* Si l'on doit manipuler une propriété d'instructon... */
if (internal)
- result = checked_call_instr_func(callable, func->args, fd, bits, list, pp);
+ result = checked_call_instr_func(false, callable, func->args, fd, bits, list, pp);
/* Si on doit constituer un opérande à ajouter... */
else
diff --git a/tools/d2c/hooks/manager.c b/tools/d2c/hooks/manager.c
index 8e7ae77..67c09f8 100644
--- a/tools/d2c/hooks/manager.c
+++ b/tools/d2c/hooks/manager.c
@@ -134,6 +134,7 @@ void register_hook_function(instr_hooks *hooks, char *type, char *name)
/******************************************************************************
* *
* 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. *
@@ -144,7 +145,7 @@ void register_hook_function(instr_hooks *hooks, char *type, char *name)
* *
******************************************************************************/
-bool write_hook_functions(const instr_hooks *hooks, int fd)
+bool write_hook_functions(const instr_hooks *hooks, bool top, int fd)
{
bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
@@ -156,8 +157,11 @@ bool write_hook_functions(const instr_hooks *hooks, int fd)
{
func = &hooks->funcs[i];
- dprintf(fd, "\t\tg_arch_instruction_set_hook(instr, IPH_%s, (instr_hook_fc)%s);\n",
- func->type, func->name);
+ 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);
}
diff --git a/tools/d2c/hooks/manager.h b/tools/d2c/hooks/manager.h
index e3d51b6..97bd388 100644
--- a/tools/d2c/hooks/manager.h
+++ b/tools/d2c/hooks/manager.h
@@ -44,7 +44,7 @@ void delete_instr_hooks(instr_hooks *);
void register_hook_function(instr_hooks *, char *, char *);
/* Associe dans le code des fonctions à une instruction. */
-bool write_hook_functions(const instr_hooks *, int);
+bool write_hook_functions(const instr_hooks *, bool, int);
diff --git a/tools/d2c/qckcall.c b/tools/d2c/qckcall.c
index e2e87d2..aa066c4 100644
--- a/tools/d2c/qckcall.c
+++ b/tools/d2c/qckcall.c
@@ -101,7 +101,8 @@ static char *build_cast_if_needed(const char *callee)
/******************************************************************************
* *
-* Paramètres : callee = fonction appelée à nommer. *
+* Paramètres : top = indique si l'écriture se fait au plus haut niveau. *
+* callee = fonction appelée à nommer. *
* args = précise si la conversion est la dernière. *
* fd = descripteur d'un flux ouvert en écriture. *
* bits = gestionnaire des bits d'encodage. *
@@ -116,7 +117,7 @@ static char *build_cast_if_needed(const char *callee)
* *
******************************************************************************/
-bool call_instr_func(const char *callee, const arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
+bool call_instr_func(bool top, const char *callee, const arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
{
bool result; /* Bilan à remonter */
char *cast; /* Macro de transtypage */
@@ -124,12 +125,21 @@ bool call_instr_func(const char *callee, const arg_list_t *args, int fd, const c
cast = build_cast_if_needed(callee);
if (cast == NULL)
- dprintf(fd, "\t\t%s(instr, ", callee);
+ {
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t%s(%s, ", callee, top ? "result" : "instr");
+ }
else
{
- dprintf(fd, "\t\t%s(%s(instr), ", callee, cast);
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t%s(%s(%s), ", callee, cast, top ? "result" : "instr");
free(cast);
+
}
result = define_arg_list(args, fd, bits, list);
@@ -143,7 +153,8 @@ bool call_instr_func(const char *callee, const arg_list_t *args, int fd, const c
/******************************************************************************
* *
-* Paramètres : callee = fonction appelée à nommer. *
+* Paramètres : top = indique si l'écriture se fait au plus haut niveau. *
+* callee = fonction appelée à nommer. *
* args = précise si la conversion est la dernière. *
* fd = descripteur d'un flux ouvert en écriture. *
* bits = gestionnaire des bits d'encodage. *
@@ -158,7 +169,7 @@ bool call_instr_func(const char *callee, const arg_list_t *args, int fd, const c
* *
******************************************************************************/
-bool checked_call_instr_func(const char *callee, const arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
+bool checked_call_instr_func(bool top, const char *callee, const arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
{
bool result; /* Bilan à remonter */
char *cast; /* Macro de transtypage */
@@ -166,12 +177,21 @@ bool checked_call_instr_func(const char *callee, const arg_list_t *args, int fd,
cast = build_cast_if_needed(callee);
if (cast == NULL)
- dprintf(fd, "\t\tif (!%s(instr, ", callee);
+ {
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\tif (!%s(%s, ", callee, top ? "result" : "instr");
+ }
else
{
- dprintf(fd, "\t\tif (!%s(%s(instr), ", callee, cast);
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\tif (!%s(%s(%s), ", callee, cast, top ? "result" : "instr");
free(cast);
+
}
result = define_arg_list(args, fd, bits, list);
diff --git a/tools/d2c/qckcall.h b/tools/d2c/qckcall.h
index 2d16048..0b9ac29 100644
--- a/tools/d2c/qckcall.h
+++ b/tools/d2c/qckcall.h
@@ -36,10 +36,10 @@
/* Réalise un appel à une fonction liée à une instruction. */
-bool call_instr_func(const char *, const arg_list_t *, int, const coding_bits *, const conv_list *, const pre_processor *);
+bool call_instr_func(bool, const char *, const arg_list_t *, int, const coding_bits *, const conv_list *, const pre_processor *);
/* Réalise un appel à une fonction liée à une instruction. */
-bool checked_call_instr_func(const char *, const arg_list_t *, int, const coding_bits *, const conv_list *, const pre_processor *);
+bool checked_call_instr_func(bool, const char *, const arg_list_t *, int, const coding_bits *, const conv_list *, const pre_processor *);
diff --git a/tools/d2c/rules/manager.c b/tools/d2c/rules/manager.c
index f30559e..6c1f069 100644
--- a/tools/d2c/rules/manager.c
+++ b/tools/d2c/rules/manager.c
@@ -404,6 +404,7 @@ void register_conditional_rule(decoding_rules *rules, cond_expr *expr, const rul
/******************************************************************************
* *
* Paramètres : rules = ensemble de règles à consulter. *
+* top = indique si l'écriture se fait au plus haut niveau. *
* filter = filtre sur les règles à effectivement imprimer. *
* fd = descripteur d'un flux ouvert en écriture. *
* arch = architecture visée par l'opération. *
@@ -421,7 +422,7 @@ void register_conditional_rule(decoding_rules *rules, cond_expr *expr, const rul
* *
******************************************************************************/
-bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd, const char *arch, const char *subarch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit)
+bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter, int fd, const char *arch, const char *subarch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit)
{
bool result; /* Bilan à remonter */
size_t i; /* Boucle de parcours */
@@ -452,7 +453,10 @@ bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd,
if (rule->expr != NULL)
{
- dprintf(fd, "\t\tif ");
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\tif ");
result = write_cond_expr(rule->expr, fd, bits);
if (!result) break;
@@ -460,7 +464,13 @@ bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd,
dprintf(fd, "\n");
if (multi_lines)
- dprintf(fd, "\t\t{\n");
+ {
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t{\n");
+
+ }
}
@@ -493,7 +503,7 @@ bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd,
if (rule->expr != NULL)
dprintf(fd, "\t");
- result = call_instr_func(callable, rule->action.args, fd, bits, list, pp);
+ result = call_instr_func(top, callable, rule->action.args, fd, bits, list, pp);
break;
@@ -507,12 +517,15 @@ bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd,
if (rule->expr != NULL)
dprintf(fd, "\t");
- result = checked_call_instr_func(callable, rule->action.args, fd, bits, list, pp);
+ result = checked_call_instr_func(top, callable, rule->action.args, fd, bits, list, pp);
if (rule->expr != NULL)
dprintf(fd, "\t");
- dprintf(fd, "\t\t\tgoto quick_exit;\n");
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t\tgoto quick_exit;\n");
*exit = true;
break;
@@ -520,7 +533,13 @@ bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd,
}
if (rule->expr != NULL && multi_lines)
- dprintf(fd, "\t\t}\n");
+ {
+ if (!top)
+ dprintf(fd, "\t");
+
+ dprintf(fd, "\t}\n");
+
+ }
dprintf(fd, "\n");
diff --git a/tools/d2c/rules/manager.h b/tools/d2c/rules/manager.h
index f8ff2d6..7106c32 100644
--- a/tools/d2c/rules/manager.h
+++ b/tools/d2c/rules/manager.h
@@ -113,7 +113,7 @@ void delete_decoding_rules(decoding_rules *);
void register_conditional_rule(decoding_rules *, cond_expr *, const rule_action *);
/* Traduit en code les éventuelles règles présentes. */
-bool write_decoding_rules(decoding_rules *, CondActionType, int, const char *, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *);
+bool write_decoding_rules(decoding_rules *, bool, CondActionType, int, const char *, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *);
diff --git a/tools/d2c/spec.c b/tools/d2c/spec.c
index 1692fd8..0a47b72 100644
--- a/tools/d2c/spec.c
+++ b/tools/d2c/spec.c
@@ -342,10 +342,10 @@ bool write_encoding_spec_disass(const encoding_spec *spec, int fd, const char *a
quick_exit = false;
- result &= write_decoding_rules(spec->rules, CAT_SEE,
+ result &= write_decoding_rules(spec->rules, false, CAT_SEE,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
- result &= write_decoding_rules(spec->rules, CAT_UNPREDICTABLE,
+ result &= write_decoding_rules(spec->rules, false, CAT_UNPREDICTABLE,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
/* Création de l'instruction en elle-même */
@@ -358,12 +358,12 @@ bool write_encoding_spec_disass(const encoding_spec *spec, int fd, const char *a
/* Inscriptions des éventuelles fonctions ou propriété à lier */
- result &= write_hook_functions(spec->hooks, fd);
+ result &= write_hook_functions(spec->hooks, false, fd);
- result &= write_decoding_rules(spec->rules, CAT_CHECKED_CALL,
+ result &= write_decoding_rules(spec->rules, false, CAT_CHECKED_CALL,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
- result &= write_decoding_rules(spec->rules, CAT_CALL,
+ result &= write_decoding_rules(spec->rules, false, CAT_CALL,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
/* Création des opérandes */
@@ -471,12 +471,14 @@ bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const
/* Inscriptions des éventuelles fonctions ou propriété à lier */
- result &= write_hook_functions(spec->hooks, fd);
+ result &= write_hook_functions(spec->hooks, true, fd);
- result &= write_decoding_rules(spec->rules, CAT_CHECKED_CALL,
+ quick_exit = false;
+
+ result &= write_decoding_rules(spec->rules, true, CAT_CHECKED_CALL,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
- result &= write_decoding_rules(spec->rules, CAT_CALL,
+ result &= write_decoding_rules(spec->rules, true, CAT_CALL,
fd, arch, subarch, spec->bits, spec->conversions, pp, &quick_exit);
/* Création des opérandes */
@@ -495,9 +497,14 @@ bool write_encoding_spec_format_disass(const encoding_spec *spec, int fd, const
dprintf(fd, "\n");
- if (bad_exit)
+ if (quick_exit || bad_exit)
{
- dprintf(fd, " bad_exit:\n");
+ if (quick_exit)
+ dprintf(fd, " quick_exit:\n");
+
+ if (bad_exit)
+ dprintf(fd, " bad_exit:\n");
+
dprintf(fd, "\n");
dprintf(fd, "\tg_object_unref(G_OBJECT(result));\n");