summaryrefslogtreecommitdiff
path: root/src/decomp/context.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-11-12 22:13:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-11-12 22:13:21 (GMT)
commitae8cf6257c8d929de1b7ee86e29fcb45ab4af91c (patch)
tree59fa356b2f83020e23df4cf6975ca5d97567df4d /src/decomp/context.c
parentabaf85fdc0edb2bfe67d07d52ae734d50c6fbf61 (diff)
Changed the display of the pseudo registers by using an index.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@192 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/decomp/context.c')
-rw-r--r--src/decomp/context.c55
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;
+
+}