summaryrefslogtreecommitdiff
path: root/src/decomp
diff options
context:
space:
mode:
Diffstat (limited to 'src/decomp')
-rw-r--r--src/decomp/expr/access.c6
-rw-r--r--src/decomp/expr/arithm.c6
-rw-r--r--src/decomp/expr/array.c6
-rw-r--r--src/decomp/expr/assign.c10
-rw-r--r--src/decomp/expr/assign.h4
-rw-r--r--src/decomp/expr/block.c41
-rw-r--r--src/decomp/expr/block.h3
-rw-r--r--src/decomp/expr/call.c3
-rw-r--r--src/decomp/expr/cond.c6
-rw-r--r--src/decomp/expr/pseudo.c27
-rw-r--r--src/decomp/expr/pseudo.h16
-rw-r--r--src/decomp/expr/return.c3
-rw-r--r--src/decomp/instr/ite.c9
-rw-r--r--src/decomp/instruction.c7
-rw-r--r--src/decomp/instruction.h10
15 files changed, 127 insertions, 30 deletions
diff --git a/src/decomp/expr/access.c b/src/decomp/expr/access.c
index f06c47b..8afe635 100644
--- a/src/decomp/expr/access.c
+++ b/src/decomp/expr/access.c
@@ -158,10 +158,12 @@ static bool g_access_expression_visit(GAccessExpression *expr, dec_instr_visitor
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->owner), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->owner), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->target), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->target), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
return result;
diff --git a/src/decomp/expr/arithm.c b/src/decomp/expr/arithm.c
index 3811cf4..e8a4c30 100644
--- a/src/decomp/expr/arithm.c
+++ b/src/decomp/expr/arithm.c
@@ -163,10 +163,12 @@ static bool g_arithm_expression_visit(GArithmExpression *expr, dec_instr_visitor
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op1), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op1), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op2), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->op2), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
return result;
diff --git a/src/decomp/expr/array.c b/src/decomp/expr/array.c
index 4053169..b2bb2f1 100644
--- a/src/decomp/expr/array.c
+++ b/src/decomp/expr/array.c
@@ -158,10 +158,12 @@ static bool g_array_access_visit(GArrayAccess *expr, dec_instr_visitor_cb callba
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->array), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->array), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->index), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->index), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
return result;
diff --git a/src/decomp/expr/assign.c b/src/decomp/expr/assign.c
index 26d31f6..939407d 100644
--- a/src/decomp/expr/assign.c
+++ b/src/decomp/expr/assign.c
@@ -158,10 +158,12 @@ static bool g_assign_expression_visit(GAssignExpression *expr, dec_instr_visitor
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->dest), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->dest), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->src), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->src), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
return result;
@@ -259,7 +261,7 @@ static GBufferLine *g_assign_expression_print(const GAssignExpression *expr, GCo
* *
******************************************************************************/
-GDecInstruction *g_assign_expression_get_dest(const GAssignExpression *assign)
+GDecExpression *g_assign_expression_get_dest(const GAssignExpression *assign)
{
return assign->dest;
@@ -278,7 +280,7 @@ GDecInstruction *g_assign_expression_get_dest(const GAssignExpression *assign)
* *
******************************************************************************/
-GDecInstruction *g_assign_expression_get_src(const GAssignExpression *assign)
+GDecExpression *g_assign_expression_get_src(const GAssignExpression *assign)
{
return assign->src;
diff --git a/src/decomp/expr/assign.h b/src/decomp/expr/assign.h
index ce441f6..b55853e 100644
--- a/src/decomp/expr/assign.h
+++ b/src/decomp/expr/assign.h
@@ -56,10 +56,10 @@ GType g_assign_expression_get_type(void);
GDecInstruction *g_assign_expression_new(GDecExpression *, GDecExpression *);
/* Indique la destination d'une assignation. */
-GDecInstruction *g_assign_expression_get_dest(const GAssignExpression *);
+GDecExpression *g_assign_expression_get_dest(const GAssignExpression *);
/* Indique la source d'une assignation. */
-GDecInstruction *g_assign_expression_get_src(const GAssignExpression *);
+GDecExpression *g_assign_expression_get_src(const GAssignExpression *);
diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c
index 3c56ef6..b58972d 100644
--- a/src/decomp/expr/block.c
+++ b/src/decomp/expr/block.c
@@ -25,6 +25,7 @@
#include <malloc.h>
+#include <string.h>
#include "../expression-int.h"
@@ -163,7 +164,8 @@ static bool g_expr_block_visit(GExprBlock *block, dec_instr_visitor_cb callback,
result = true;
for (i = 0; i < block->count && result; i++)
- result = g_dec_instruction_visit(block->list[i], callback, flags, data);
+ result = _g_dec_instruction_visit(block->list[i], G_DEC_INSTRUCTION(block),
+ callback, flags, data);
return result;
@@ -270,3 +272,40 @@ void g_expr_block_add_item(GExprBlock *block, GDecInstruction *item)
block->list[block->count - 1] = item;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = ensemble à faire évoluer. *
+* item = nouvel élément à retirer de l'ensemble. *
+* *
+* Description : Supprime une instruction décompilée du conteneur existant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_expr_block_delete_item(GExprBlock *block, GDecInstruction *item)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < block->count; i++)
+ if (block->list[i] == item)
+ break;
+
+ if (i < block->count)
+ {
+ if ((i + 1) < block->count)
+ memmove(&block->list[i], &block->list[i + 1],
+ (block->count - i - 1) * sizeof(GDecInstruction *));
+
+ block->list = (GDecInstruction **)realloc(block->list,
+ --block->count * sizeof(GDecInstruction *));
+
+ g_object_unref(G_OBJECT(item));
+
+ }
+
+}
diff --git a/src/decomp/expr/block.h b/src/decomp/expr/block.h
index 4ae4ff1..b0c2baa 100644
--- a/src/decomp/expr/block.h
+++ b/src/decomp/expr/block.h
@@ -57,6 +57,9 @@ GDecInstruction *g_expr_block_new(GDecInstruction *);
/* Ajoute une instruction décompilée au conteneur existant. */
void g_expr_block_add_item(GExprBlock *, GDecInstruction *);
+/* Supprime une instruction décompilée du conteneur existant. */
+void g_expr_block_delete_item(GExprBlock *, GDecInstruction *);
+
#endif /* _DECOMP_EXPR_BLOCK_H */
diff --git a/src/decomp/expr/call.c b/src/decomp/expr/call.c
index ed1c43a..9aad9c0 100644
--- a/src/decomp/expr/call.c
+++ b/src/decomp/expr/call.c
@@ -166,7 +166,8 @@ static bool g_routine_call_visit(GRoutineCall *call, dec_instr_visitor_cb callba
result = true;
for (i = 0; i < call->count && result; i++)
- result = g_dec_instruction_visit(call->args[i], callback, flags, data);
+ result = _g_dec_instruction_visit(call->args[i], G_DEC_INSTRUCTION(call),
+ callback, flags, data);
return result;
diff --git a/src/decomp/expr/cond.c b/src/decomp/expr/cond.c
index d96f483..fab2c17 100644
--- a/src/decomp/expr/cond.c
+++ b/src/decomp/expr/cond.c
@@ -161,10 +161,12 @@ static bool g_cond_expression_visit(GCondExpression *expr, dec_instr_visitor_cb
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->a), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->a), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->b), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->b), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
return result;
diff --git a/src/decomp/expr/pseudo.c b/src/decomp/expr/pseudo.c
index 9da76e7..7c7ba71 100644
--- a/src/decomp/expr/pseudo.c
+++ b/src/decomp/expr/pseudo.c
@@ -38,6 +38,8 @@ struct _GPseudoRegister
{
GDecExpression parent; /* A laisser en premier */
+ PseudoRegUsage usage; /* Type d'utilisation attendue */
+
char *name; /* Désignation générale */
size_t index; /* Position dans l'ensemble */
GBinVariable *var; /* Variable plus précise */
@@ -112,7 +114,7 @@ static void g_pseudo_register_init(GPseudoRegister *reg)
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : usage = précision quant à l'usage du pseudo-registre à créer.*
* *
* Description : Assigne le contenu d'une expression dans une autre. *
* *
@@ -122,12 +124,14 @@ static void g_pseudo_register_init(GPseudoRegister *reg)
* *
******************************************************************************/
-GDecInstruction *g_pseudo_register_new(void)
+GDecInstruction *g_pseudo_register_new(PseudoRegUsage usage)
{
GPseudoRegister *result; /* Pseudo-registre à renvoyer */
result = g_object_new(G_TYPE_PSEUDO_REGISTER, NULL);
+ result->usage = usage;
+
return G_DEC_INSTRUCTION(result);
}
@@ -135,6 +139,25 @@ GDecInstruction *g_pseudo_register_new(void)
/******************************************************************************
* *
+* Paramètres : reg = pseudo-registre à venir consulter. *
+* *
+* Description : Indique l'usage attendu du pseudo-registre consulté. *
+* *
+* Retour : Utilité du pseudo-registre en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PseudoRegUsage g_pseudo_register_get_usage(const GPseudoRegister *reg)
+{
+ return reg->usage;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : reg = expression à transcrire en version humaine. *
* buffer = tampon où doit se réaliser l'insertion. *
* line = ligne d'impression prête à emploi ou NULL. *
diff --git a/src/decomp/expr/pseudo.h b/src/decomp/expr/pseudo.h
index a465b41..e7f3b00 100644
--- a/src/decomp/expr/pseudo.h
+++ b/src/decomp/expr/pseudo.h
@@ -42,6 +42,17 @@
+/* Types de pseudo-registre */
+typedef enum _PseudoRegUsage
+{
+ PRU_THIS, /* "this" pour les objets */
+ PRU_ARG, /* Argument de fonction */
+ PRU_LOCAL, /* Variable locale */
+ PRU_FIXED /* Variable type champ */
+
+} PseudoRegUsage;
+
+
/* Définition d'un pseudo-registre (instance) */
typedef struct _GPseudoRegister GPseudoRegister;
@@ -53,7 +64,10 @@ typedef struct _GPseudoRegisterClass GPseudoRegisterClass;
GType g_pseudo_register_get_type(void);
/* Assigne le contenu d'une expression dans une autre. */
-GDecInstruction *g_pseudo_register_new(void);
+GDecInstruction *g_pseudo_register_new(PseudoRegUsage);
+
+/* Indique l'usage attendu du pseudo-registre consulté. */
+PseudoRegUsage g_pseudo_register_get_usage(const GPseudoRegister *);
/* Définit un nom général pour un pseudo-registre donné. */
void g_pseudo_register_set_basename(GPseudoRegister *, const char *);
diff --git a/src/decomp/expr/return.c b/src/decomp/expr/return.c
index d012893..65fd641 100644
--- a/src/decomp/expr/return.c
+++ b/src/decomp/expr/return.c
@@ -156,7 +156,8 @@ static bool g_return_expression_visit(GReturnExpression *expr, dec_instr_visitor
bool result; /* Bilan à retourner */
if (expr->payload)
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->payload), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(expr->payload), G_DEC_INSTRUCTION(expr),
+ callback, flags, data);
else
result = false;
diff --git a/src/decomp/instr/ite.c b/src/decomp/instr/ite.c
index 1abf61c..d78bb31 100644
--- a/src/decomp/instr/ite.c
+++ b/src/decomp/instr/ite.c
@@ -178,13 +178,16 @@ static bool g_ite_instruction_visit(GITEInstruction *instr, dec_instr_visitor_cb
{
bool result; /* Bilan à retourner */
- result = g_dec_instruction_visit(G_DEC_INSTRUCTION(instr->cond), callback, flags, data);
+ result = _g_dec_instruction_visit(G_DEC_INSTRUCTION(instr->cond), G_DEC_INSTRUCTION(instr),
+ callback, flags, data);
if (result)
- result = g_dec_instruction_visit(instr->true_branch, callback, flags, data);
+ result = _g_dec_instruction_visit(instr->true_branch, G_DEC_INSTRUCTION(instr),
+ callback, flags, data);
if (result && instr->false_branch != NULL)
- result = g_dec_instruction_visit(instr->false_branch, callback, flags, data);
+ result = _g_dec_instruction_visit(instr->false_branch, G_DEC_INSTRUCTION(instr),
+ callback, flags, data);
return result;
diff --git a/src/decomp/instruction.c b/src/decomp/instruction.c
index 3a9917a..92388fc 100644
--- a/src/decomp/instruction.c
+++ b/src/decomp/instruction.c
@@ -80,6 +80,7 @@ static void g_dec_instruction_init(GDecInstruction *instr)
/******************************************************************************
* *
* Paramètres : instr = première instruction à venir visiter. *
+* parent = instruction parente. *
* callback = procédure à appeler à chaque instruction visitée. *
* flags = moments des appels à réaliser en retour. *
* data = données quelconques associées au visiteur. *
@@ -92,20 +93,20 @@ static void g_dec_instruction_init(GDecInstruction *instr)
* *
******************************************************************************/
-bool g_dec_instruction_visit(GDecInstruction *instr, dec_instr_visitor_cb callback, DecInstrVisitFlags flags, void *data)
+bool _g_dec_instruction_visit(GDecInstruction *instr, GDecInstruction *parent, dec_instr_visitor_cb callback, DecInstrVisitFlags flags, void *data)
{
bool result; /* Bilan à retourner */
result = true;
if (flags & DVF_ENTER)
- result = callback(instr, DVF_ENTER, data);
+ result = callback(instr, parent, DVF_ENTER, data);
if (result && instr->visit)
result = instr->visit(instr, callback, flags, data);
if (result && (flags & DVF_EXIT))
- result = callback(instr, DVF_EXIT, data);
+ result = callback(instr, parent, DVF_EXIT, data);
return result;
diff --git a/src/decomp/instruction.h b/src/decomp/instruction.h
index ed8090d..3c8657b 100644
--- a/src/decomp/instruction.h
+++ b/src/decomp/instruction.h
@@ -50,20 +50,22 @@ typedef struct _GDecInstructionClass GDecInstructionClass;
/* Position au cours d'une visite */
typedef enum _DecInstrVisitFlags
{
- DVF_ENTER, /* Entrée dans une instruction */
- DVF_EXIT /* Sortie d'une instruction */
+ DVF_ENTER = (1 << 0), /* Entrée dans une instruction */
+ DVF_EXIT = (1 << 1) /* Sortie d'une instruction */
} DecInstrVisitFlags;
/* Rappel à chaque instruction décompilée visitée */
-typedef bool (* dec_instr_visitor_cb) (GDecInstruction *, DecInstrVisitFlags, void *);
+typedef bool (* dec_instr_visitor_cb) (GDecInstruction *, GDecInstruction *, DecInstrVisitFlags, void *);
/* Indique le type défini pour une instruction décompilée. */
GType g_dec_instruction_get_type(void);
/* Visite un ensemble hiérarchique d'instructions décompilées. */
-bool g_dec_instruction_visit(GDecInstruction *, dec_instr_visitor_cb, DecInstrVisitFlags, void *);
+bool _g_dec_instruction_visit(GDecInstruction *, GDecInstruction *, dec_instr_visitor_cb, DecInstrVisitFlags, void *);
+
+#define g_dec_instruction_visit(instr, callback, flags, data) _g_dec_instruction_visit(instr, NULL, callback, flags, data)
/* Remplace une instruction décompilée par une autre. */
bool g_dec_instruction_replace(GDecInstruction *, GDecInstruction *, GDecInstruction *);