summaryrefslogtreecommitdiff
path: root/src/decomp/expr/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/decomp/expr/block.c')
-rw-r--r--src/decomp/expr/block.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c
new file mode 100644
index 0000000..c14e169
--- /dev/null
+++ b/src/decomp/expr/block.c
@@ -0,0 +1,185 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * block.c - regroupement d'un lot d'instructions
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "block.h"
+
+
+#include <malloc.h>
+
+
+#include "../expression-int.h"
+
+
+
+/* Définition d'un ensemble d'instructions décompilées (instance) */
+struct _GExprBlock
+{
+ GDecExpression parent; /* A laisser en premier */
+
+ GDecInstruction **list; /* Instructions contenues */
+ size_t count; /* Taille de cette liste */
+
+};
+
+
+/* Définition d'un ensemble d'instructions décompilées (classe) */
+struct _GExprBlockClass
+{
+ GDecExpressionClass parent; /* A laisser en premier */
+
+};
+
+
+
+/* Initialise la classe des ensembles d'instructions. */
+static void g_expr_block_class_init(GExprBlockClass *);
+
+/* Initialise une instance d'ensemble d'instructions. */
+static void g_expr_block_init(GExprBlock *);
+
+/* Imprime pour l'écran un version humaine d'une expression. */
+static void g_expr_block_print(const GExprBlock *, GCodeBuffer *, GBufferLine *, GLangOutput *);
+
+
+
+/* Indique le type défini pour un ensemble d'instructions décompilées. */
+G_DEFINE_TYPE(GExprBlock, g_expr_block, G_TYPE_DEC_EXPRESSION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des ensembles d'instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_expr_block_class_init(GExprBlockClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = instance à initialiser. *
+* *
+* Description : Initialise une instance d'ensemble d'instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_expr_block_init(GExprBlock *block)
+{
+ GDecInstruction *instr; /* Autre version de l'objet */
+
+ instr = G_DEC_INSTRUCTION(block);
+
+ instr->print = (dec_instr_print_fc)g_expr_block_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = premier élément du nouvel ensemble. *
+* *
+* Description : Constuit un conteneur pour diverses instructions décompilées.*
+* *
+* Retour : Conteneur d'instructions mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDecInstruction *g_expr_block_new(GDecInstruction *item)
+{
+ GExprBlock *result; /* Groupe d'instructions à renvoyer */
+
+ result = g_object_new(G_TYPE_EXPR_BLOCK, NULL);
+
+ g_expr_block_add_item(result, item);
+
+ return G_DEC_INSTRUCTION(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = expression à transcrire en version humaine. *
+* buffer = tampon où doit se réaliser l'insertion. *
+* line = ligne d'impression prête à emploi ou NULL. *
+* output = langage de programmation de sortie. *
+* *
+* Description : Imprime pour l'écran un version humaine d'une expression. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_expr_block_print(const GExprBlock *block, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < block->count; i++)
+ {
+ if (i > 0)
+ line = g_code_buffer_append_new_line(buffer); /* FIXME : n° de ligne */
+
+ g_dec_instruction_print(block->list[i], buffer, line, output);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : block = ensemble à faire évoluer. *
+* item = nouvel élément à placer dans l'ensemble. *
+* *
+* Description : Ajoute une instruction décompilée au conteneur existant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_expr_block_add_item(GExprBlock *block, GDecInstruction *item)
+{
+ block->list = (GDecInstruction **)realloc(block->list,
+ ++block->count * sizeof(GDecInstruction *));
+ block->list[block->count - 1] = item;
+
+}