summaryrefslogtreecommitdiff
path: root/src/analysis/decomp/il.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2013-01-20 13:10:06 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2013-01-20 13:10:06 (GMT)
commit37fd2f1329c56078bc8a8b2fc955aa001c109c01 (patch)
tree71bcce9a3eaf6b7569d1f1d3e057752ae517ebde /src/analysis/decomp/il.c
parenta9bbd894bd25f7c2bb72fb7d4064b19377d90c6d (diff)
Took care of shared allocations between blocks when converting registers.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@326 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/decomp/il.c')
-rw-r--r--src/analysis/decomp/il.c86
1 files changed, 59 insertions, 27 deletions
diff --git a/src/analysis/decomp/il.c b/src/analysis/decomp/il.c
index 642c921..64f6398 100644
--- a/src/analysis/decomp/il.c
+++ b/src/analysis/decomp/il.c
@@ -40,8 +40,11 @@ static bool track_used_registers(GFlowBlock *, BlockFollowPosition, GRAccessList
/* Etablit le relévé des allocations de registre. */
static void setup_awaited_regs_allocation(const GInstrBlock *, vmpa_t);
+/* Etablit la liste de tous les allocations attendues. */
+static bool merge_all_awaited_regs(GInstrBlock *, BlockVisitOrder, GRAccessList *);
+
/* Met en place un contexte adapté aux sous-blocs d'un bloc. */
-static GDecContext *create_new_context_for_sub_block(GDecContext *, GInstrBlock *);
+static GDecContext *create_new_context_for_sub_block(GDecContext *, GInstrBlock *, GHashTable *);
@@ -147,7 +150,7 @@ static bool track_used_registers(GFlowBlock *block, BlockFollowPosition pos, GRA
}
-
+ /*
do
{
vmpa_t start, end;
@@ -160,7 +163,7 @@ static bool track_used_registers(GFlowBlock *block, BlockFollowPosition pos, GRA
}
while (0);
-
+ */
break;
@@ -203,8 +206,38 @@ static void setup_awaited_regs_allocation(const GInstrBlock *list, vmpa_t start)
/******************************************************************************
* *
-* Paramètres : ctx = contexte de décompilation courant. *
-* block = block regroupant les branches de division. *
+* Paramètres : block = bloc d'instructions concerné par la visite. *
+* order = position dans la visite. *
+* list = liste à compléter. *
+* *
+* Description : Etablit la liste de tous les allocations attendues. *
+* *
+* Retour : true pour parcourir tous les blocs. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool merge_all_awaited_regs(GInstrBlock *block, BlockVisitOrder order, GRAccessList *list)
+{
+ const GRAccessList *awaited; /* Registres conséquents */
+
+ if (G_IS_FLOW_BLOCK(block))
+ {
+ awaited = g_flow_block_list_regs_accesses(G_FLOW_BLOCK(block));
+ g_raccess_list_merge(list, awaited);
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ctx = contexte de décompilation courant. *
+* block = block regroupant les branches de division. *
+* shared = liste des allocations passées de registres attendus.*
* *
* Description : Met en place un contexte adapté aux sous-blocs d'un bloc. *
* *
@@ -214,17 +247,26 @@ static void setup_awaited_regs_allocation(const GInstrBlock *list, vmpa_t start)
* *
******************************************************************************/
-static GDecContext *create_new_context_for_sub_block(GDecContext *ctx, GInstrBlock *block)
+static GDecContext *create_new_context_for_sub_block(GDecContext *ctx, GInstrBlock *block, GHashTable *shared)
{
+ GDecContext *result; /* Contexte à retourner */
+ GRAccessList *list; /* Allocations attendues */
+ result = g_dec_context_dup(ctx);
- return g_dec_context_dup(ctx);
+ list = g_raccess_list_new();
+ g_instr_block_visit(block, (instr_block_visitor_cb)merge_all_awaited_regs, list);
+ g_dec_context_set_awaited(result, list);
+ g_object_unref(G_OBJECT(list));
+ g_dec_context_set_shared_allocs(result, shared);
+ return result;
}
+
/* ---------------------------------------------------------------------------------- */
/* ENCADREMENT DES INSTRUCTIONS */
/* ---------------------------------------------------------------------------------- */
@@ -282,8 +324,6 @@ static GDecInstruction *merge_decompiled_instructions(GDecInstruction *group, GD
static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecContext *ctx)
{
- GDecInstruction *res;
-
GArchInstruction *instrs; /* Liste d'instructions natives*/
GArchInstruction *first; /* Première instruction du lot */
GArchInstruction *last; /* Dernière instruction du lot */
@@ -291,12 +331,12 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon
GArchInstruction *iter; /* Boucle de parcours */
GDecInstruction *decomp; /* Dernier résultat de décomp. */
GInstrBlock *sub_parent; /* Groupe des sous-branches */
+ GHashTable *sub_shared; /* Allocations communes */
GDecContext *sub_ctx; /* Sous-contexte pour branche */
GDecInstruction *true_dinstr; /* Décompilation 'cond vraie' */
GDecInstruction *false_dinstr; /* Décompilation 'cond fausse' */
GArchInstruction *next; /* Instruction de branchement */
vmpa_t next_addr; /* Adresse de cette instruct° */
- //GInstrBlock *next_parent; /* Bloc basique correspondant */
GInstrBlock *next_block; /* Sous-bloc basique direct */
instrs = g_flow_block_get_all_instructions_list(block);
@@ -316,14 +356,13 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon
/* Post-traitement selon les types de lien */
-
- //res = g_dec_context_get_decomp_instrs(ctx);
-
-
/* if ... then ... else ... */
if (G_IS_ITE_INSTRUCTION(decomp))
{
sub_parent = g_instr_block_get_links_block(G_INSTR_BLOCK(block));
+ sub_shared = g_hash_table_new_full((GHashFunc)g_arch_register_hash,
+ (GEqualFunc)g_arch_register_equal,
+ g_object_unref, g_object_unref);
true_dinstr = NULL;
@@ -335,9 +374,9 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon
if (next_block != NULL)
{
- sub_ctx = create_new_context_for_sub_block(ctx, sub_parent);
+ sub_ctx = create_new_context_for_sub_block(ctx, next_block, sub_shared);
true_dinstr = decompiled_basic_block(next_block, sub_ctx);
- /* TODO : merge awaited */
+ g_dec_context_spread_allocated_shared_regs(ctx, sub_ctx);
g_object_unref(G_OBJECT(sub_ctx));
}
@@ -353,29 +392,22 @@ static GDecInstruction *decompiled_instructions_block(GFlowBlock *block, GDecCon
if (next_block != NULL)
{
- sub_ctx = create_new_context_for_sub_block(ctx, sub_parent);
+ sub_ctx = create_new_context_for_sub_block(ctx, next_block, sub_shared);
false_dinstr = decompiled_basic_block(next_block, sub_ctx);
- /* TODO : merge awaited */
+ g_dec_context_spread_allocated_shared_regs(ctx, sub_ctx);
g_object_unref(G_OBJECT(sub_ctx));
}
}
- printf(" -> ite : %p + %p\n", true_dinstr, false_dinstr);
-
- printf(" -> ite : %s + %s\n",
- true_dinstr ? g_type_name(G_TYPE_FROM_INSTANCE(true_dinstr)) : "none",
- false_dinstr ? g_type_name(G_TYPE_FROM_INSTANCE(false_dinstr)) : "none");
-
-
g_ite_instruction_set_branches(G_ITE_INSTRUCTION(decomp), true_dinstr, false_dinstr);
+ g_hash_table_unref(sub_shared);
+
}
/* Renvoi des instructions mises en place */
- //return res;
-
return g_dec_context_get_decomp_instrs(ctx);
}