summaryrefslogtreecommitdiff
path: root/src/decomp/instr
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-11-28 09:43:50 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-11-28 09:43:50 (GMT)
commitf95598b68b98f6eda701f8f02bc09cb13f65fc72 (patch)
treeeefee33963448a1ce53a7eb80dacabbcdce8fc21 /src/decomp/instr
parentfbb4b6f53d2189ba9f61c1fd149534d8aef82dcd (diff)
Followed the excution flow to decompile instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@293 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/decomp/instr')
-rw-r--r--src/decomp/instr/ite.c51
-rw-r--r--src/decomp/instr/ite.h3
2 files changed, 42 insertions, 12 deletions
diff --git a/src/decomp/instr/ite.c b/src/decomp/instr/ite.c
index f08df1e..7c68031 100644
--- a/src/decomp/instr/ite.c
+++ b/src/decomp/instr/ite.c
@@ -35,6 +35,9 @@ struct _GITEInstruction
GDecExpression *cond; /* Condition prise en compte */
+ GDecInstruction *true_branch; /* Condition vérifiée */
+ GDecInstruction *false_branch; /* Condition non vérifiée */
+
union
{
vmpa_t addr; /* Adresse de saut */
@@ -68,7 +71,7 @@ static void g_ite_instruction_class_init(GITEInstructionClass *);
static void g_ite_instruction_init(GITEInstruction *);
/* Imprime pour l'écran un version humaine d'une instruction. */
-static void g_ite_instruction_print(const GITEInstruction *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+static GBufferLine *g_ite_instruction_print(const GITEInstruction *, GCodeBuffer *, GBufferLine *, GLangOutput *);
@@ -148,6 +151,28 @@ GDecInstruction *g_ite_instruction_new(GDecExpression *cond, vmpa_t if_true, vmp
/******************************************************************************
* *
+* Paramètres : cond = expression fixant le choix de l'aiguillage. *
+* true_branch = instructions si la condition est vérifiée. *
+* false_branch = instructions si la cond. n'est pas vérifiée. *
+* *
+* Description : Détermine le corps des différentes branches possibles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_ite_instruction_set_branches(GITEInstruction *expr, GDecInstruction *true_branch, GDecInstruction *false_branch)
+{
+ expr->true_branch = true_branch;
+ expr->false_branch = false_branch;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : expr = instruction à transcrire en version humaine. *
* buffer = tampon où doit se réaliser l'insertion. *
* line = ligne d'impression prête à emploi ou NULL. *
@@ -161,22 +186,24 @@ GDecInstruction *g_ite_instruction_new(GDecExpression *cond, vmpa_t if_true, vmp
* *
******************************************************************************/
-static void g_ite_instruction_print(const GITEInstruction *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+static GBufferLine *g_ite_instruction_print(const GITEInstruction *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
{
- g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "if ", 3, RTT_KEY_WORD);
+ GBufferLine *result; /* Ligne à retourner */
- g_dec_instruction_print(G_DEC_INSTRUCTION(expr->cond),
- buffer, line, output);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, "if ", 3, RTT_KEY_WORD);
- /*
- g_dec_instruction_print(G_DEC_INSTRUCTION(expr->dest),
- buffer, line, output);
+ result = g_dec_instruction_print(G_DEC_INSTRUCTION(expr->cond),
+ buffer, line, output);
- g_buffer_line_insert_text(line, BLC_ASSEMBLY_HEAD, " = ", 3, RTT_SIGNS);
+ if (expr->true_branch != NULL)
+ result = g_dec_instruction_print(expr->true_branch, buffer, result, output);
- g_dec_instruction_print(G_DEC_INSTRUCTION(expr->src),
- buffer, line, output);
- */
+ if (expr->false_branch != NULL)
+ {
+ g_buffer_line_insert_text(result, BLC_ASSEMBLY_HEAD, "else", 4, RTT_KEY_WORD);
+ result = g_dec_instruction_print(expr->false_branch, buffer, result, output);
+ }
+ return result;
}
diff --git a/src/decomp/instr/ite.h b/src/decomp/instr/ite.h
index cff073a..e53abe8 100644
--- a/src/decomp/instr/ite.h
+++ b/src/decomp/instr/ite.h
@@ -52,6 +52,9 @@ typedef struct _GITEInstructionClass GITEInstructionClass;
/* Indique le type défini pour un aiguillage du flux d'exécution. */
GType g_ite_instruction_get_type(void);
+/* Détermine le corps des différentes branches possibles. */
+void g_ite_instruction_set_branches(GITEInstruction *, GDecInstruction *, GDecInstruction *);
+
/* Exprime un aiguillage du flux en fonction d'une condition. */
GDecInstruction *g_ite_instruction_new(GDecExpression *, vmpa_t, vmpa_t);