diff options
Diffstat (limited to 'src/decomp/context.c')
-rw-r--r-- | src/decomp/context.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/decomp/context.c b/src/decomp/context.c index 7fe6937..6440c56 100644 --- a/src/decomp/context.c +++ b/src/decomp/context.c @@ -24,6 +24,14 @@ #include "context.h" +#include <malloc.h> + + +#include "expr/pseudo.h" +#include "../arch/operand.h" +#include "../glibext/gnhash.h" + + /* Définition d'une context décompilée (instance) */ struct _GDecContext @@ -32,6 +40,12 @@ struct _GDecContext vmpa_t max; /* Première adresse à écarter */ + GHashTable *machine; /* Correspondance reg./pseudo */ + GHashTable *ssa; /* Remplacement des pseudos */ + + GDecInstruction **pseudos; /* Liste des pseudos-registre */ + size_t count; /* Taille de cette liste */ + }; @@ -87,6 +101,8 @@ static void g_dec_context_class_init(GDecContextClass *klass) static void g_dec_context_init(GDecContext *ctx) { + ctx->machine = g_hash_table_new(g_constant_hash, (GEqualFunc)g_arch_operand_compare); + ctx->ssa = g_hash_table_new(NULL, NULL); } @@ -151,3 +167,42 @@ void g_dec_context_set_max_address(GDecContext *ctx, vmpa_t max) ctx->max = max; } + + +/****************************************************************************** +* * +* Paramètres : ctx = instance à consulter, voire mettre à jour. * +* operand = opérande représentant un registre quelconque. * +* * +* Description : Convertit un registre machine en un pseudo-registre. * +* * +* Retour : Pseudo-registre, existant ou non, prêt à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_dec_context_convert_register(GDecContext *ctx, gpointer operand) +{ + GDecInstruction *result; /* Instance à retourner */ + gpointer *found; /* Pseudo-registre trouvé */ + + found = g_hash_table_lookup(ctx->machine, operand); + + if (found != NULL) result = G_DEC_INSTRUCTION(found); + else + { + result = g_pseudo_register_new(); + g_pseudo_register_set_index(G_PSEUDO_REGISTER(result), ctx->count); + + g_hash_table_insert(ctx->machine, operand, result); + + ctx->pseudos = (GDecInstruction **)realloc(ctx->pseudos, + ++ctx->count * sizeof(GDecInstruction *)); + ctx->pseudos[ctx->count - 1] = result; + + } + + return result; + +} |