From acd355c4c5ae25fb9cac64b8dc17407a2bcc979b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 21 May 2017 18:48:11 +0200 Subject: Refined the whole share system for operands. --- ChangeLog | 47 +++++- src/arch/arm/register.c | 6 +- src/arch/arm/v7/core.c | 57 ++++++- src/arch/arm/v7/operands/coproc.c | 181 ++++++++++++++++++++++- src/arch/arm/v7/operands/coproc.h | 19 +++ src/arch/arm/v7/operands/estate.c | 181 ++++++++++++++++++++++- src/arch/arm/v7/operands/estate.h | 19 +++ src/arch/arm/v7/operands/limitation.c | 187 +++++++++++++++++++++-- src/arch/arm/v7/operands/limitation.h | 19 +++ src/arch/arm/v7/operands/maccess.c | 249 +++++++++++++++++++++++++++++-- src/arch/arm/v7/operands/maccess.h | 19 +++ src/arch/arm/v7/operands/offset.c | 227 ++++++++++++++++++++++++++-- src/arch/arm/v7/operands/offset.h | 19 +++ src/arch/arm/v7/operands/reglist.c | 271 +++++++++++++++++++++++++++++++++- src/arch/arm/v7/operands/reglist.h | 19 +++ src/arch/arm/v7/operands/rotation.c | 231 ++++++++++++++++++++++++++--- src/arch/arm/v7/operands/rotation.h | 26 +++- src/arch/arm/v7/operands/shift.c | 239 +++++++++++++++++++++++++++--- src/arch/arm/v7/operands/shift.h | 27 +++- src/arch/arm/v7/register.c | 157 ++++++++++++++++++-- src/arch/arm/v7/register.h | 20 +++ src/arch/dalvik/operands/args.c | 154 ++++++++++++++----- src/arch/dalvik/operands/pool.c | 172 +++++++++++++-------- src/arch/dalvik/operands/register.c | 194 +++++++++++++++--------- src/arch/dalvik/register.c | 101 ++++++++----- src/arch/dalvik/register.h | 2 +- src/arch/immediate.c | 154 ++++++++++--------- src/arch/instruction.c | 24 ++- src/arch/operand-int.h | 21 ++- src/arch/operand.c | 115 ++++++++++++--- src/arch/operand.h | 2 +- src/arch/register-int.h | 20 ++- src/arch/register.c | 253 ++++++++++++++++++++++++++++--- src/arch/register.h | 18 ++- src/arch/sharing/instance-int.h | 22 ++- src/arch/sharing/instance.c | 64 +++++++- src/arch/sharing/instance.h | 12 +- src/arch/sharing/manager.c | 77 ++++++++-- src/arch/sharing/manager.h | 5 +- src/arch/target.c | 142 ++++++++++-------- src/common/sort.c | 66 +++++++++ src/common/sort.h | 6 + src/core/processors.c | 3 + 43 files changed, 3302 insertions(+), 545 deletions(-) diff --git a/ChangeLog b/ChangeLog index 906efaa..bceb52b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,50 @@ -17-05-16 Cyrille Bagard +17-05-21 Cyrille Bagard + * src/arch/arm/register.c: + * src/arch/arm/v7/core.c: + * src/arch/arm/v7/operands/coproc.c: + * src/arch/arm/v7/operands/coproc.h: + * src/arch/arm/v7/operands/estate.c: + * src/arch/arm/v7/operands/estate.h: + * src/arch/arm/v7/operands/limitation.c: + * src/arch/arm/v7/operands/limitation.h: + * src/arch/arm/v7/operands/maccess.c: + * src/arch/arm/v7/operands/maccess.h: + * src/arch/arm/v7/operands/offset.c: + * src/arch/arm/v7/operands/offset.h: + * src/arch/arm/v7/operands/reglist.c: + * src/arch/arm/v7/operands/reglist.h: + * src/arch/arm/v7/operands/rotation.c: + * src/arch/arm/v7/operands/rotation.h: + * src/arch/arm/v7/operands/shift.c: + * src/arch/arm/v7/operands/shift.h: + * src/arch/arm/v7/register.c: + * src/arch/arm/v7/register.h: + * src/arch/dalvik/operands/args.c: + * src/arch/dalvik/operands/pool.c: + * src/arch/dalvik/operands/register.c: + * src/arch/dalvik/register.c: + * src/arch/dalvik/register.h: + * src/arch/immediate.c: + * src/arch/instruction.c: + * src/arch/operand-int.h: + * src/arch/operand.c: + * src/arch/operand.h: + * src/arch/register-int.h: + * src/arch/register.c: + * src/arch/register.h: + * src/arch/sharing/instance-int.h: + * src/arch/sharing/instance.c: + * src/arch/sharing/instance.h: + * src/arch/sharing/manager.c: + * src/arch/sharing/manager.h: + * src/arch/target.c: + * src/common/sort.c: + * src/common/sort.h: + * src/core/processors.c: + Refine the whole share system for operands. + +17-05-16 Cyrille Bagard * plugins/mobicore/symbols.c: * plugins/pychrysa/format/symbol.c: diff --git a/src/arch/arm/register.c b/src/arch/arm/register.c index fc7ecde..c351f12 100644 --- a/src/arch/arm/register.c +++ b/src/arch/arm/register.c @@ -45,7 +45,7 @@ static void g_arm_register_finalize(GArmRegister *); static guint g_arm_register_hash(const GArmRegister *); /* Compare un registre avec un autre. */ -static int g_arm_register_compare(const GArmRegister * const *, const GArmRegister * const *); +static int g_arm_register_compare(const GArmRegister *, const GArmRegister *); @@ -189,11 +189,11 @@ static guint g_arm_register_hash(const GArmRegister *reg) * * ******************************************************************************/ -static int g_arm_register_compare(const GArmRegister * const *a, const GArmRegister * const *b) +static int g_arm_register_compare(const GArmRegister *a, const GArmRegister *b) { int result; /* Bilan à retourner */ - result = sort_unsigned_long((*a)->index, (*b)->index); + result = sort_unsigned_long(b->index, b->index); return result; diff --git a/src/arch/arm/v7/core.c b/src/arch/arm/v7/core.c index 299b9bd..ee43366 100644 --- a/src/arch/arm/v7/core.c +++ b/src/arch/arm/v7/core.c @@ -24,6 +24,17 @@ #include "core.h" +#include "register.h" +#include "operands/coproc.h" +#include "operands/estate.h" +#include "operands/limitation.h" +#include "operands/maccess.h" +#include "operands/offset.h" +#include "operands/reglist.h" +#include "operands/rotation.h" +#include "operands/shift.h" + + /****************************************************************************** * * @@ -41,7 +52,31 @@ bool init_armv7_core(void) { bool result; /* Bilan à renvoyer */ - result = true; + result = init_armv7_register_sharing(); + + if (result) + result = init_armv7_coproc_operand_sharing(); + + if (result) + result = init_armv7_endian_operand_sharing(); + + if (result) + result = init_armv7_limitation_operand_sharing(); + + if (result) + result = init_armv7_maccess_operand_sharing(); + + if (result) + result = init_armv7_offset_operand_sharing(); + + if (result) + result = init_armv7_reglist_operand_sharing(); + + if (result) + result = init_armv7_rotation_operand_sharing(); + + if (result) + result = init_armv7_shift_operand_sharing(); return result; @@ -62,6 +97,16 @@ bool init_armv7_core(void) #ifdef DEBUG_DUMP_STATS void dump_armv7_share_stats(void) { + dump_armv7_register_share_stats(); + + dump_armv7_coproc_operand_share_stats(); + dump_armv7_endian_operand_share_stats(); + dump_armv7_limitation_operand_share_stats(); + dump_armv7_maccess_operand_share_stats(); + dump_armv7_offset_operand_share_stats(); + dump_armv7_reglist_operand_share_stats(); + dump_armv7_rotation_operand_share_stats(); + dump_armv7_shift_operand_share_stats(); } #endif @@ -81,5 +126,15 @@ void dump_armv7_share_stats(void) void exit_armv7_core(void) { + exit_armv7_register_sharing(); + + exit_armv7_coproc_operand_sharing(); + exit_armv7_endian_operand_sharing(); + exit_armv7_limitation_operand_sharing(); + exit_armv7_maccess_operand_sharing(); + exit_armv7_offset_operand_sharing(); + exit_armv7_reglist_operand_sharing(); + exit_armv7_rotation_operand_sharing(); + exit_armv7_shift_operand_sharing(); } diff --git a/src/arch/arm/v7/operands/coproc.c b/src/arch/arm/v7/operands/coproc.c index 5f90cb2..ff34943 100644 --- a/src/arch/arm/v7/operands/coproc.c +++ b/src/arch/arm/v7/operands/coproc.c @@ -25,9 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande représentant un co-processeur (instance) */ struct _GArmV7CoprocOperand { @@ -58,11 +63,34 @@ static void g_armv7_coproc_operand_dispose(GArmV7CoprocOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_coproc_operand_finalize(GArmV7CoprocOperand *); +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_coproc_operand_define_template(const GArmV7CoprocOperand *, GArmV7CoprocOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_coproc_operand_compare(const GArmV7CoprocOperand *, const GArmV7CoprocOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_coproc_operand_print(const GArmV7CoprocOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_coproc_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_coproc_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour un co-processeur ARM. */ G_DEFINE_TYPE(GArmV7CoprocOperand, g_armv7_coproc_operand, G_TYPE_ARCH_OPERAND); @@ -90,6 +118,13 @@ static void g_armv7_coproc_operand_class_init(GArmV7CoprocOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_coproc_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_coproc_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_coproc_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)NULL; + operand->define_template = (define_operand_template_fc)g_armv7_coproc_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_coproc_operand_compare; operand->print = (operand_print_fc)g_armv7_coproc_operand_print; } @@ -153,25 +188,44 @@ static void g_armv7_coproc_operand_finalize(GArmV7CoprocOperand *operand) /****************************************************************************** * * -* Paramètres : raw = valeur brute du co-processeur à considérer. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Crée une représentation d'un co-processeur ARM. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Opérande mis en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_coproc_operand_new(uint8_t raw) +static void g_armv7_coproc_operand_define_template(const GArmV7CoprocOperand *operand, GArmV7CoprocOperand *template) { - GArmV7CoprocOperand *result; /* Structure à retourner */ + template->index = operand->index; - result = g_object_new(G_TYPE_ARMV7_COPROC_OPERAND, NULL); +} - result->index = raw; - return G_ARCH_OPERAND(result); +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_coproc_operand_compare(const GArmV7CoprocOperand *a, const GArmV7CoprocOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = sort_unsigned_long(a->index, b->index); + + return result; } @@ -204,6 +258,32 @@ static void g_armv7_coproc_operand_print(const GArmV7CoprocOperand *operand, GBu /****************************************************************************** * * +* Paramètres : raw = valeur brute du co-processeur à considérer. * +* * +* Description : Crée une représentation d'un co-processeur ARM. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_coproc_operand_new(uint8_t raw) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7CoprocOperand template; /* Transport d'informations */ + + template.index = raw; + + result = g_share_manager_build(_armv7_coproc_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Fournit l'indice d'un co-processeur ARM. * @@ -219,3 +299,88 @@ uint8_t g_armv7_coproc_operand_get_index(const GArmV7CoprocOperand *operand) return operand->index; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_coproc_operand_share_manager(void) +{ + return _armv7_coproc_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des co-processeurs. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_coproc_operand_sharing(void) +{ + _armv7_coproc_operand_manager = g_share_manager_new(G_TYPE_ARMV7_COPROC_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_coproc_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_coproc_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des co-processeurs. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_coproc_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_coproc_operand_manager)); + +} diff --git a/src/arch/arm/v7/operands/coproc.h b/src/arch/arm/v7/operands/coproc.h index 07224d3..241db19 100644 --- a/src/arch/arm/v7/operands/coproc.h +++ b/src/arch/arm/v7/operands/coproc.h @@ -32,6 +32,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_COPROC_OPERAND g_armv7_coproc_operand_get_type() #define G_ARMV7_COPROC_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_coproc_operand_get_type(), GArmV7CoprocOperand)) #define G_IS_ARMV7_COPROC_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_coproc_operand_get_type())) @@ -58,4 +61,20 @@ uint8_t g_armv7_coproc_operand_get_index(const GArmV7CoprocOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des co-processeurs. */ +bool init_armv7_coproc_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_coproc_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des co-processeurs. */ +void exit_armv7_coproc_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_COPROC_H */ diff --git a/src/arch/arm/v7/operands/estate.c b/src/arch/arm/v7/operands/estate.c index 32c873b..25c60ab 100644 --- a/src/arch/arm/v7/operands/estate.c +++ b/src/arch/arm/v7/operands/estate.c @@ -25,9 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande affichant le choix d'un boutisme (instance) */ struct _GArmV7EndianOperand { @@ -58,11 +63,34 @@ static void g_armv7_endian_operand_dispose(GArmV7EndianOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_endian_operand_finalize(GArmV7EndianOperand *); +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_endian_operand_define_template(const GArmV7EndianOperand *, GArmV7EndianOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_endian_operand_compare(const GArmV7EndianOperand *, const GArmV7EndianOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_endian_operand_print(const GArmV7EndianOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_endian_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_endian_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour une endian de domaine et d'accès. */ G_DEFINE_TYPE(GArmV7EndianOperand, g_armv7_endian_operand, G_TYPE_ARCH_OPERAND); @@ -90,6 +118,13 @@ static void g_armv7_endian_operand_class_init(GArmV7EndianOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_endian_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_endian_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_endian_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)NULL; + operand->define_template = (define_operand_template_fc)g_armv7_endian_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_endian_operand_compare; operand->print = (operand_print_fc)g_armv7_endian_operand_print; } @@ -153,25 +188,44 @@ static void g_armv7_endian_operand_finalize(GArmV7EndianOperand *operand) /****************************************************************************** * * -* Paramètres : big = indication sur le boutisme à représenter. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Crée une représentation de boutisme ARMv7. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Opérande mis en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_endian_operand_new(bool big) +static void g_armv7_endian_operand_define_template(const GArmV7EndianOperand *operand, GArmV7EndianOperand *template) { - GArmV7EndianOperand *result; /* Structure à retourner */ + template->big = operand->big; - result = g_object_new(G_TYPE_ARMV7_ENDIAN_OPERAND, NULL); +} - result->big = big; - return G_ARCH_OPERAND(result); +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_endian_operand_compare(const GArmV7EndianOperand *a, const GArmV7EndianOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = sort_boolean(a->big, b->big); + + return result; } @@ -202,6 +256,32 @@ static void g_armv7_endian_operand_print(const GArmV7EndianOperand *operand, GBu /****************************************************************************** * * +* Paramètres : big = indication sur le boutisme à représenter. * +* * +* Description : Crée une représentation de boutisme ARMv7. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_endian_operand_new(bool big) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7EndianOperand template; /* Transport d'informations */ + + template.big = big; + + result = g_share_manager_build(_armv7_endian_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Indique le type de boutisme représenté. * @@ -217,3 +297,88 @@ bool g_armv7_endian_operand_is_big_endian(const GArmV7EndianOperand *operand) return operand->big; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_endian_operand_share_manager(void) +{ + return _armv7_endian_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des états de boutisme.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_endian_operand_sharing(void) +{ + _armv7_endian_operand_manager = g_share_manager_new(G_TYPE_ARMV7_ENDIAN_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_endian_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_endian_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des états de boutisme. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_endian_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_endian_operand_manager)); + +} diff --git a/src/arch/arm/v7/operands/estate.h b/src/arch/arm/v7/operands/estate.h index a1726cf..506bcb4 100644 --- a/src/arch/arm/v7/operands/estate.h +++ b/src/arch/arm/v7/operands/estate.h @@ -32,6 +32,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_ENDIAN_OPERAND g_armv7_endian_operand_get_type() #define G_ARMV7_ENDIAN_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_endian_operand_get_type(), GArmV7EndianOperand)) #define G_IS_ARMV7_ENDIAN_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_endian_operand_get_type())) @@ -58,4 +61,20 @@ bool g_armv7_endian_operand_is_big_endian(const GArmV7EndianOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des états de boutisme. */ +bool init_armv7_endian_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_endian_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des états de boutisme. */ +void exit_armv7_endian_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_ESTATE_H */ diff --git a/src/arch/arm/v7/operands/limitation.c b/src/arch/arm/v7/operands/limitation.c index 3684167..a86502c 100644 --- a/src/arch/arm/v7/operands/limitation.c +++ b/src/arch/arm/v7/operands/limitation.c @@ -25,9 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande déterminant une limitation de domaine et d'accès (instance) */ struct _GArmV7LimitationOperand { @@ -58,11 +63,34 @@ static void g_armv7_limitation_operand_dispose(GArmV7LimitationOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_limitation_operand_finalize(GArmV7LimitationOperand *); +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_limitation_operand_define_template(const GArmV7LimitationOperand *, GArmV7LimitationOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *, const GArmV7LimitationOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_limitation_operand_print(const GArmV7LimitationOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_limitation_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_limitation_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour une limitation de domaine et d'accès. */ G_DEFINE_TYPE(GArmV7LimitationOperand, g_armv7_limitation_operand, G_TYPE_ARCH_OPERAND); @@ -90,6 +118,13 @@ static void g_armv7_limitation_operand_class_init(GArmV7LimitationOperandClass * object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_limitation_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_limitation_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_limitation_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)NULL; + operand->define_template = (define_operand_template_fc)g_armv7_limitation_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_limitation_operand_compare; operand->print = (operand_print_fc)g_armv7_limitation_operand_print; } @@ -153,29 +188,44 @@ static void g_armv7_limitation_operand_finalize(GArmV7LimitationOperand *operand /****************************************************************************** * * -* Paramètres : raw = valeur brute de la limitation à considérer. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Crée une représentation d'une limitation pour barrière. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Opérande mis en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_limitation_operand_new(uint8_t raw) +static void g_armv7_limitation_operand_define_template(const GArmV7LimitationOperand *operand, GArmV7LimitationOperand *template) { - GArmV7LimitationOperand *result; /* Structure à retourner */ + template->type = operand->type; - result = g_object_new(G_TYPE_ARMV7_LIMITATION_OPERAND, NULL); +} - if (raw < 0b0010 || raw > 0b1111) - result->type = BLT_RESERVED; - else - result->type = raw; +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ - return G_ARCH_OPERAND(result); +static int g_armv7_limitation_operand_compare(const GArmV7LimitationOperand *a, const GArmV7LimitationOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = sort_unsigned_long(a->type, b->type); + + return result; } @@ -241,6 +291,36 @@ static void g_armv7_limitation_operand_print(const GArmV7LimitationOperand *oper /****************************************************************************** * * +* Paramètres : raw = valeur brute de la limitation à considérer. * +* * +* Description : Crée une représentation d'une limitation pour barrière. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_limitation_operand_new(uint8_t raw) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7LimitationOperand template; /* Transport d'informations */ + + if (raw < 0b0010 || raw > 0b1111) + template.type = BLT_RESERVED; + + else + template.type = raw; + + result = g_share_manager_build(_armv7_limitation_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Indique le type de limitation représentée. * @@ -256,3 +336,88 @@ BarrierLimitationType g_armv7_limitation_operand_get_value(const GArmV7Limitatio return operand->type; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_limitation_operand_share_manager(void) +{ + return _armv7_limitation_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage de limites de domaine.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_limitation_operand_sharing(void) +{ + _armv7_limitation_operand_manager = g_share_manager_new(G_TYPE_ARMV7_LIMITATION_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_limitation_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_limitation_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des limites de domaine. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_limitation_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_limitation_operand_manager)); + +} diff --git a/src/arch/arm/v7/operands/limitation.h b/src/arch/arm/v7/operands/limitation.h index 4f7db88..6fc61d2 100644 --- a/src/arch/arm/v7/operands/limitation.h +++ b/src/arch/arm/v7/operands/limitation.h @@ -32,6 +32,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_LIMITATION_OPERAND g_armv7_limitation_operand_get_type() #define G_ARMV7_LIMITATION_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_limitation_operand_get_type(), GArmV7LimitationOperand)) #define G_IS_ARMV7_LIMITATION_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_limitation_operand_get_type())) @@ -74,4 +77,20 @@ BarrierLimitationType g_armv7_limitation_operand_get_value(const GArmV7Limitatio +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage de limites de domaine. */ +bool init_armv7_limitation_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_limitation_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des limites de domaine. */ +void exit_armv7_limitation_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_LIMITATION_H */ diff --git a/src/arch/arm/v7/operands/maccess.c b/src/arch/arm/v7/operands/maccess.c index eeb80c4..71d55e0 100644 --- a/src/arch/arm/v7/operands/maccess.c +++ b/src/arch/arm/v7/operands/maccess.c @@ -25,9 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande offrant un accès à la mémoire depuis une base (instance) */ struct _GArmV7MAccessOperand { @@ -62,11 +67,37 @@ static void g_armv7_maccess_operand_dispose(GArmV7MAccessOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_maccess_operand_finalize(GArmV7MAccessOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_armv7_maccess_operand_apply_template(GArmV7MAccessOperand *, const GArmV7MAccessOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_maccess_operand_define_template(const GArmV7MAccessOperand *, GArmV7MAccessOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *, const GArmV7MAccessOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_maccess_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_maccess_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour un accès à la mémoire depuis une base. */ G_DEFINE_TYPE(GArmV7MAccessOperand, g_armv7_maccess_operand, G_TYPE_ARCH_OPERAND); @@ -94,6 +125,13 @@ static void g_armv7_maccess_operand_class_init(GArmV7MAccessOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_maccess_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_maccess_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_maccess_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_armv7_maccess_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_armv7_maccess_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_maccess_operand_compare; operand->print = (operand_print_fc)g_armv7_maccess_operand_print; } @@ -165,34 +203,93 @@ static void g_armv7_maccess_operand_finalize(GArmV7MAccessOperand *operand) /****************************************************************************** * * -* Paramètres : base = représente le registre de la base d'accès. * -* offset = détermine le décallage entre l'adresse et la base. * -* shift = opération de décallage pour jouer sur le décallage.* -* indexed = précise la forme donnée au décallage à appliquer. * -* wback = indique une mise à jour de la base après usage. * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un accès à la mémoire depuis une base et un décallage. * +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_maccess_operand_new(GArchOperand *base, GArchOperand *offset, GArchOperand *shift, bool indexed, bool wback) +static bool g_armv7_maccess_operand_apply_template(GArmV7MAccessOperand *operand, const GArmV7MAccessOperand *template) { - GArmV7MAccessOperand *result; /* Structure à retourner */ + g_armv7_maccess_operand_define_template(template, operand); - result = g_object_new(G_TYPE_ARMV7_MACCESS_OPERAND, NULL); + g_object_ref(G_OBJECT(operand->base)); - result->base = base; - result->offset = offset; - result->shift = shift; + if (operand->offset != NULL) + g_object_ref(G_OBJECT(operand->offset)); - result->not_post_indexed = indexed; - result->write_back = wback; + if (operand->shift != NULL) + g_object_ref(G_OBJECT(operand->shift)); - return G_ARCH_OPERAND(result); + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_maccess_operand_define_template(const GArmV7MAccessOperand *operand, GArmV7MAccessOperand *template) +{ + template->base = operand->base; + template->offset = operand->offset; + template->shift = operand->shift; + + template->not_post_indexed = operand->not_post_indexed; + template->write_back = operand->write_back; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_maccess_operand_compare(const GArmV7MAccessOperand *a, const GArmV7MAccessOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = g_arch_operand_compare(a->base, b->base); + if (result != 0) goto gamoc_done; + + result = sort_pointer(a->offset, b->offset, (__compar_fn_t)g_arch_operand_compare); + if (result != 0) goto gamoc_done; + + result = sort_pointer(a->shift, b->shift, (__compar_fn_t)g_arch_operand_compare); + if (result != 0) goto gamoc_done; + + result = sort_boolean(a->not_post_indexed, b->not_post_indexed); + if (result != 0) goto gamoc_done; + + result = sort_boolean(a->write_back, b->write_back); + + gamoc_done: + + return result; } @@ -249,6 +346,41 @@ static void g_armv7_maccess_operand_print(const GArmV7MAccessOperand *operand, G /****************************************************************************** * * +* Paramètres : base = représente le registre de la base d'accès. * +* offset = détermine le décallage entre l'adresse et la base. * +* shift = opération de décallage pour jouer sur le décallage.* +* indexed = précise la forme donnée au décallage à appliquer. * +* wback = indique une mise à jour de la base après usage. * +* * +* Description : Crée un accès à la mémoire depuis une base et un décallage. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_maccess_operand_new(GArchOperand *base, GArchOperand *offset, GArchOperand *shift, bool indexed, bool wback) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7MAccessOperand template; /* Transport d'informations */ + + template.base = base; + template.offset = offset; + template.shift = shift; + + template.not_post_indexed = indexed; + template.write_back = wback; + + result = g_share_manager_build(_armv7_maccess_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Founit la base d'un accès à la mémoire. * @@ -340,3 +472,88 @@ bool g_armv7_maccess_operand_has_to_write_back(const GArmV7MAccessOperand *opera return operand->write_back; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_maccess_operand_share_manager(void) +{ + return _armv7_maccess_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des accès mémmoire. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_maccess_operand_sharing(void) +{ + _armv7_maccess_operand_manager = g_share_manager_new(G_TYPE_ARMV7_MACCESS_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_maccess_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_maccess_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des accès mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_maccess_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_maccess_operand_manager)); + +} diff --git a/src/arch/arm/v7/operands/maccess.h b/src/arch/arm/v7/operands/maccess.h index 6e99e0b..52f297d 100644 --- a/src/arch/arm/v7/operands/maccess.h +++ b/src/arch/arm/v7/operands/maccess.h @@ -34,6 +34,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_MACCESS_OPERAND g_armv7_maccess_operand_get_type() #define G_ARMV7_MACCESS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_maccess_operand_get_type(), GArmV7MAccessOperand)) #define G_IS_ARMV7_MACCESS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_maccess_operand_get_type())) @@ -72,4 +75,20 @@ bool g_armv7_maccess_operand_has_to_write_back(const GArmV7MAccessOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des accès mémmoire. */ +bool init_armv7_maccess_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_maccess_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des accès mémoire. */ +void exit_armv7_maccess_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_MACCESS_H */ diff --git a/src/arch/arm/v7/operands/offset.c b/src/arch/arm/v7/operands/offset.c index 9368faf..ebd73c8 100644 --- a/src/arch/arm/v7/operands/offset.c +++ b/src/arch/arm/v7/operands/offset.c @@ -25,9 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande visant à constituer un décallage relatif ARMv7 (instance) */ struct _GArmV7OffsetOperand { @@ -59,11 +64,37 @@ static void g_armv7_offset_operand_dispose(GArmV7OffsetOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_armv7_offset_operand_apply_template(GArmV7OffsetOperand *, const GArmV7OffsetOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_offset_operand_define_template(const GArmV7OffsetOperand *, GArmV7OffsetOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *, const GArmV7OffsetOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_offset_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_offset_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour un décallage relatif ARMv7. */ G_DEFINE_TYPE(GArmV7OffsetOperand, g_armv7_offset_operand, G_TYPE_ARCH_OPERAND); @@ -91,6 +122,13 @@ static void g_armv7_offset_operand_class_init(GArmV7OffsetOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_offset_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_offset_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_offset_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_armv7_offset_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_armv7_offset_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_offset_operand_compare; operand->print = (operand_print_fc)g_armv7_offset_operand_print; } @@ -156,27 +194,75 @@ static void g_armv7_offset_operand_finalize(GArmV7OffsetOperand *operand) /****************************************************************************** * * -* Paramètres : positive = indique si la quantité doit être ajoutée ou non. * -* value = valeur du décallage à appliquer. * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un décallage selon un sens et une valeur donnés. * +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value) +static bool g_armv7_offset_operand_apply_template(GArmV7OffsetOperand *operand, const GArmV7OffsetOperand *template) { - GArmV7OffsetOperand *result; /* Structure à retourner */ + g_armv7_offset_operand_define_template(template, operand); - result = g_object_new(G_TYPE_ARMV7_OFFSET_OPERAND, NULL); + g_object_ref(G_OBJECT(operand->value)); - result->positive = positive; - result->value = value; + return true; - return G_ARCH_OPERAND(result); +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_offset_operand_define_template(const GArmV7OffsetOperand *operand, GArmV7OffsetOperand *template) +{ + template->positive = operand->positive; + + template->value = operand->value; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_offset_operand_compare(const GArmV7OffsetOperand *a, const GArmV7OffsetOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = sort_boolean(a->positive, b->positive); + if (result != 0) goto gaooc_done; + + result = g_arch_operand_compare(a->value, b->value); + + gaooc_done: + + return result; } @@ -207,6 +293,34 @@ static void g_armv7_offset_operand_print(const GArmV7OffsetOperand *operand, GBu /****************************************************************************** * * +* Paramètres : positive = indique si la quantité doit être ajoutée ou non. * +* value = valeur du décallage à appliquer. * +* * +* Description : Crée un décallage selon un sens et une valeur donnés. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_offset_operand_new(bool positive, GArchOperand *value) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7OffsetOperand template; /* Transport d'informations */ + + template.positive = positive; + template.value = value; + + result = g_share_manager_build(_armv7_offset_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Indique le sens du décallage représenté. * @@ -238,6 +352,97 @@ bool g_armv7_offset_operand_is_positive(const GArmV7OffsetOperand *operand) GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *operand) { - return operand->value; + GArchOperand *result; /* Instance à retourner */ + + result = operand->value; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_offset_operand_share_manager(void) +{ + return _armv7_offset_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des décallages ARMv7. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_offset_operand_sharing(void) +{ + _armv7_offset_operand_manager = g_share_manager_new(G_TYPE_ARMV7_OFFSET_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_offset_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_offset_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des décallages ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_offset_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_offset_operand_manager)); } diff --git a/src/arch/arm/v7/operands/offset.h b/src/arch/arm/v7/operands/offset.h index 64744df..b1e1ddc 100644 --- a/src/arch/arm/v7/operands/offset.h +++ b/src/arch/arm/v7/operands/offset.h @@ -34,6 +34,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_OFFSET_OPERAND g_armv7_offset_operand_get_type() #define G_ARMV7_OFFSET_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_offset_operand_get_type(), GArmV7OffsetOperand)) #define G_IS_ARMV7_OFFSET_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_offset_operand_get_type())) @@ -63,4 +66,20 @@ GArchOperand *g_armv7_offset_operand_get_value(const GArmV7OffsetOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des décallages ARMv7. */ +bool init_armv7_offset_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_offset_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des décallages ARMv7. */ +void exit_armv7_offset_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_OFFSET_H */ diff --git a/src/arch/arm/v7/operands/reglist.c b/src/arch/arm/v7/operands/reglist.c index cfbc6ab..968a423 100644 --- a/src/arch/arm/v7/operands/reglist.c +++ b/src/arch/arm/v7/operands/reglist.c @@ -30,9 +30,14 @@ #include "../../../operand-int.h" #include "../../../register.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + /* Définition d'un opérande listant une série de registres ARM (instance) */ struct _GArmV7RegListOperand { @@ -64,11 +69,40 @@ static void g_armv7_reglist_operand_dispose(GArmV7RegListOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_reglist_operand_finalize(GArmV7RegListOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_armv7_reglist_operand_apply_template(GArmV7RegListOperand *, const GArmV7RegListOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_reglist_operand_define_template(const GArmV7RegListOperand *, GArmV7RegListOperand *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +static void g_armv7_reglist_operand_free_template(const GArmV7RegListOperand *, GArmV7RegListOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *, const GArmV7RegListOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_reglist_operand_print(const GArmV7RegListOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_reglist_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_reglist_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini par la GLib pour une liste de registres ARM. */ G_DEFINE_TYPE(GArmV7RegListOperand, g_armv7_reglist_operand, G_TYPE_ARCH_OPERAND); @@ -96,6 +130,13 @@ static void g_armv7_reglist_operand_class_init(GArmV7RegListOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_reglist_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_reglist_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_reglist_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_armv7_reglist_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_armv7_reglist_operand_define_template; + operand->free_template = (free_operand_template_fc)g_armv7_reglist_operand_free_template;; + + operand->compare = (operand_compare_fc)g_armv7_reglist_operand_compare; operand->print = (operand_print_fc)g_armv7_reglist_operand_print; } @@ -167,23 +208,131 @@ static void g_armv7_reglist_operand_finalize(GArmV7RegListOperand *operand) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée une liste vierge de registres ARM. * +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_reglist_operand_new(void) +static bool g_armv7_reglist_operand_apply_template(GArmV7RegListOperand *operand, const GArmV7RegListOperand *template) { - GArmV7RegListOperand *result; /* Structure à retourner */ + size_t i; /* Boucle de parcours */ - result = g_object_new(G_TYPE_ARMV7_REGLIST_OPERAND, NULL); + g_armv7_reglist_operand_define_template(template, operand); - return G_ARCH_OPERAND(result); + for (i = 0; i < operand->count; i++) + g_object_ref(G_OBJECT(operand->registers[i])); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_reglist_operand_define_template(const GArmV7RegListOperand *operand, GArmV7RegListOperand *template) +{ + size_t i; /* Boucle de parcours */ + + if (operand != NULL) + template->count = operand->count; + else + template->count = 0; + + if (template->count == 0) + template->registers = NULL; + + else + { + template->registers = (GArmV7Register **)malloc(template->count * sizeof(GArmV7Register *)); + + for (i = 0; i < template->count; i++) + template->registers[i] = operand->registers[i]; + + } + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations dont le contenu est à libérer. * +* * +* Description : Libère la mémoire utilisée par un patron d'instance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_reglist_operand_free_template(const GArmV7RegListOperand *operand, GArmV7RegListOperand *template) +{ + if (template->registers != NULL) + free(template->registers); + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_reglist_operand_compare(const GArmV7RegListOperand *a, const GArmV7RegListOperand *b) +{ + int result; /* Bilan à faire remonter */ + size_t i; /* Boucle de parcours */ + GArchRegister *ra; /* Registre de la liste A */ + GArchRegister *rb; /* Registre de la liste B */ + + /* Création de l'objet... */ + if (b == NULL) + { + result = 1; + goto garoc_done; + } + + result = sort_unsigned_long(a->count, b->count); + if (result != 0) goto garoc_done; + + for (i = 0; i < a->count && result == 0; i++) + { + ra = G_ARCH_REGISTER(a->registers[i]); + rb = G_ARCH_REGISTER(b->registers[i]); + + result = g_arch_register_compare(ra, rb); + + } + + garoc_done: + + return result; } @@ -227,6 +376,29 @@ static void g_armv7_reglist_operand_print(const GArmV7RegListOperand *operand, G /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Crée une liste vierge de registres ARM. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_reglist_operand_new(void) +{ + GSharedInstance *result; /* Structure à retourner */ + + result = g_share_manager_build(_armv7_reglist_operand_manager, NULL); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = liste de registres à compléter. * * selected = masque de bits pour les registres à intégrer. * * * @@ -323,3 +495,88 @@ GArmV7Register *g_armv7_reglist_operand_get_register(const GArmV7RegListOperand return operand->registers[index]; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_reglist_operand_share_manager(void) +{ + return _armv7_reglist_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage de listes de reg. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_reglist_operand_sharing(void) +{ + _armv7_reglist_operand_manager = g_share_manager_new(G_TYPE_ARMV7_REGLIST_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_reglist_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_reglist_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des listes de registres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_reglist_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_reglist_operand_manager)); + +} diff --git a/src/arch/arm/v7/operands/reglist.h b/src/arch/arm/v7/operands/reglist.h index 7c60805..497c852 100644 --- a/src/arch/arm/v7/operands/reglist.h +++ b/src/arch/arm/v7/operands/reglist.h @@ -34,6 +34,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_REGLIST_OPERAND g_armv7_reglist_operand_get_type() #define G_ARMV7_REGLIST_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_reglist_operand_get_type(), GArmV7RegListOperand)) #define G_IS_ARMV7_REGLIST_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_reglist_operand_get_type())) @@ -69,4 +72,20 @@ GArmV7Register *g_armv7_reglist_operand_get_register(const GArmV7RegListOperand +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage de listes de registres. */ +bool init_armv7_reglist_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_reglist_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des listes de registres. */ +void exit_armv7_reglist_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_REGLIST_H */ diff --git a/src/arch/arm/v7/operands/rotation.c b/src/arch/arm/v7/operands/rotation.c index 5733aa2..be89cd5 100644 --- a/src/arch/arm/v7/operands/rotation.c +++ b/src/arch/arm/v7/operands/rotation.c @@ -25,10 +25,14 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + +/* Définition d'un opérande visant une opérande de rotation ARMv7 (instance) */ struct _GArmV7RotationOperand { GArchOperand parent; /* Instance parente */ @@ -38,7 +42,7 @@ struct _GArmV7RotationOperand }; -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +/* Définition d'un opérande visant une opérande de rotation ARMv7 (classe) */ struct _GArmV7RotationOperandClass { GArchOperandClass parent; /* Classe parente */ @@ -46,10 +50,10 @@ struct _GArmV7RotationOperandClass }; -/* Initialise la classe des listes d'opérandes Dalvik. */ +/* Initialise la classe des opérandes de rotation ARMv7. */ static void g_armv7_rotation_operand_class_init(GArmV7RotationOperandClass *); -/* Initialise une instance de liste d'opérandes Dalvik. */ +/* Initialise une instance d'opérande de rotation ARMv7. */ static void g_armv7_rotation_operand_init(GArmV7RotationOperand *); /* Supprime toutes les références externes. */ @@ -58,12 +62,38 @@ static void g_armv7_rotation_operand_dispose(GArmV7RotationOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_rotation_operand_finalize(GArmV7RotationOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_armv7_rotation_operand_apply_template(GArmV7RotationOperand *, const GArmV7RotationOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_rotation_operand_define_template(const GArmV7RotationOperand *, GArmV7RotationOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_rotation_operand_compare(const GArmV7RotationOperand *, const GArmV7RotationOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_rotation_operand_print(const GArmV7RotationOperand *, GBufferLine *, AsmSyntax); -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_rotation_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_rotation_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini par la GLib pour une opérande de rotation ARMv7. */ G_DEFINE_TYPE(GArmV7RotationOperand, g_armv7_rotation_operand, G_TYPE_ARCH_OPERAND); @@ -71,7 +101,7 @@ G_DEFINE_TYPE(GArmV7RotationOperand, g_armv7_rotation_operand, G_TYPE_ARCH_OPERA * * * Paramètres : klass = classe à initialiser. * * * -* Description : Initialise la classe des listes d'opérandes Dalvik. * +* Description : Initialise la classe des opérandes de rotation ARMv7. * * * * Retour : - * * * @@ -90,6 +120,13 @@ static void g_armv7_rotation_operand_class_init(GArmV7RotationOperandClass *klas object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_rotation_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_rotation_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_rotation_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_armv7_rotation_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_armv7_rotation_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_rotation_operand_compare; operand->print = (operand_print_fc)g_armv7_rotation_operand_print; } @@ -99,7 +136,7 @@ static void g_armv7_rotation_operand_class_init(GArmV7RotationOperandClass *klas * * * Paramètres : operand = instance à initialiser. * * * -* Description : Initialise une instance de liste d'opérandes Dalvik. * +* Description : Initialise une instance d'opérande de rotation ARMv7. * * * * Retour : - * * * @@ -155,25 +192,68 @@ static void g_armv7_rotation_operand_finalize(GArmV7RotationOperand *operand) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_rotation_operand_new(GArchOperand *value) +static bool g_armv7_rotation_operand_apply_template(GArmV7RotationOperand *operand, const GArmV7RotationOperand *template) { - GArmV7RotationOperand *result; /* Structure à retourner */ + g_armv7_rotation_operand_define_template(template, operand); - result = g_object_new(G_TYPE_ARMV7_ROTATION_OPERAND, NULL); + g_object_ref(G_OBJECT(operand->value)); - result->value = value; + return true; - return G_ARCH_OPERAND(result); +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_rotation_operand_define_template(const GArmV7RotationOperand *operand, GArmV7RotationOperand *template) +{ + template->value = operand->value; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_rotation_operand_compare(const GArmV7RotationOperand *a, const GArmV7RotationOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = g_arch_operand_compare(a->value, b->value); + + return result; } @@ -205,9 +285,35 @@ static void g_armv7_rotation_operand_print(const GArmV7RotationOperand *operand, /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Crée un réceptacle pour opérandes de rotation ARMv7. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_rotation_operand_new(GArchOperand *value) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7RotationOperand template; /* Transport d'informations */ + + template.value = value; + + result = g_share_manager_build(_armv7_rotation_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * -* Description : Founit la valeur utilisée pour un décallage. * +* Description : Founit la valeur utilisée pour une rotation. * * * * Retour : Opérande en place. * * * @@ -217,6 +323,97 @@ static void g_armv7_rotation_operand_print(const GArmV7RotationOperand *operand, GArchOperand *g_armv7_rotation_operand_get_value(const GArmV7RotationOperand *operand) { - return operand->value; + GArchOperand *result; /* Instance à retourner */ + + result = operand->value; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_rotation_operand_share_manager(void) +{ + return _armv7_rotation_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des rotation ARMv7. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_rotation_operand_sharing(void) +{ + _armv7_rotation_operand_manager = g_share_manager_new(G_TYPE_ARMV7_ROTATION_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_rotation_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_rotation_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des opérandes de rotation.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_rotation_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_rotation_operand_manager)); } diff --git a/src/arch/arm/v7/operands/rotation.h b/src/arch/arm/v7/operands/rotation.h index e42b219..399baf4 100644 --- a/src/arch/arm/v7/operands/rotation.h +++ b/src/arch/arm/v7/operands/rotation.h @@ -40,22 +40,38 @@ #define G_ARMV7_ROTATION_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARMV7_ROTATION_OPERAND, GArmV7RotationOperandClass)) -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +/* Définition d'un opérande visant une opérande de rotation ARMv7 (instance) */ typedef struct _GArmV7RotationOperand GArmV7RotationOperand; -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +/* Définition d'un opérande visant une opérande de rotation ARMv7 (classe) */ typedef struct _GArmV7RotationOperandClass GArmV7RotationOperandClass; -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +/* Indique le type défini par la GLib pour une opérande de rotation ARMv7. */ GType g_armv7_rotation_operand_get_type(void); -/* Crée un réceptacle pour opérandes Dalvik servant d'arguments. */ +/* Crée un réceptacle pour opérandes de rotation ARMv7. */ GArchOperand *g_armv7_rotation_operand_new(GArchOperand *); -/* Founit la valeur utilisée pour un décallage. */ +/* Founit la valeur utilisée pour une rotation. */ GArchOperand *g_armv7_rotation_operand_get_value(const GArmV7RotationOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des rotation ARMv7. */ +bool init_armv7_rotation_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_rotation_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des opérandes de rotation. */ +void exit_armv7_rotation_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_ROTATION_H */ diff --git a/src/arch/arm/v7/operands/shift.c b/src/arch/arm/v7/operands/shift.c index 8797c3d..3a37e81 100644 --- a/src/arch/arm/v7/operands/shift.c +++ b/src/arch/arm/v7/operands/shift.c @@ -25,10 +25,15 @@ #include "../../../operand-int.h" +#include "../../../sharing/manager.h" +#include "../../../../common/sort.h" -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + +/* Définition d'un opérande visant une opérande de décallage ARMv7 (instance) */ struct _GArmV7ShiftOperand { GArchOperand parent; /* Instance parente */ @@ -39,7 +44,7 @@ struct _GArmV7ShiftOperand }; -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +/* Définition d'un opérande visant une opérande de décallage ARMv7 (classe) */ struct _GArmV7ShiftOperandClass { GArchOperandClass parent; /* Classe parente */ @@ -47,10 +52,10 @@ struct _GArmV7ShiftOperandClass }; -/* Initialise la classe des listes d'opérandes Dalvik. */ +/* Initialise la classe des opérandes de décallage ARMv7. */ static void g_armv7_shift_operand_class_init(GArmV7ShiftOperandClass *); -/* Initialise une instance de liste d'opérandes Dalvik. */ +/* Initialise une instance d'opérande de décallage ARMv7. */ static void g_armv7_shift_operand_init(GArmV7ShiftOperand *); /* Supprime toutes les références externes. */ @@ -59,12 +64,38 @@ static void g_armv7_shift_operand_dispose(GArmV7ShiftOperand *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_shift_operand_finalize(GArmV7ShiftOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_armv7_shift_operand_apply_template(GArmV7ShiftOperand *, const GArmV7ShiftOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_shift_operand_define_template(const GArmV7ShiftOperand *, GArmV7ShiftOperand *); + +/* Compare un opérande avec un autre. */ +static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *, const GArmV7ShiftOperand *); + /* Traduit un opérande en version humainement lisible. */ static void g_armv7_shift_operand_print(const GArmV7ShiftOperand *, GBufferLine *, AsmSyntax); -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_shift_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_shift_operand_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION D'OPERANDES INDIVIDUELLES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini par la GLib pour une opérande de décallage ARMv7. */ G_DEFINE_TYPE(GArmV7ShiftOperand, g_armv7_shift_operand, G_TYPE_ARCH_OPERAND); @@ -72,7 +103,7 @@ G_DEFINE_TYPE(GArmV7ShiftOperand, g_armv7_shift_operand, G_TYPE_ARCH_OPERAND); * * * Paramètres : klass = classe à initialiser. * * * -* Description : Initialise la classe des listes d'opérandes Dalvik. * +* Description : Initialise la classe des opérandes de décallage ARMv7. * * * * Retour : - * * * @@ -91,6 +122,13 @@ static void g_armv7_shift_operand_class_init(GArmV7ShiftOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_shift_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_armv7_shift_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_armv7_shift_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_armv7_shift_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_armv7_shift_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + + operand->compare = (operand_compare_fc)g_armv7_shift_operand_compare; operand->print = (operand_print_fc)g_armv7_shift_operand_print; } @@ -100,7 +138,7 @@ static void g_armv7_shift_operand_class_init(GArmV7ShiftOperandClass *klass) * * * Paramètres : operand = instance à initialiser. * * * -* Description : Initialise une instance de liste d'opérandes Dalvik. * +* Description : Initialise une instance d'opérande de décallage ARMv7. * * * * Retour : - * * * @@ -156,26 +194,75 @@ static void g_armv7_shift_operand_finalize(GArmV7ShiftOperand *operand) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_armv7_shift_operand_new(SRType type, GArchOperand *value) +static bool g_armv7_shift_operand_apply_template(GArmV7ShiftOperand *operand, const GArmV7ShiftOperand *template) { - GArmV7ShiftOperand *result; /* Structure à retourner */ + g_armv7_shift_operand_define_template(template, operand); - result = g_object_new(G_TYPE_ARMV7_SHIFT_OPERAND, NULL); + g_object_ref(G_OBJECT(operand->shift_value)); - result->shift_type = type; - result->shift_value = value; + return true; - return G_ARCH_OPERAND(result); +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv7_shift_operand_define_template(const GArmV7ShiftOperand *operand, GArmV7ShiftOperand *template) +{ + template->shift_type = operand->shift_type; + + template->shift_value = operand->shift_value; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_armv7_shift_operand_compare(const GArmV7ShiftOperand *a, const GArmV7ShiftOperand *b) +{ + int result; /* Bilan à faire remonter */ + + result = sort_unsigned_long(a->shift_type, b->shift_type); + if (result != 0) goto gasoc_done; + + result = g_arch_operand_compare(a->shift_value, b->shift_value); + + gasoc_done: + + return result; } @@ -224,6 +311,33 @@ static void g_armv7_shift_operand_print(const GArmV7ShiftOperand *operand, GBuff /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Crée un réceptacle pour opérande de décallage ARMv7. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv7_shift_operand_new(SRType type, GArchOperand *value) +{ + GSharedInstance *result; /* Structure à retourner */ + GArmV7ShiftOperand template; /* Transport d'informations */ + + template.shift_type = type; + template.shift_value = value; + + result = g_share_manager_build(_armv7_shift_operand_manager, (GSharedInstance *)&template); + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Indique la forme de décallage représenté. * @@ -255,6 +369,97 @@ SRType g_armv7_shift_operand_get_shift_type(const GArmV7ShiftOperand *operand) GArchOperand *g_armv7_shift_operand_get_shift_value(const GArmV7ShiftOperand *operand) { - return operand->shift_value; + GArchOperand *result; /* Instance à retourner */ + + result = operand->shift_value; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_shift_operand_share_manager(void) +{ + return _armv7_shift_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des décallages ARMv7. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_shift_operand_sharing(void) +{ + _armv7_shift_operand_manager = g_share_manager_new(G_TYPE_ARMV7_SHIFT_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_shift_operand_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_shift_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des décallages ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_shift_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_shift_operand_manager)); } diff --git a/src/arch/arm/v7/operands/shift.h b/src/arch/arm/v7/operands/shift.h index 3351056..1169946 100644 --- a/src/arch/arm/v7/operands/shift.h +++ b/src/arch/arm/v7/operands/shift.h @@ -33,6 +33,9 @@ +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + + #define G_TYPE_ARMV7_SHIFT_OPERAND g_armv7_shift_operand_get_type() #define G_ARMV7_SHIFT_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_shift_operand_get_type(), GArmV7ShiftOperand)) #define G_IS_ARMV7_SHIFT_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_shift_operand_get_type())) @@ -41,17 +44,17 @@ #define G_ARMV7_SHIFT_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARMV7_SHIFT_OPERAND, GArmV7ShiftOperandClass)) -/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */ +/* Définition d'un opérande visant une opérande de décallage ARMv7 (instance) */ typedef struct _GArmV7ShiftOperand GArmV7ShiftOperand; -/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */ +/* Définition d'un opérande visant une opérande de décallage ARMv7 (classe) */ typedef struct _GArmV7ShiftOperandClass GArmV7ShiftOperandClass; -/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */ +/* Indique le type défini par la GLib pour une opérande de décallage ARMv7. */ GType g_armv7_shift_operand_get_type(void); -/* Crée un réceptacle pour opérandes Dalvik servant d'arguments. */ +/* Crée un réceptacle pour opérande de décallage ARMv7. */ GArchOperand *g_armv7_shift_operand_new(SRType, GArchOperand *); /* Indique la forme de décallage représenté. */ @@ -62,4 +65,20 @@ GArchOperand *g_armv7_shift_operand_get_shift_value(const GArmV7ShiftOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des décallages ARMv7. */ +bool init_armv7_shift_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_shift_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des décallages ARMv7. */ +void exit_armv7_shift_operand_sharing(void); + + + #endif /* _ARCH_ARM_V7_OPERANDS_SHIFT_H */ diff --git a/src/arch/arm/v7/register.c b/src/arch/arm/v7/register.c index 1e76764..7a873b5 100644 --- a/src/arch/arm/v7/register.c +++ b/src/arch/arm/v7/register.c @@ -31,6 +31,9 @@ +/* ------------------------- ENCADREMENT DE REGISTRES BRUTS ------------------------- */ + + /* Représentation d'un registre ARMv7 (instance) */ struct _GArmV7Register { @@ -62,11 +65,31 @@ static void g_armv7_register_dispose(GArmV7Register *); /* Procède à la libération totale de la mémoire. */ static void g_armv7_register_finalize(GArmV7Register *); +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_armv7_register_define_template(const GArmV7Register *, GArmV7Register *); + /* Traduit un registre en version humainement lisible. */ static void g_armv7_register_print(const GArmV7Register *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_armv7_register_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_armv7_register_share_manager(void); + + + +/* ---------------------------------------------------------------------------------- */ +/* ENCADREMENT DE REGISTRES BRUTS */ +/* ---------------------------------------------------------------------------------- */ + + /* Indique le type défini pour une représentation d'un registre ARMv7. */ G_DEFINE_TYPE(GArmV7Register, g_armv7_register, G_TYPE_ARM_REGISTER); @@ -94,6 +117,10 @@ static void g_armv7_register_class_init(GArmV7RegisterClass *klass) object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_register_dispose; object_class->finalize = (GObjectFinalizeFunc)g_armv7_register_finalize; + reg_class->get_manager = (get_register_manager_fc)get_armv7_register_share_manager; + + reg_class->define_template = (define_register_template_fc)g_armv7_register_define_template; + reg_class->print = (reg_print_fc)g_armv7_register_print; } @@ -157,25 +184,26 @@ static void g_armv7_register_finalize(GArmV7Register *reg) /****************************************************************************** * * -* Paramètres : index = indice du registre correspondant. * +* Paramètres : reg = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Crée une réprésentation de registre ARMv7. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Adresse de la structure mise en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GArmV7Register *g_armv7_register_new(uint8_t index) +static void g_armv7_register_define_template(const GArmV7Register *reg, GArmV7Register *template) { - GArmV7Register *result; /* Structure à retourner */ + GArmRegister *areg; /* Version parente #1 */ + GArmRegister *treg; /* Version parente #2 */ - result = g_object_new(G_TYPE_ARMV7_REGISTER, NULL); + areg = (GArmRegister *)reg; + treg = (GArmRegister *)template; - G_ARM_REGISTER(result)->index = index; - - return result; + treg->index = areg->index; } @@ -227,3 +255,114 @@ static void g_armv7_register_print(const GArmV7Register *reg, GBufferLine *line, g_buffer_line_append_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER, NULL); } + + +/****************************************************************************** +* * +* Paramètres : index = indice du registre correspondant. * +* * +* Description : Crée une réprésentation de registre ARMv7. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArmV7Register *g_armv7_register_new(uint8_t index) +{ + GArmV7Register *result; /* Structure à retourner */ + GArmRegister template; /* Transport d'informations */ + + template.index = index; + + result = G_ARMV7_REGISTER(g_share_manager_build(_armv7_register_manager, (GSharedInstance *)&template)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_armv7_register_share_manager(void) +{ + return _armv7_register_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des registres ARMv7. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_armv7_register_sharing(void) +{ + _armv7_register_manager = g_share_manager_new(G_TYPE_ARMV7_REGISTER); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_register_share_stats(void) +{ + g_share_manager_dump_stats(_armv7_register_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des registres ARMv7. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_armv7_register_sharing(void) +{ + g_object_unref(G_OBJECT(_armv7_register_manager)); + +} diff --git a/src/arch/arm/v7/register.h b/src/arch/arm/v7/register.h index de038e2..0408859 100644 --- a/src/arch/arm/v7/register.h +++ b/src/arch/arm/v7/register.h @@ -26,10 +26,14 @@ #include +#include #include +/* ------------------------- ENCADREMENT DE REGISTRES BRUTS ------------------------- */ + + #define G_TYPE_ARMV7_REGISTER g_armv7_register_get_type() #define G_ARMV7_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_armv7_register_get_type(), GArmV7Register)) #define G_IS_ARMV7_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_armv7_register_get_type())) @@ -53,4 +57,20 @@ GArmV7Register *g_armv7_register_new(uint8_t); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des registres ARMv7. */ +bool init_armv7_register_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_armv7_register_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des registres ARMv7. */ +void exit_armv7_register_sharing(void); + + + #endif /* _ARCH_ARM_V7_REGISTER_H */ diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c index 8a687db..2092e6b 100644 --- a/src/arch/dalvik/operands/args.c +++ b/src/arch/dalvik/operands/args.c @@ -69,10 +69,16 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *); static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *, const GDalvikArgsOperand *); +static bool g_dalvik_args_operand_apply_template(GDalvikArgsOperand *, const GDalvikArgsOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_dalvik_args_operand_define_template(const GDalvikArgsOperand *, GDalvikArgsOperand *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +static void g_dalvik_args_operand_free_template(const GDalvikArgsOperand *, GDalvikArgsOperand *); /* Compare un opérande avec un autre. */ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *, const GDalvikArgsOperand * const *); +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *, AsmSyntax); @@ -86,6 +92,10 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine static GShareManager *_dalvik_args_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_dalvik_args_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* MANIPULATION D'OPERANDES INDIVIDUELLES */ @@ -119,7 +129,11 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_args_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_dalvik_args_operand_finalize; - operand->init = (operand_do_init_fc)g_dalvik_args_operand_do_init; + operand->get_manager = (get_operand_manager_fc)get_dalvik_args_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_dalvik_args_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_dalvik_args_operand_define_template; + operand->free_template = (free_operand_template_fc)g_dalvik_args_operand_free_template; operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare; operand->print = (operand_print_fc)g_dalvik_args_operand_print; @@ -190,62 +204,95 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_dalvik_args_operand_new(void) +static bool g_dalvik_args_operand_apply_template(GDalvikArgsOperand *operand, const GDalvikArgsOperand *template) { - GArchOperand *result; /* Structure à retourner */ + size_t i; /* Boucle de parcours */ + + if (template == NULL) + { + operand->args = NULL; + operand->count = 0; + } - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_args_operand_manager, NULL)); + else + { + g_dalvik_args_operand_define_template(template, operand); - return result; + for (i = 0; i < operand->count; i++) + g_object_ref(G_OBJECT(operand->args[i])); + + } + + return true; } /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* fake = coquille vide contenant les infos à enregistrer. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Initialise un nouvel objet partagé avec des informations. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *operand, const GDalvikArgsOperand *fake) +static void g_dalvik_args_operand_define_template(const GDalvikArgsOperand *operand, GDalvikArgsOperand *template) { size_t i; /* Boucle de parcours */ - if (fake == NULL) + if (operand->count == 0) { - operand->args = NULL; - operand->count = 0; + template->args = NULL; + template->count = 0; } else { - operand->args = (GArchOperand **)calloc(fake->count, sizeof(GArchOperand *)); + template->args = (GArchOperand **)calloc(operand->count, sizeof(GArchOperand *)); - for (i = 0; i < fake->count; i++) - operand->args[i] = fake->args[i]; + for (i = 0; i < operand->count; i++) + template->args[i] = operand->args[i]; - operand->count = fake->count; + template->count = operand->count; } - return true; +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations dont le contenu est à libérer. * +* * +* Description : Libère la mémoire utilisée par un patron d'instance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_args_operand_free_template(const GDalvikArgsOperand *operand, GDalvikArgsOperand *template) +{ + if (template != NULL && template->args != NULL) + free(template->args); } @@ -263,26 +310,21 @@ static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *operand, const GDa * * ******************************************************************************/ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *a, const GDalvikArgsOperand * const *b) +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b) { int result; /* Bilan à renvoyer */ - const GDalvikArgsOperand *_a; /* Accès rapide à l'élément A */ - const GDalvikArgsOperand *_b; /* Accès rapide à l'élément B */ size_t i; /* Boucle de parcours */ - _a = *a; - _b = *b; - - if (_b == NULL) - result = sort_unsigned_long(_a->count, 0); + /* Création de l'objet... */ + if (b == NULL) + result = 1; else { - result = sort_unsigned_long(_a->count, _b->count); + result = sort_unsigned_long(a->count, b->count); - for (i = 0; i < _a->count && result == 0; i++) - result = g_arch_operand_compare((const GArchOperand * const *)&_a->args[i], - (const GArchOperand * const *)&_b->args[i]); + for (i = 0; i < a->count && result == 0; i++) + result = g_arch_operand_compare(a->args[i], b->args[i]); } @@ -333,6 +375,29 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *operand, GBuff /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_dalvik_args_operand_new(void) +{ + GArchOperand *result; /* Structure à retourner */ + + result = G_ARCH_OPERAND(g_share_manager_build(_dalvik_args_operand_manager, NULL)); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à compléter. * * arg = nouvel argument pour un appel. * * * @@ -419,6 +484,25 @@ GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_ * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_dalvik_args_operand_share_manager(void) +{ + return _dalvik_args_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Met en place les mécanismes de partage des opérandes Dalvik. * * * * Retour : Bilan de l'opération. * diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c index fa7ed54..d97c93b 100644 --- a/src/arch/dalvik/operands/pool.c +++ b/src/arch/dalvik/operands/pool.c @@ -74,10 +74,13 @@ static void g_dalvik_pool_operand_dispose(GDalvikPoolOperand *); static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *, const GDalvikPoolOperand *); +static bool g_dalvik_pool_operand_apply_template(GDalvikPoolOperand *, const GDalvikPoolOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_dalvik_pool_operand_define_template(const GDalvikPoolOperand *, GDalvikPoolOperand *); /* Compare un opérande avec un autre. */ -static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *, const GDalvikPoolOperand * const *); +static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand *, const GDalvikPoolOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine *, AsmSyntax); @@ -91,6 +94,10 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine static GShareManager *_dalvik_pool_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_dalvik_pool_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* MANIPULATION D'OPERANDES INDIVIDUELLES */ @@ -125,7 +132,11 @@ static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass) operand = G_ARCH_OPERAND_CLASS(klass); - operand->init = (operand_do_init_fc)g_dalvik_pool_operand_do_init; + operand->get_manager = (get_operand_manager_fc)get_dalvik_pool_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_dalvik_pool_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_dalvik_pool_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; operand->compare = (operand_compare_fc)g_dalvik_pool_operand_compare; operand->print = (operand_print_fc)g_dalvik_pool_operand_print; @@ -193,82 +204,47 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *operand) /****************************************************************************** * * -* Paramètres : format = format du fichier contenant le code. * -* type = type de table visée avec la référence. * -* content = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* size = taille de l'opérande, et donc du registre. * -* endian = ordre des bits dans la source. * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un opérande visant un élément constant Dalvik. * +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian) +static bool g_dalvik_pool_operand_apply_template(GDalvikPoolOperand *operand, const GDalvikPoolOperand *template) { - GArchOperand *result; /* Structure à retourner */ - uint8_t index8; /* Indice sur 8 bits */ - uint16_t index16; /* Indice sur 16 bits */ - bool test; /* Bilan de lecture */ - GDalvikPoolOperand fake; /* Transport d'informations */ + g_dalvik_pool_operand_define_template(template, operand); - result = NULL; + g_object_ref(G_OBJECT(operand->format)); - switch (size) - { - case MDS_8_BITS: - test = g_binary_content_read_u8(content, pos, &index8); - break; - case MDS_16_BITS: - test = g_binary_content_read_u16(content, pos, endian, &index16); - break; - default: - test = false; - break; - } - - if (!test) - goto gdpon_exit; - - fake.format = format; - fake.type = type; - fake.index = (size == MDS_8_BITS ? index8 : index16); - - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_pool_operand_manager, (GSharedInstance *)&fake)); - - gdpon_exit: - - return result; + return true; } /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* fake = coquille vide contenant les infos à enregistrer. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Initialise un nouvel objet partagé avec des informations. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDalvikPoolOperand *fake) +static void g_dalvik_pool_operand_define_template(const GDalvikPoolOperand *operand, GDalvikPoolOperand *template) { - operand->format = fake->format; - g_object_ref(G_OBJECT(fake->format)); - - operand->type = fake->type; - operand->index = fake->index; + template->format = operand->format; - return true; + template->type = operand->type; + template->index = operand->index; } @@ -286,22 +262,17 @@ static bool g_dalvik_pool_operand_do_init(GDalvikPoolOperand *operand, const GDa * * ******************************************************************************/ -static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand * const *a, const GDalvikPoolOperand * const *b) +static int g_dalvik_pool_operand_compare(const GDalvikPoolOperand *a, const GDalvikPoolOperand *b) { int result; /* Bilan à renvoyer */ - const GDalvikPoolOperand *_a; /* Accès rapide à l'élément A */ - const GDalvikPoolOperand *_b; /* Accès rapide à l'élément B */ - - _a = *a; - _b = *b; - result = sort_unsigned_long((unsigned long)_a->format, (unsigned long)_b->format); + result = sort_unsigned_long((unsigned long)a->format, (unsigned long)b->format); if (result == 0) - result = sort_unsigned_long(_a->type, _b->type); + result = sort_unsigned_long(a->type, b->type); if (result == 0) - result = sort_unsigned_long(_a->index, _b->index); + result = sort_unsigned_long(a->index, b->index); return result; @@ -471,6 +442,62 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff /****************************************************************************** * * +* Paramètres : format = format du fichier contenant le code. * +* type = type de table visée avec la référence. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* size = taille de l'opérande, et donc du registre. * +* endian = ordre des bits dans la source. * +* * +* Description : Crée un opérande visant un élément constant Dalvik. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian) +{ + GArchOperand *result; /* Structure à retourner */ + uint8_t index8; /* Indice sur 8 bits */ + uint16_t index16; /* Indice sur 16 bits */ + bool test; /* Bilan de lecture */ + GDalvikPoolOperand fake; /* Transport d'informations */ + + result = NULL; + + switch (size) + { + case MDS_8_BITS: + test = g_binary_content_read_u8(content, pos, &index8); + break; + case MDS_16_BITS: + test = g_binary_content_read_u16(content, pos, endian, &index16); + break; + default: + test = false; + break; + } + + if (!test) + goto gdpon_exit; + + fake.format = format; + fake.type = type; + fake.index = (size == MDS_8_BITS ? index8 : index16); + + result = G_ARCH_OPERAND(g_share_manager_build(_dalvik_pool_operand_manager, (GSharedInstance *)&fake)); + + gdpon_exit: + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * * * Description : Indique la nature de la table de constantes visée ici. * @@ -517,6 +544,25 @@ uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand) * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_dalvik_pool_operand_share_manager(void) +{ + return _dalvik_pool_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Met en place les mécanismes de partage des opérandes Dalvik. * * * * Retour : Bilan de l'opération. * diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c index b415d3f..cf29455 100644 --- a/src/arch/dalvik/operands/register.c +++ b/src/arch/dalvik/operands/register.c @@ -65,10 +65,13 @@ static void g_dalvik_register_operand_dispose(GDalvikRegisterOperand *); static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *, const GDalvikRegisterOperand *); +static bool g_dalvik_register_operand_apply_template(GDalvikRegisterOperand *, const GDalvikRegisterOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_dalvik_register_operand_define_template(const GDalvikRegisterOperand *, GDalvikRegisterOperand *); /* Compare un opérande avec un autre. */ -static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand * const *, const GDalvikRegisterOperand * const *); +static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBufferLine *, AsmSyntax); @@ -82,6 +85,10 @@ static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBuf static GShareManager *_dalvik_register_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_dalvik_register_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* MANIPULATION D'OPERANDES INDIVIDUELLES */ @@ -116,7 +123,11 @@ static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *kl operand = G_ARCH_OPERAND_CLASS(klass); - operand->init = (operand_do_init_fc)g_dalvik_register_operand_do_init; + operand->get_manager = (get_operand_manager_fc)get_dalvik_register_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_dalvik_register_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_dalvik_register_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; operand->compare = (operand_compare_fc)g_dalvik_register_operand_compare; operand->print = (operand_print_fc)g_dalvik_register_operand_print; @@ -183,6 +194,95 @@ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *operand) /****************************************************************************** * * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * +* * +* Description : Initialise un nouvel objet partagé avec des informations. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_dalvik_register_operand_apply_template(GDalvikRegisterOperand *operand, const GDalvikRegisterOperand *template) +{ + g_dalvik_register_operand_define_template(template, operand); + + g_object_ref(G_OBJECT(operand->reg)); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_register_operand_define_template(const GDalvikRegisterOperand *operand, GDalvikRegisterOperand *template) +{ + template->reg = operand->reg; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b) +{ + int result; /* Bilan à retourner */ + + result = g_dalvik_register_compare(a->reg, b->reg); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à traiter. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un opérande en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ + g_arch_register_print(G_ARCH_REGISTER(operand->reg), line, syntax); + +} + + +/****************************************************************************** +* * * Paramètres : content = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * * low = position éventuelle des 4 bits visés. [OUT] * @@ -275,53 +375,7 @@ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *reg) fake.reg = reg; - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_register_operand_manager, (GSharedInstance *)&fake)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = objet partagé à initialiser. * -* fake = coquille vide contenant les infos à enregistrer. * -* * -* Description : Initialise un nouvel objet partagé avec des informations. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_dalvik_register_operand_do_init(GDalvikRegisterOperand *operand, const GDalvikRegisterOperand *fake) -{ - operand->reg = fake->reg; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * -* * -* Description : Compare un opérande avec un autre. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand * const *a, const GDalvikRegisterOperand * const *b) -{ - int result; /* Bilan à retourner */ - - result = g_dalvik_register_compare(&(*a)->reg, &(*b)->reg); + result = G_ARCH_OPERAND(g_share_manager_build(_dalvik_register_operand_manager, (GSharedInstance *)&fake)); return result; @@ -330,27 +384,6 @@ static int g_dalvik_register_operand_compare(const GDalvikRegisterOperand * cons /****************************************************************************** * * -* Paramètres : operand = opérande à traiter. * -* line = ligne tampon où imprimer l'opérande donné. * -* syntax = type de représentation demandée. * -* * -* Description : Traduit un opérande en version humainement lisible. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax) -{ - g_arch_register_print(G_ARCH_REGISTER(operand->reg), line, syntax); - -} - - -/****************************************************************************** -* * * Paramètres : operand = opérande représentant un registre. * * * * Description : Fournit le registre Dalvik associé à l'opérande. * @@ -416,6 +449,25 @@ bool g_dalvik_register_operand_is_written(const GDalvikRegisterOperand *operand) * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_dalvik_register_operand_share_manager(void) +{ + return _dalvik_register_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Met en place les mécanismes de partage des opérandes Dalvik. * * * * Retour : Bilan de l'opération. * diff --git a/src/arch/dalvik/register.c b/src/arch/dalvik/register.c index 45b2224..2b5a285 100644 --- a/src/arch/dalvik/register.c +++ b/src/arch/dalvik/register.c @@ -69,8 +69,8 @@ static void g_dalvik_register_dispose(GDalvikRegister *); /* Procède à la libération totale de la mémoire. */ static void g_dalvik_register_finalize(GDalvikRegister *); -/* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_register_do_init(GDalvikRegister *, const GDalvikRegister *); +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_dalvik_register_define_template(const GDalvikRegister *, GDalvikRegister *); /* Produit une empreinte à partir d'un registre. */ static guint g_dalvik_register_hash(const GDalvikRegister *); @@ -87,6 +87,10 @@ static void g_dalvik_register_print(const GDalvikRegister *, GBufferLine *, AsmS static GShareManager *_dalvik_register_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_dalvik_register_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* ENCADREMENT DE REGISTRES BRUTS */ @@ -121,7 +125,9 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *klass) register_class = G_ARCH_REGISTER_CLASS(klass); - register_class->init = (init_shared_fc)g_dalvik_register_do_init; + register_class->get_manager = (get_register_manager_fc)get_dalvik_register_share_manager; + + register_class->define_template = (define_register_template_fc)g_dalvik_register_define_template; register_class->hash = (reg_hash_fc)g_dalvik_register_hash; register_class->compare = (reg_compare_fc)g_dalvik_register_compare; @@ -188,48 +194,20 @@ static void g_dalvik_register_finalize(GDalvikRegister *reg) /****************************************************************************** * * -* Paramètres : index = indice du registre correspondant. * -* * -* Description : Crée une réprésentation de registre Dalvik. * -* * -* Retour : Adresse de la structure mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GDalvikRegister *g_dalvik_register_new(uint16_t index) -{ - GDalvikRegister *result; /* Structure à retourner */ - GDalvikRegister fake; /* Transport d'informations */ - - fake.index = index; - - result = G_DALVIK_REGISTER(g_share_manager_get(_dalvik_register_manager, (GSharedInstance *)&fake)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : reg = objet partagé à initialiser. * -* fake = coquille vide contenant les infos à enregistrer. * +* Paramètres : reg = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Initialise un nouvel objet partagé avec des informations. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool g_dalvik_register_do_init(GDalvikRegister *reg, const GDalvikRegister *fake) +static void g_dalvik_register_define_template(const GDalvikRegister *reg, GDalvikRegister *template) { - reg->index = fake->index; - - return true; + template->index = reg->index; } @@ -295,6 +273,32 @@ static void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *lin /****************************************************************************** * * +* Paramètres : index = indice du registre correspondant. * +* * +* Description : Crée une réprésentation de registre Dalvik. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDalvikRegister *g_dalvik_register_new(uint16_t index) +{ + GDalvikRegister *result; /* Structure à retourner */ + GDalvikRegister template; /* Transport d'informations */ + + template.index = index; + + result = G_DALVIK_REGISTER(g_share_manager_build(_dalvik_register_manager, (GSharedInstance *)&template)); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : reg = registre à consulter. * * * * Description : Fournit l'indice d'un registre Dalvik. * @@ -325,11 +329,11 @@ uint16_t g_dalvik_register_get_index(const GDalvikRegister *reg) * * ******************************************************************************/ -int g_dalvik_register_compare(const GDalvikRegister * const *a, const GDalvikRegister * const *b) +int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b) { int result; /* Bilan à retourner */ - result = sort_unsigned_long((*a)->index, (*b)->index); + result = sort_unsigned_long(a->index, b->index); return result; @@ -345,6 +349,25 @@ int g_dalvik_register_compare(const GDalvikRegister * const *a, const GDalvikReg * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_dalvik_register_share_manager(void) +{ + return _dalvik_register_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Met en place les mécanismes de partage des registres Dalvik. * * * * Retour : Bilan de l'opération. * diff --git a/src/arch/dalvik/register.h b/src/arch/dalvik/register.h index 136741c..3bd6286 100644 --- a/src/arch/dalvik/register.h +++ b/src/arch/dalvik/register.h @@ -62,7 +62,7 @@ GDalvikRegister *g_dalvik_register_new(uint16_t); uint16_t g_dalvik_register_get_index(const GDalvikRegister *); /* Compare un registre avec un autre. */ -int g_dalvik_register_compare(const GDalvikRegister * const *, const GDalvikRegister * const *); +int g_dalvik_register_compare(const GDalvikRegister *, const GDalvikRegister *); diff --git a/src/arch/immediate.c b/src/arch/immediate.c index 5d3b844..9c807db 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -96,14 +96,11 @@ static void g_imm_operand_dispose(GImmOperand *); /* Procède à la libération totale de la mémoire. */ static void g_imm_operand_finalize(GImmOperand *); -/* Initialise un nouvel objet partagé avec des informations. */ -static bool g_imm_operand_do_init(GImmOperand *, const GImmOperand *); - /* Réalise une copie minimale d'un contenu partagé. */ -static void g_imm_operand_quickly_copy(const GImmOperand *, GImmOperand *); +static void g_imm_operand_define_template(const GImmOperand *, GImmOperand *); /* Compare un opérande avec un autre. */ -static int g_imm_operand_compare(const GImmOperand * const *, const GImmOperand * const *); +static int g_imm_operand_compare(const GImmOperand *, const GImmOperand *); /* Indique si une valeur est complétée par des zéros. */ static bool g_imm_operand_does_padding_for_display(const GImmOperand *, ImmOperandDisplay); @@ -126,6 +123,10 @@ static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinar static GShareManager *_imm_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_imm_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* MANIPULATION D'OPERANDES DE VALEUR IMMEDIATE */ @@ -160,8 +161,11 @@ static void g_imm_operand_class_init(GImmOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_imm_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_imm_operand_finalize; - operand->init = (operand_do_init_fc)g_imm_operand_do_init; - operand->qck_copy = (operand_qck_copy_fc)g_imm_operand_quickly_copy; + operand->get_manager = (get_operand_manager_fc)get_imm_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)NULL; + operand->define_template = (define_operand_template_fc)g_imm_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; operand->compare = (operand_compare_fc)g_imm_operand_compare; operand->print = (operand_print_fc)g_imm_operand_print; @@ -331,7 +335,7 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten } - result = G_ARCH_OPERAND(g_share_manager_get(_imm_operand_manager, (GSharedInstance *)&fake)); + result = G_ARCH_OPERAND(g_share_manager_build(_imm_operand_manager, (GSharedInstance *)&fake)); return result; @@ -370,7 +374,7 @@ GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, uint64_t value) fake.size = size; fake.raw = value; - result = G_ARCH_OPERAND(g_share_manager_get(_imm_operand_manager, (GSharedInstance *)&fake)); + result = G_ARCH_OPERAND(g_share_manager_build(_imm_operand_manager, (GSharedInstance *)&fake)); } @@ -381,28 +385,6 @@ GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, uint64_t value) /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* template = coquille vide contenant les infos à enregistrer. * -* * -* Description : Initialise un nouvel objet partagé avec des informations. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_imm_operand_do_init(GImmOperand *operand, const GImmOperand *template) -{ - g_imm_operand_quickly_copy(template, operand); - - return true; - -} - - -/****************************************************************************** -* * * Paramètres : operand = objet partagé à consulter. * * template = informations à retrouver intégralement. * * * @@ -414,7 +396,7 @@ static bool g_imm_operand_do_init(GImmOperand *operand, const GImmOperand *templ * * ******************************************************************************/ -static void g_imm_operand_quickly_copy(const GImmOperand *operand, GImmOperand *template) +static void g_imm_operand_define_template(const GImmOperand *operand, GImmOperand *template) { template->raw = operand->raw; template->size = operand->size; @@ -439,85 +421,80 @@ static void g_imm_operand_quickly_copy(const GImmOperand *operand, GImmOperand * * * ******************************************************************************/ -static int g_imm_operand_compare(const GImmOperand * const *a, const GImmOperand * const *b) +static int g_imm_operand_compare(const GImmOperand *a, const GImmOperand *b) { int result; /* Bilan à retourner */ - const GImmOperand *imm_a; /* Accès simplifié à A */ - const GImmOperand *imm_b; /* Accès simplifié à B */ - - imm_a = *a; - imm_b = *b; - if (imm_a->size < imm_b->size) + if (a->size < b->size) { result = -1; goto gioc_done; } - else if (imm_a->size > imm_b->size) + else if (a->size > b->size) { result = 1; goto gioc_done; } - if (imm_a->raw < imm_b->raw) + if (a->raw < b->raw) { result = -1; goto gioc_done; } - else if (imm_a->raw > imm_b->raw) + else if (a->raw > b->raw) { result = 1; goto gioc_done; } - if (imm_a->def_display < imm_b->def_display) + if (a->def_display < b->def_display) { result = -1; goto gioc_done; } - else if (imm_a->def_display > imm_b->def_display) + else if (a->def_display > b->def_display) { result = 1; goto gioc_done; } - if (IMM_HAS_DISPLAY(imm_a) != IMM_HAS_DISPLAY(imm_b)) + if (IMM_HAS_DISPLAY(a) != IMM_HAS_DISPLAY(b)) { - result = (IMM_HAS_DISPLAY(imm_a) ? 1 : -1); + result = (IMM_HAS_DISPLAY(a) ? 1 : -1); goto gioc_done; } - if (IMM_HAS_DISPLAY(imm_a)) + if (IMM_HAS_DISPLAY(a)) { - if (imm_a->display < imm_b->display) + if (a->display < b->display) { result = -1; goto gioc_done; } - else if (imm_a->display > imm_b->display) + else if (a->display > b->display) { result = 1; goto gioc_done; } } - if (IMM_GET_DEF_ZERO_PADDING(imm_a) != IMM_GET_DEF_ZERO_PADDING(imm_b)) + if (IMM_GET_DEF_ZERO_PADDING(a) != IMM_GET_DEF_ZERO_PADDING(b)) { - result = (IMM_GET_DEF_ZERO_PADDING(imm_a) ? 1 : -1); + result = (IMM_GET_DEF_ZERO_PADDING(a) ? 1 : -1); goto gioc_done; } - if (IMM_HAS_ZERO_PADDING(imm_a) != IMM_HAS_ZERO_PADDING(imm_b)) + if (IMM_HAS_ZERO_PADDING(a) != IMM_HAS_ZERO_PADDING(b)) { - result = (IMM_HAS_ZERO_PADDING(imm_a) ? 1 : -1); + result = (IMM_HAS_ZERO_PADDING(a) ? 1 : -1); goto gioc_done; } - if (IMM_HAS_ZERO_PADDING(imm_a)) + if (IMM_HAS_ZERO_PADDING(a)) { - if (IMM_GET_ZERO_PADDING_VALUE(imm_a) != IMM_GET_ZERO_PADDING_VALUE(imm_b)) + if (IMM_GET_ZERO_PADDING_VALUE(a) != IMM_GET_ZERO_PADDING_VALUE(b)) { - result = (IMM_GET_ZERO_PADDING_VALUE(imm_a) ? 1 : -1); + result = (IMM_GET_ZERO_PADDING_VALUE(a) ? 1 : -1); goto gioc_done; } } @@ -668,18 +645,18 @@ uint64_t g_imm_operand_get_raw_value(const GImmOperand *operand) void g_imm_operand_set_value(GImmOperand **operand, MemoryDataSize size, uint64_t value, GShareContainer *container) { GSharedInstance *shared; /* Instace de travail partagée */ - GImmOperand fake; /* Transport d'informations */ + GImmOperand template; /* Transport d'informations */ assert(size != MDS_UNDEFINED); shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - fake.size = size; - fake.raw = value; + template.size = size; + template.raw = value; - shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container); *operand = G_IMM_OPERAND(shared); @@ -703,15 +680,15 @@ void g_imm_operand_set_value(GImmOperand **operand, MemoryDataSize size, uint64_ void g_imm_operand_pad_by_default(GImmOperand **operand, bool state, GShareContainer *container) { GSharedInstance *shared; /* Instace de travail partagée */ - GImmOperand fake; /* Transport d'informations */ + GImmOperand template; /* Transport d'informations */ shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - IMM_SET_DEF_ZERO_PADDING(&fake, state); + IMM_SET_DEF_ZERO_PADDING(&template, state); - shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container); *operand = G_IMM_OPERAND(shared); @@ -757,16 +734,16 @@ bool g_imm_operand_does_padding_by_default(const GImmOperand *operand) void g_imm_operand_pad(GImmOperand **operand, bool state, GShareContainer *container) { GSharedInstance *shared; /* Instace de travail partagée */ - GImmOperand fake; /* Transport d'informations */ + GImmOperand template; /* Transport d'informations */ shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - IMM_SET_ZERO_PADDING(&fake); - IMM_SET_ZERO_PADDING_VALUE(&fake, state); + IMM_SET_ZERO_PADDING(&template); + IMM_SET_ZERO_PADDING_VALUE(&template, state); - shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container); *operand = G_IMM_OPERAND(shared); @@ -849,15 +826,15 @@ static bool g_imm_operand_does_padding_for_display(const GImmOperand *operand, I void g_imm_operand_set_default_display(GImmOperand **operand, ImmOperandDisplay display, GShareContainer *container) { GSharedInstance *shared; /* Instace de travail partagée */ - GImmOperand fake; /* Transport d'informations */ + GImmOperand template; /* Transport d'informations */ shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - fake.def_display = display; + template.def_display = display; - shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container); *operand = G_IMM_OPERAND(shared); @@ -900,16 +877,16 @@ ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand) void g_imm_operand_set_display(GImmOperand **operand, ImmOperandDisplay display, GShareContainer *container) { GSharedInstance *shared; /* Instace de travail partagée */ - GImmOperand fake; /* Transport d'informations */ + GImmOperand template; /* Transport d'informations */ shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - IMM_SET_DISPLAY(&fake); - fake.display = display; + IMM_SET_DISPLAY(&template); + template.display = display; - shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container); *operand = G_IMM_OPERAND(shared); @@ -1509,6 +1486,25 @@ bool g_imm_operand_to_off_t(const GImmOperand *operand, off_t *value, bool *nega * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_imm_operand_share_manager(void) +{ + return _imm_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Initialise les mécanismes de partage d'opérandes immédiates. * * * * Retour : Bilan de l'opération. * diff --git a/src/arch/instruction.c b/src/arch/instruction.c index dd5b019..8f2f262 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -191,6 +191,26 @@ static void g_arch_instruction_generator_interface_init(GLineGeneratorInterface static void g_arch_instruction_dispose(GArchInstruction *instr) { + size_t count; /* Nombre d'opérandes en place */ + size_t i; /* Boucle de parcours */ + GArchOperand *op; /* Opérande à manipuler */ + + g_arch_instruction_lock_operands(instr); + + count = _g_arch_instruction_count_operands(instr); + + for (i = 0; i < count; i++) + { + op = _g_arch_instruction_get_operand(instr, 0); + + rem_item_from_flat_array(&instr->operands, 0, sizeof(GArchOperand *)); + + g_shared_instance_unref(G_SHARED_INSTANCE(op)); + + } + + g_arch_instruction_unlock_operands(instr); + G_OBJECT_CLASS(g_arch_instruction_parent_class)->dispose(G_OBJECT(instr)); } @@ -619,7 +639,7 @@ bool _g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand * { rpl_item_in_flat_array(instr->operands, i, &new, sizeof(GArchOperand *)); - //g_object_unref(G_OBJECT(old)); + g_shared_instance_unref(G_SHARED_INSTANCE(old)); } @@ -660,7 +680,7 @@ void _g_arch_instruction_detach_operand(GArchInstruction *instr, GArchOperand *t rem_item_from_flat_array(&instr->operands, i, sizeof(GArchOperand *)); - g_object_unref(G_OBJECT(target)); + g_shared_instance_unref(G_SHARED_INSTANCE(target)); } diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h index 535df1b..3caca46 100644 --- a/src/arch/operand-int.h +++ b/src/arch/operand-int.h @@ -30,14 +30,20 @@ +/* Fournit le gestionnaire de partages attribué à un type. */ +typedef GShareManager * (* get_operand_manager_fc) (void); + /* Initialise un nouvel objet partagé avec des informations. */ -typedef bool (* operand_do_init_fc) (GArchOperand *, const GArchOperand *); +typedef bool (* apply_operand_template_fc) (GArchOperand *, const GArchOperand *); + +/* Procède à l'initialisation de l'interface de partage. */ +typedef void (* define_operand_template_fc) (const GArchOperand *, GArchOperand *); -/* Réalise une copie minimale d'un contenu partagé. */ -typedef void (* operand_qck_copy_fc) (const GArchOperand *, GArchOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +typedef bool (* free_operand_template_fc) (const GArchOperand *, GArchOperand *); /* Compare un opérande avec un autre. */ -typedef int (* operand_compare_fc) (const GArchOperand * const *, const GArchOperand * const *); +typedef int (* operand_compare_fc) (const GArchOperand *, const GArchOperand *); /* Traduit un opérande en version humainement lisible. */ typedef void (* operand_print_fc) (const GArchOperand *, GBufferLine *, AsmSyntax); @@ -72,8 +78,11 @@ struct _GArchOperandClass { GObjectClass parent; /* A laisser en premier */ - operand_do_init_fc init; /* Mise en place via interface */ - operand_qck_copy_fc qck_copy; /* Copie minimale via interface*/ + get_operand_manager_fc get_manager; /* Accès au gestionnaire */ + + apply_operand_template_fc apply_template; /* Intialisation d'instance */ + define_operand_template_fc define_template; /* Copie de détails */ + free_operand_template_fc free_template; /* Libération d'un patron */ operand_compare_fc compare; /* Comparaison d'opérandes */ operand_print_fc print; /* Texte humain équivalent */ diff --git a/src/arch/operand.c b/src/arch/operand.c index 584e3c0..8bc85fb 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -49,11 +49,17 @@ static void g_arch_operand_dispose(GArchOperand *); /* Procède à la libération totale de la mémoire. */ static void g_arch_operand_finalize(GArchOperand *); +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_arch_operand_share_manager(const GArchOperand *); + /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_arch_operand_do_init(GArchOperand *, const GArchOperand *); +static bool g_arch_operand_apply_template(GArchOperand *, const GArchOperand *); /* Réalise une copie minimale d'un contenu partagé. */ -static void g_arch_operand_quickly_copy(const GArchOperand *, GArchOperand *); +static void g_arch_operand_define_template(const GArchOperand *, GArchOperand *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +static void g_arch_operand_free_template(const GArchOperand *, GArchOperand *); /* Fournit la valeur du compteur de partage. */ static unsigned int g_arch_operand_get_references(const GArchOperand *); @@ -64,8 +70,8 @@ static void g_arch_operand_inc_references(GArchOperand *); /* Décrémente le compteur de partage. */ static void g_arch_operand_dec_references(GArchOperand *); -/* Compare de façon accélérée un opérande avec un autre. */ -static int g_arch_operand_quickly_compare(const GArchOperand **, const GArchOperand **); +/* Compare le contenu d'un opérande avec un autre. */ +static int g_arch_operand_compare_shared(const GArchOperand * const *, const GArchOperand * const *); @@ -131,14 +137,17 @@ static void g_arch_operand_init(GArchOperand *operand) static void g_arch_operand_interface_init(GSharedInstanceInterface *iface) { - iface->init = (init_shared_fc)g_arch_operand_do_init; - iface->qck_copy = (qck_copy_shared_fc)g_arch_operand_quickly_copy; + iface->get_manager = (get_share_manager_fc)get_arch_operand_share_manager; + + iface->apply_template = (apply_shared_template_fc)g_arch_operand_apply_template; + iface->define_template = (define_shared_template_fc)g_arch_operand_define_template; + iface->free_template = (free_shared_template_fc)g_arch_operand_free_template; iface->get_ref = (get_shared_ref_fc)g_arch_operand_get_references; iface->inc_ref = (inc_shared_ref_fc)g_arch_operand_inc_references; iface->dec_ref = (dec_shared_ref_fc)g_arch_operand_dec_references; - iface->qck_cmp = (qck_compare_shared_fc)g_arch_operand_quickly_compare; + iface->compare = (compare_shared_fc)g_arch_operand_compare_shared; } @@ -185,8 +194,34 @@ static void g_arch_operand_finalize(GArchOperand *operand) /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* info = information à utiliser pour la mise en place. * +* Paramètres : operand = instance partagée à consulter. * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_arch_operand_share_manager(const GArchOperand *operand) +{ + GShareManager *result; /* Instance à retourner */ + + if (G_ARCH_OPERAND_GET_CLASS(operand)->get_manager == NULL) + printf("No manager for '%s'\n", G_OBJECT_TYPE_NAME(operand)); + + result = G_ARCH_OPERAND_GET_CLASS(operand)->get_manager(); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * * Description : Initialise un nouvel objet partagé avec des informations. * * * @@ -196,11 +231,25 @@ static void g_arch_operand_finalize(GArchOperand *operand) * * ******************************************************************************/ -static bool g_arch_operand_do_init(GArchOperand *operand, const GArchOperand *info) +static bool g_arch_operand_apply_template(GArchOperand *operand, const GArchOperand *template) { bool result; /* Bilan à retourner */ + apply_operand_template_fc func; /* Fonction à appeler */ - result = G_ARCH_OPERAND_GET_CLASS(operand)->init(operand, info); + func = G_ARCH_OPERAND_GET_CLASS(operand)->apply_template; + + if (func != NULL) + result = func(operand, template); + + else + { + if (G_ARCH_OPERAND_GET_CLASS(operand)->define_template == NULL) + printf("No def for '%s'\n", G_OBJECT_TYPE_NAME(operand)); + + + G_ARCH_OPERAND_GET_CLASS(operand)->define_template(template, operand); + result = true; + } return result; @@ -220,9 +269,34 @@ static bool g_arch_operand_do_init(GArchOperand *operand, const GArchOperand *in * * ******************************************************************************/ -static void g_arch_operand_quickly_copy(const GArchOperand *operand, GArchOperand *template) +static void g_arch_operand_define_template(const GArchOperand *operand, GArchOperand *template) { - G_ARCH_OPERAND_GET_CLASS(operand)->qck_copy(operand, template); + G_ARCH_OPERAND_GET_CLASS(operand)->define_template(operand, template); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations dont le contenu est à libérer. * +* * +* Description : Libère la mémoire utilisée par un patron d'instance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_operand_free_template(const GArchOperand *operand, GArchOperand *template) +{ + free_operand_template_fc func; /* Fonction à appeler */ + + func = G_ARCH_OPERAND_GET_CLASS(operand)->free_template; + + if (func != NULL) + func(operand, template); } @@ -289,7 +363,7 @@ static void g_arch_operand_dec_references(GArchOperand *operand) * Paramètres : a = premier opérande à consulter. * * b = second opérande à consulter. * * * -* Description : Compare de façon accélérée un opérande avec un autre. * +* Description : Compare le contenu d'un opérande avec un autre. * * * * Retour : Bilan de la comparaison. * * * @@ -297,17 +371,16 @@ static void g_arch_operand_dec_references(GArchOperand *operand) * * ******************************************************************************/ -static int g_arch_operand_quickly_compare(const GArchOperand **a, const GArchOperand **b) +static int g_arch_operand_compare_shared(const GArchOperand * const *a, const GArchOperand * const *b) { int result; /* Bilan à faire remonter */ - result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(a, b); + result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(*a, *b); return result; } - /****************************************************************************** * * * Paramètres : a = premier opérande à consulter. * @@ -321,21 +394,21 @@ static int g_arch_operand_quickly_compare(const GArchOperand **a, const GArchOpe * * ******************************************************************************/ -int g_arch_operand_compare(const GArchOperand * const *a, const GArchOperand * const *b) +int g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b) { int result; /* Bilan à faire remonter */ GType type_a; /* Type de l'object A */ GType type_b; /* Type de l'object B */ - type_a = G_OBJECT_TYPE(G_OBJECT(*a)); - type_b = G_OBJECT_TYPE(G_OBJECT(*b)); + type_a = G_OBJECT_TYPE(G_OBJECT(a)); + type_b = G_OBJECT_TYPE(G_OBJECT(b)); assert(sizeof(GType) <= sizeof(unsigned long)); result = sort_unsigned_long(type_a, type_b); if (result == 0) - result = G_ARCH_OPERAND_GET_CLASS(*a)->compare(a, b); + result = G_ARCH_OPERAND_GET_CLASS(a)->compare(a, b); return result; diff --git a/src/arch/operand.h b/src/arch/operand.h index 36fc231..5242e24 100644 --- a/src/arch/operand.h +++ b/src/arch/operand.h @@ -55,7 +55,7 @@ typedef struct _GArchOperandClass GArchOperandClass; GType g_arch_operand_get_type(void); /* Compare un opérande avec un autre. */ -int g_arch_operand_compare(const GArchOperand * const *, const GArchOperand * const *); +int g_arch_operand_compare(const GArchOperand *, const GArchOperand *); /* Définit une autre représentation textuelle pour l'opérande. */ void g_arch_operand_set_alt_text(GArchOperand *, const char *, RenderingTagType); diff --git a/src/arch/register-int.h b/src/arch/register-int.h index 4d8e364..0934f95 100644 --- a/src/arch/register-int.h +++ b/src/arch/register-int.h @@ -36,11 +36,23 @@ /* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */ +/* Fournit le gestionnaire de partages attribué à un type. */ +typedef GShareManager * (* get_register_manager_fc) (void); + +/* Initialise un nouvel objet partagé avec des informations. */ +typedef bool (* apply_register_template_fc) (GArchRegister *, const GArchRegister *); + +/* Réalise une copie minimale d'un contenu partagé. */ +typedef void (* define_register_template_fc) (const GArchRegister *, GArchRegister *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +typedef void (* free_register_template_fc) (const GArchRegister *, GArchOperand *); + /* Produit une empreinte à partir d'un registre. */ typedef guint (* reg_hash_fc) (const GArchRegister *); /* Compare un registre avec un autre. */ -typedef int (* reg_compare_fc) (const GArchRegister * const *, const GArchRegister * const *); +typedef int (* reg_compare_fc) (const GArchRegister *, const GArchRegister *); /* Traduit un registre en version humainement lisible. */ typedef void (* reg_print_fc) (const GArchRegister *, GBufferLine *, AsmSyntax); @@ -68,7 +80,11 @@ struct _GArchRegisterClass { GObjectClass parent; /* A laisser en premier */ - init_shared_fc init; /* Mise en place via interface */ + get_register_manager_fc get_manager; /* Accès au gestionnaire */ + + apply_register_template_fc apply_template; /* Intialisation d'instance */ + define_register_template_fc define_template; /* Copie de détails */ + free_register_template_fc free_template; /* Libération d'un patron */ reg_hash_fc hash; /* Production d'empreinte */ reg_compare_fc compare; /* Comparaison de registres */ diff --git a/src/arch/register.c b/src/arch/register.c index 519ecdd..3071198 100644 --- a/src/arch/register.c +++ b/src/arch/register.c @@ -46,8 +46,14 @@ static void g_arch_register_dispose(GArchRegister *); /* Procède à la libération totale de la mémoire. */ static void g_arch_register_finalize(GArchRegister *); +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_arch_register_share_manager(const GArchRegister *); + /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_arch_register_do_init(GArchRegister *, const void *); +static bool g_arch_register_apply_template(GArchRegister *, const GArchRegister *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_arch_register_define_template(const GArchRegister *, GArchRegister *); /* Fournit la valeur du compteur de partage. */ static unsigned int g_arch_register_get_references(const GArchRegister *); @@ -59,7 +65,7 @@ static void g_arch_register_inc_references(GArchRegister *); static void g_arch_register_dec_references(GArchRegister *); /* Compare de façon accélérée un registre avec un autre. */ -static int g_arch_register_quickly_compare(const GArchRegister **, const GArchRegister **); +static int g_arch_register_compare_shared(const GArchRegister * const *, const GArchRegister * const *); @@ -78,14 +84,32 @@ static void g_register_operand_dispose(GRegisterOperand *); /* Procède à la libération totale de la mémoire. */ static void g_register_operand_finalize(GRegisterOperand *); +/* Initialise un nouvel objet partagé avec des informations. */ +static bool g_register_operand_apply_template(GRegisterOperand *, const GRegisterOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_register_operand_define_template(const GRegisterOperand *, GRegisterOperand *); + /* Compare un opérande avec un autre. */ -static int g_register_operand_compare(const GRegisterOperand **, const GRegisterOperand **); +static int g_register_operand_compare(const GRegisterOperand *, const GRegisterOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_register_operand_print(const GRegisterOperand *, GBufferLine *, AsmSyntax); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_register_operand_manager = NULL; + + +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_register_operand_share_manager(void); + + + /* ---------------------------------------------------------------------------------- */ /* PUR REGISTRE DU MATERIEL */ /* ---------------------------------------------------------------------------------- */ @@ -152,20 +176,24 @@ static void g_arch_register_init(GArchRegister *reg) static void g_arch_register_interface_init(GSharedInstanceInterface *iface) { - iface->init = (init_shared_fc)g_arch_register_do_init; + iface->get_manager = (get_share_manager_fc)get_arch_register_share_manager; + + iface->apply_template = (apply_shared_template_fc)g_arch_register_apply_template; + iface->define_template = (define_shared_template_fc)g_arch_register_define_template; + iface->free_template = (free_shared_template_fc)NULL; iface->get_ref = (get_shared_ref_fc)g_arch_register_get_references; iface->inc_ref = (inc_shared_ref_fc)g_arch_register_inc_references; iface->dec_ref = (dec_shared_ref_fc)g_arch_register_dec_references; - iface->qck_cmp = (qck_compare_shared_fc)g_arch_register_quickly_compare; + iface->compare = (compare_shared_fc)g_arch_register_compare_shared; } /****************************************************************************** * * -* Paramètres : binary = instance d'objet GLib à traiter. * +* Paramètres : reg = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * @@ -184,7 +212,7 @@ static void g_arch_register_dispose(GArchRegister *reg) /****************************************************************************** * * -* Paramètres : binary = instance d'objet GLib à traiter. * +* Paramètres : reg = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * @@ -203,8 +231,31 @@ static void g_arch_register_finalize(GArchRegister *reg) /****************************************************************************** * * -* Paramètres : reg = objet partagé à initialiser. * -* info = information à utiliser pour la mise en place. * +* Paramètres : reg = instance partagée à consulter. * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_arch_register_share_manager(const GArchRegister *reg) +{ + GShareManager *result; /* Instance à retourner */ + + result = G_ARCH_REGISTER_GET_CLASS(reg)->get_manager(); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * * Description : Initialise un nouvel objet partagé avec des informations. * * * @@ -214,11 +265,21 @@ static void g_arch_register_finalize(GArchRegister *reg) * * ******************************************************************************/ -static bool g_arch_register_do_init(GArchRegister *reg, const void *info) +static bool g_arch_register_apply_template(GArchRegister *reg, const GArchRegister *template) { bool result; /* Bilan à retourner */ + apply_register_template_fc func; /* Fonction à appeler */ - result = G_ARCH_REGISTER_GET_CLASS(reg)->init(G_SHARED_INSTANCE(reg), info); + func = G_ARCH_REGISTER_GET_CLASS(reg)->apply_template; + + if (func != NULL) + result = func(reg, template); + + else + { + G_ARCH_REGISTER_GET_CLASS(reg)->define_template(template, reg); + result = true; + } return result; @@ -227,6 +288,26 @@ static bool g_arch_register_do_init(GArchRegister *reg, const void *info) /****************************************************************************** * * +* Paramètres : reg = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_register_define_template(const GArchRegister *reg, GArchRegister *template) +{ + G_ARCH_REGISTER_GET_CLASS(reg)->define_template(reg, template); + +} + + +/****************************************************************************** +* * * Paramètres : reg = objet partagé à consulter. * * * * Description : Fournit la valeur du compteur de partage. * @@ -295,11 +376,11 @@ static void g_arch_register_dec_references(GArchRegister *reg) * * ******************************************************************************/ -static int g_arch_register_quickly_compare(const GArchRegister **a, const GArchRegister **b) +static int g_arch_register_compare_shared(const GArchRegister * const *a, const GArchRegister * const *b) { int result; /* Bilan à faire remonter */ - result = G_ARCH_REGISTER_GET_CLASS(*a)->compare(a, b); + result = G_ARCH_REGISTER_GET_CLASS(*a)->compare(*a, *b); return result; @@ -338,9 +419,9 @@ guint g_arch_register_hash(const GArchRegister *reg) * * ******************************************************************************/ -int g_arch_register_compare(const GArchRegister * const *a, const GArchRegister * const *b) +int g_arch_register_compare(const GArchRegister *a, const GArchRegister *b) { - return G_ARCH_REGISTER_GET_CLASS(*a)->compare(a, b); + return G_ARCH_REGISTER_GET_CLASS(a)->compare(a, b); } @@ -451,6 +532,12 @@ static void g_register_operand_class_init(GRegisterOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_register_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_register_operand_finalize; + operand->get_manager = (get_operand_manager_fc)get_register_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_register_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_register_operand_define_template; + operand->free_template = (free_operand_template_fc)NULL; + operand->compare = (operand_compare_fc)g_register_operand_compare; operand->print = (operand_print_fc)g_register_operand_print; @@ -518,6 +605,52 @@ static void g_register_operand_finalize(GRegisterOperand *operand) /****************************************************************************** * * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * +* * +* Description : Initialise un nouvel objet partagé avec des informations. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_register_operand_apply_template(GRegisterOperand *operand, const GRegisterOperand *template) +{ + g_register_operand_define_template(template, operand); + + g_object_ref(G_OBJECT(operand->reg)); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * +* * +* Description : Réalise une copie minimale d'un contenu partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_register_operand_define_template(const GRegisterOperand *operand, GRegisterOperand *template) +{ + template->reg = operand->reg; + + template->is_written = operand->is_written; + +} + + +/****************************************************************************** +* * * Paramètres : reg = registre déjà en place. * * * * Description : Crée un opérande visant un registre. * @@ -575,12 +708,11 @@ GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand) * * ******************************************************************************/ -static int g_register_operand_compare(const GRegisterOperand **a, const GRegisterOperand **b) +static int g_register_operand_compare(const GRegisterOperand *a, const GRegisterOperand *b) { int result; /* Bilan à retourner */ - result = g_arch_register_compare((const GArchRegister * const *)&(*a)->reg, - (const GArchRegister * const *)&(*b)->reg); + result = g_arch_register_compare(a->reg, b->reg); return result; @@ -644,3 +776,88 @@ bool g_register_operand_is_written(const GRegisterOperand *operand) return operand->is_written; } + + + +/* ---------------------------------------------------------------------------------- */ +/* PARTAGES DE CONTENUS UNIQUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_register_operand_share_manager(void) +{ + return _register_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place les mécanismes de partage des registres. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_register_operand_sharing(void) +{ + _register_operand_manager = g_share_manager_new(G_TYPE_REGISTER_OPERAND); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Imprime des statistiques quant aux partages dans l'archi. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_register_operand_share_stats(void) +{ + g_share_manager_dump_stats(_register_operand_manager); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime les mécanismes de partage des opérandes de registre.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_register_operand_sharing(void) +{ + g_object_unref(G_OBJECT(_register_operand_manager)); + +} diff --git a/src/arch/register.h b/src/arch/register.h index ecbc5d7..ab611bf 100644 --- a/src/arch/register.h +++ b/src/arch/register.h @@ -60,7 +60,7 @@ GType g_arch_register_get_type(void); guint g_arch_register_hash(const GArchRegister *); /* Compare un registre avec un autre. */ -int g_arch_register_compare(const GArchRegister * const *, const GArchRegister * const *); +int g_arch_register_compare(const GArchRegister *, const GArchRegister *); /* Traduit un registre en version humainement lisible. */ void g_arch_register_print(const GArchRegister *, GBufferLine *, AsmSyntax); @@ -108,4 +108,20 @@ bool g_register_operand_is_written(const GRegisterOperand *); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Met en place les mécanismes de partage des registres. */ +bool init_register_operand_sharing(void); + +/* Imprime des statistiques quant aux partages dans l'archi. */ +#ifdef DEBUG_DUMP_STATS +void dump_register_operand_share_stats(void); +#endif + +/* Supprime les mécanismes de partage des opérandes de registre. */ +void exit_register_operand_sharing(void); + + + #endif /* _ARCH_ARCH_REGISTER_H */ diff --git a/src/arch/sharing/instance-int.h b/src/arch/sharing/instance-int.h index f9a91ba..cf5a56d 100644 --- a/src/arch/sharing/instance-int.h +++ b/src/arch/sharing/instance-int.h @@ -26,14 +26,21 @@ #include "instance.h" +#include "manager.h" +/* Fournit le gestionnaire de partages attribué à un type. */ +typedef GShareManager * (* get_share_manager_fc) (const GSharedInstance *); + /* Initialise un nouvel objet partagé avec des informations. */ -typedef bool (* init_shared_fc) (GSharedInstance *, const GSharedInstance *); +typedef bool (* apply_shared_template_fc) (GSharedInstance *, const GSharedInstance *); /* Procède à l'initialisation de l'interface de partage. */ -typedef void (* qck_copy_shared_fc) (const GSharedInstance *, GSharedInstance *); +typedef void (* define_shared_template_fc) (const GSharedInstance *, GSharedInstance *); + +/* Initialise un nouvel objet partagé avec des informations. */ +typedef bool (* free_shared_template_fc) (const GSharedInstance *, GSharedInstance *); /* Fournit la valeur du compteur de partage. */ typedef unsigned int (* get_shared_ref_fc) (const GSharedInstance *); @@ -45,7 +52,7 @@ typedef void (* inc_shared_ref_fc) (GSharedInstance *); typedef void (* dec_shared_ref_fc) (GSharedInstance *); /* Procède à l'initialisation de l'interface de partage. */ -typedef int (* qck_compare_shared_fc) (const GSharedInstance **, const GSharedInstance **); +typedef int (* compare_shared_fc) (const GSharedInstance * const *, const GSharedInstance * const *); /* Règles de partage d'une instance GObject (interface) */ @@ -53,14 +60,17 @@ struct _GSharedInstanceIface { GTypeInterface base_iface; /* A laisser en premier */ - init_shared_fc init; /* Initialisation de l'objet */ - qck_copy_shared_fc qck_copy; /* Copie minimale des détails */ + get_share_manager_fc get_manager; /* Accès au gestionnaire */ + + apply_shared_template_fc apply_template;/* Intialisation d'instance */ + define_shared_template_fc define_template; /* Copie minimale de détails*/ + free_shared_template_fc free_template; /* Libération d'un patron */ get_shared_ref_fc get_ref; /* Obtention du compteur */ inc_shared_ref_fc inc_ref; /* Incrémentation du compteur */ dec_shared_ref_fc dec_ref; /* Décrémentation du compteur */ - qck_compare_shared_fc qck_cmp; /* Comparaison des détails */ + compare_shared_fc compare; /* Comparaison des détails */ }; diff --git a/src/arch/sharing/instance.c b/src/arch/sharing/instance.c index 39dacec..05081bb 100644 --- a/src/arch/sharing/instance.c +++ b/src/arch/sharing/instance.c @@ -71,7 +71,7 @@ static void g_shared_instance_default_init(GSharedInstanceInterface *iface) * * ******************************************************************************/ -bool g_shared_instance_init(GSharedInstance *instance, const GSharedInstance *template) +bool g_shared_instance_apply_template(GSharedInstance *instance, const GSharedInstance *template) { bool result; /* Bilan à retourner */ GSharedInstanceIface *iface; /* Interface utilisée */ @@ -83,7 +83,7 @@ bool g_shared_instance_init(GSharedInstance *instance, const GSharedInstance *te * à la différence d'une opération de copie minimaliste. */ - result = iface->init(instance, template); + result = iface->apply_template(instance, template); return result; @@ -103,7 +103,7 @@ bool g_shared_instance_init(GSharedInstance *instance, const GSharedInstance *te * * ******************************************************************************/ -void g_shared_instance_quickly_copy(const GSharedInstance *instance, GSharedInstance *template) +void g_shared_instance_define_template(const GSharedInstance *instance, GSharedInstance *template) { GSharedInstanceIface *iface; /* Interface utilisée */ @@ -114,7 +114,59 @@ void g_shared_instance_quickly_copy(const GSharedInstance *instance, GSharedInst * Ce genre de traitement est réservé à la phase d'initialisation. */ - iface->qck_copy(instance, template); + iface->define_template(instance, template); + +} + + +/****************************************************************************** +* * +* Paramètres : instance = objet partagé à modifier. * +* * +* Description : Incrémente le compteur de références d'un élément partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_shared_instance_ref(GSharedInstance *instance) +{ + GSharedInstanceIface *iface; /* Interface utilisée */ + GShareManager *manager; /* Gestionnaire associé */ + + iface = G_SHARED_INSTANCE_GET_IFACE(instance); + + manager = iface->get_manager(instance); + + g_share_manager_get(manager, instance); + +} + + +/****************************************************************************** +* * +* Paramètres : instance = objet partagé à modifier. * +* * +* Description : Décrémente le compteur de références d'un élément partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_shared_instance_unref(GSharedInstance *instance) +{ + GSharedInstanceIface *iface; /* Interface utilisée */ + GShareManager *manager; /* Gestionnaire associé */ + + iface = G_SHARED_INSTANCE_GET_IFACE(instance); + + manager = iface->get_manager(instance); + + g_share_manager_put(manager, instance); } @@ -201,7 +253,7 @@ void g_shared_instance_dec_references(GSharedInstance *instance) * * ******************************************************************************/ -int g_shared_instance_quickly_compare(const GSharedInstance **a, const GSharedInstance **b) +int g_shared_instance_compare(const GSharedInstance * const *a, const GSharedInstance * const *b) { int result; /* Bilan à faire remonter */ GSharedInstanceIface *iface; /* Interface utilisée */ @@ -214,7 +266,7 @@ int g_shared_instance_quickly_compare(const GSharedInstance **a, const GSharedIn iface = G_SHARED_INSTANCE_GET_IFACE(*b); - result = iface->qck_cmp(b, a) * -1; + result = iface->compare(b, a) * -1; return result; diff --git a/src/arch/sharing/instance.h b/src/arch/sharing/instance.h index fdc94d7..d9653ff 100644 --- a/src/arch/sharing/instance.h +++ b/src/arch/sharing/instance.h @@ -49,10 +49,16 @@ typedef struct _GSharedInstanceIface GSharedInstanceIface; GType g_shared_instance_get_type(void) G_GNUC_CONST; /* Initialise un nouvel objet partagé avec des informations. */ -bool g_shared_instance_init(GSharedInstance *, const GSharedInstance *); +bool g_shared_instance_apply_template(GSharedInstance *, const GSharedInstance *); /* Réalise une copie minimale d'un contenu partagé. */ -void g_shared_instance_quickly_copy(const GSharedInstance *, GSharedInstance *); +void g_shared_instance_define_template(const GSharedInstance *, GSharedInstance *); + +/* Incrémente le compteur de références d'un élément partagé. */ +void g_shared_instance_ref(GSharedInstance *); + +/* Décrémente le compteur de références d'un élément partagé. */ +void g_shared_instance_unref(GSharedInstance *); /* Fournit la valeur du compteur de partage. */ unsigned int g_shared_instance_get_references(const GSharedInstance *); @@ -64,7 +70,7 @@ void g_shared_instance_inc_references(GSharedInstance *); void g_shared_instance_dec_references(GSharedInstance *); /* Compare de façon accélérée un object partagé avec un autre. */ -int g_shared_instance_quickly_compare(const GSharedInstance **, const GSharedInstance **); +int g_shared_instance_compare(const GSharedInstance * const *, const GSharedInstance * const *); diff --git a/src/arch/sharing/manager.c b/src/arch/sharing/manager.c index 3b7cd01..379c342 100644 --- a/src/arch/sharing/manager.c +++ b/src/arch/sharing/manager.c @@ -69,6 +69,9 @@ static void g_share_manager_dispose(GShareManager *); /* Procède à la libération totale de la mémoire. */ static void g_share_manager_finalize(GShareManager *); +/* Note une augmentation des utilisations d'un élément partagé. */ +static void _g_share_manager_get(GShareManager *, GSharedInstance *); + /* Détermine le type du gestionnaire d'instances partagées. */ @@ -207,7 +210,7 @@ GShareManager *g_share_manager_new(GType type) * * ******************************************************************************/ -GSharedInstance *g_share_manager_get(GShareManager *manager, GSharedInstance *template) +GSharedInstance *g_share_manager_build(GShareManager *manager, GSharedInstance *template) { GSharedInstance *result; /* Trouvaille à retourner */ size_t index; /* Indice d'une instance idéale*/ @@ -217,13 +220,13 @@ GSharedInstance *g_share_manager_get(GShareManager *manager, GSharedInstance *te g_mutex_lock(&manager->access); found = bsearch_index(&template, manager->instances, manager->count, sizeof(GSharedInstance *), - (__compar_fn_t)g_shared_instance_quickly_compare, &index); + (__compar_fn_t)g_shared_instance_compare, &index); if (!found) { result = g_object_new(manager->managed, NULL); - status = g_shared_instance_init(result, template); + status = g_shared_instance_apply_template(result, template); if (!status) { @@ -245,11 +248,7 @@ GSharedInstance *g_share_manager_get(GShareManager *manager, GSharedInstance *te else result = manager->instances[index]; - if (result != NULL) - { - g_object_ref(G_OBJECT(result)); - g_shared_instance_inc_references(result); - } + _g_share_manager_get(manager, result); g_mutex_unlock(&manager->access); @@ -278,7 +277,7 @@ GSharedInstance *g_share_manager_update(GShareManager *manager, GSharedInstance GSharedInstance *result; /* Nouvelle instance à renvoyer*/ bool replaced; /* Remplacement effectué ? */ - result = g_share_manager_get(manager, template); + result = g_share_manager_build(manager, template); if (container != NULL) replaced = g_share_container_replace(container, old, result); @@ -301,6 +300,64 @@ GSharedInstance *g_share_manager_update(GShareManager *manager, GSharedInstance /****************************************************************************** * * +* Paramètres : manager = gestionnaire d'instance à consulter. * +* instance = élément partagé à manipuler. * +* * +* Description : Note une augmentation des utilisations d'un élément partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void _g_share_manager_get(GShareManager *manager, GSharedInstance *instance) +{ +#ifndef NDEBUG + bool found; /* Existence de cette instance */ +#endif + +#ifndef NDEBUG + + found = bsearch_index(&instance, manager->instances, manager->count, sizeof(GSharedInstance *), + (__compar_fn_t)g_shared_instance_compare, (size_t []) { 0 }); + + assert(found); + +#endif + + g_object_ref(G_OBJECT(instance)); + g_shared_instance_inc_references(instance); + +} + + +/****************************************************************************** +* * +* Paramètres : manager = gestionnaire d'instance à consulter. * +* instance = élément partagé à manipuler. * +* * +* Description : Note une augmentation des utilisations d'un élément partagé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_share_manager_get(GShareManager *manager, GSharedInstance *instance) +{ + g_mutex_lock(&manager->access); + + _g_share_manager_get(manager, instance); + + g_mutex_unlock(&manager->access); + +} + + +/****************************************************************************** +* * * Paramètres : manager = gestionnaire d'instance à consulter. * * shared = instance partagée à libérer. * * * @@ -322,7 +379,7 @@ void g_share_manager_put(GShareManager *manager, GSharedInstance *shared) { manager->instances = qdelete(manager->instances, &manager->count, sizeof(GSharedInstance *), - (__compar_fn_t)g_shared_instance_quickly_compare, + (__compar_fn_t)g_shared_instance_compare, &shared); g_object_unref(G_OBJECT(shared)); diff --git a/src/arch/sharing/manager.h b/src/arch/sharing/manager.h index 959087d..c24fcc6 100644 --- a/src/arch/sharing/manager.h +++ b/src/arch/sharing/manager.h @@ -60,11 +60,14 @@ GType g_share_manager_get_type(void); GShareManager *g_share_manager_new(GType); /* Retrouve ou crée une instance partagée. */ -GSharedInstance *g_share_manager_get(GShareManager *, GSharedInstance *); +GSharedInstance *g_share_manager_build(GShareManager *, GSharedInstance *); /* Met à jour une instance partagée. */ GSharedInstance *g_share_manager_update(GShareManager *, GSharedInstance *, GSharedInstance *, GShareContainer *); +/* Note une augmentation des utilisations d'un élément partagé. */ +void g_share_manager_get(GShareManager *, GSharedInstance *); + /* Abandonne un usage d'une instance partagée. */ void g_share_manager_put(GShareManager *, GSharedInstance *); diff --git a/src/arch/target.c b/src/arch/target.c index 056ace3..3f6d9a5 100644 --- a/src/arch/target.c +++ b/src/arch/target.c @@ -78,13 +78,13 @@ static void g_target_operand_dispose(GTargetOperand *); static void g_target_operand_finalize(GTargetOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_target_operand_do_init(GTargetOperand *, const GTargetOperand *); +static bool g_target_operand_apply_template(GTargetOperand *, const GTargetOperand *); /* Réalise une copie minimale d'un contenu partagé. */ -static void g_target_operand_quickly_copy(const GTargetOperand *, GTargetOperand *); +static void g_target_operand_define_template(const GTargetOperand *, GTargetOperand *); /* Compare un opérande avec un autre. */ -static int g_target_operand_compare(const GTargetOperand * const *, const GTargetOperand * const *); +static int g_target_operand_compare(const GTargetOperand *, const GTargetOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_target_operand_print(const GTargetOperand *, GBufferLine *, AsmSyntax); @@ -101,6 +101,10 @@ static char *g_target_operand_build_tooltip(const GTargetOperand *, const GLoade static GShareManager *_target_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_target_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* GESTION DES OPERANDES DE CIBLAGE */ @@ -135,8 +139,10 @@ static void g_target_operand_class_init(GTargetOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_target_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_target_operand_finalize; - operand->init = (operand_do_init_fc)g_target_operand_do_init; - operand->qck_copy = (operand_qck_copy_fc)g_target_operand_quickly_copy; + operand->get_manager = (get_operand_manager_fc)get_target_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_target_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_target_operand_define_template; operand->compare = (operand_compare_fc)g_target_operand_compare; operand->print = (operand_print_fc)g_target_operand_print; @@ -182,8 +188,6 @@ static void g_target_operand_init(GTargetOperand *operand) static void g_target_operand_dispose(GTargetOperand *operand) { - printf(" !! dispose %p\n", operand); - if (operand->symbol != NULL) g_object_unref(G_OBJECT(operand->symbol)); @@ -213,36 +217,6 @@ static void g_target_operand_finalize(GTargetOperand *operand) /****************************************************************************** * * -* Paramètres : size = taille des adresse mémoire virtuelles. * -* addr = localisation d'un élément à retrouver. * -* * -* Description : Crée un opérande réprésentant une valeur numérique. * -* * -* Retour : Instruction mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_target_operand_new(MemoryDataSize size, const vmpa2t *addr) -{ - GArchOperand *result; /* Opérande à retourner */ - GTargetOperand fake; /* Transport d'informations */ - - g_target_operand_init(&fake); - - fake.size = size; - copy_vmpa(&fake.addr, addr); - - result = G_ARCH_OPERAND(g_share_manager_get(_target_operand_manager, (GSharedInstance *)&fake)); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : operand = objet partagé à initialiser. * * template = coquille vide contenant les infos à enregistrer. * * * @@ -254,9 +228,9 @@ GArchOperand *g_target_operand_new(MemoryDataSize size, const vmpa2t *addr) * * ******************************************************************************/ -static bool g_target_operand_do_init(GTargetOperand *operand, const GTargetOperand *template) +static bool g_target_operand_apply_template(GTargetOperand *operand, const GTargetOperand *template) { - g_target_operand_quickly_copy(template, operand); + g_target_operand_define_template(template, operand); if (operand->symbol != NULL) g_object_ref(G_OBJECT(operand->symbol)); @@ -279,7 +253,7 @@ static bool g_target_operand_do_init(GTargetOperand *operand, const GTargetOpera * * ******************************************************************************/ -static void g_target_operand_quickly_copy(const GTargetOperand *operand, GTargetOperand *template) +static void g_target_operand_define_template(const GTargetOperand *operand, GTargetOperand *template) { template->size = operand->size; copy_vmpa(&template->addr, &operand->addr); @@ -303,52 +277,47 @@ static void g_target_operand_quickly_copy(const GTargetOperand *operand, GTarget * * ******************************************************************************/ -static int g_target_operand_compare(const GTargetOperand * const *a, const GTargetOperand * const *b) +static int g_target_operand_compare(const GTargetOperand *a, const GTargetOperand *b) { int result; /* Bilan à retourner */ - const GTargetOperand *target_a; /* Accès simplifié à A */ - const GTargetOperand *target_b; /* Accès simplifié à B */ - target_a = *a; - target_b = *b; - - result = cmp_vmpa(&target_a->addr, &target_b->addr); + result = cmp_vmpa(&a->addr, &b->addr); if (result != 0) goto gtoc_done; - if (target_a->size < target_b->size) + if (a->size < b->size) { result = -1; goto gtoc_done; } - else if (target_a->size > target_b->size) + else if (a->size > b->size) { result = 1; goto gtoc_done; } - if (target_a->symbol == NULL && target_b->symbol != NULL) + if (a->symbol == NULL && b->symbol != NULL) { result = -1; goto gtoc_done; } - else if (target_a->symbol != NULL && target_b->symbol == NULL) + else if (a->symbol != NULL && b->symbol == NULL) { result = 1; goto gtoc_done; } - else if (target_a->symbol != NULL && target_b->symbol != NULL) + else if (a->symbol != NULL && b->symbol != NULL) { - result = g_binary_symbol_cmp((const GBinSymbol * []) { target_a->symbol }, - (const GBinSymbol * []) { target_b->symbol }); + result = g_binary_symbol_cmp((const GBinSymbol * []) { a->symbol }, + (const GBinSymbol * []) { b->symbol }); if (result != 0) goto gtoc_done; } - if (target_a->diff < target_b->diff) + if (a->diff < b->diff) { result = -1; goto gtoc_done; } - else if (target_a->diff > target_b->diff) + else if (a->diff > b->diff) { result = 1; goto gtoc_done; @@ -419,6 +388,36 @@ static void g_target_operand_print(const GTargetOperand *operand, GBufferLine *l /****************************************************************************** * * +* Paramètres : size = taille des adresse mémoire virtuelles. * +* addr = localisation d'un élément à retrouver. * +* * +* Description : Crée un opérande réprésentant une valeur numérique. * +* * +* Retour : Instruction mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_target_operand_new(MemoryDataSize size, const vmpa2t *addr) +{ + GArchOperand *result; /* Opérande à retourner */ + GTargetOperand fake; /* Transport d'informations */ + + g_target_operand_init(&fake); + + fake.size = size; + copy_vmpa(&fake.addr, addr); + + result = G_ARCH_OPERAND(g_share_manager_build(_target_operand_manager, (GSharedInstance *)&fake)); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à consulter. * * binary = informations relatives au binaire chargé. * * * @@ -545,7 +544,7 @@ bool g_target_operand_resolve(GTargetOperand **operand, GBinFormat *format, bool { bool result; /* Bilan à retourner */ GSharedInstance *shared; /* Instace de travail partagée */ - GTargetOperand fake; /* Transport d'informations */ + GTargetOperand template; /* Transport d'informations */ GBinSymbol *symbol; /* Facilités d'accès au symbole*/ SymbolType stype; /* Type de symbole trouvé */ const mrange_t *range; /* Couverture du symbole */ @@ -553,14 +552,14 @@ bool g_target_operand_resolve(GTargetOperand **operand, GBinFormat *format, bool shared = G_SHARED_INSTANCE(*operand); - g_shared_instance_quickly_copy(shared, (GSharedInstance *)&fake); + g_shared_instance_define_template(shared, (GSharedInstance *)&template); - result = g_binary_format_resolve_symbol(format, &fake.addr, strict, &fake.symbol, &fake.diff); + result = g_binary_format_resolve_symbol(format, &template.addr, strict, &template.symbol, &template.diff); - shared = g_share_manager_update(_target_operand_manager, shared, (GSharedInstance *)&fake, container); + shared = g_share_manager_update(_target_operand_manager, shared, (GSharedInstance *)&template, container); - if (fake.symbol != NULL) - g_object_unref(G_OBJECT(fake.symbol)); + if (template.symbol != NULL) + g_object_unref(G_OBJECT(template.symbol)); *operand = G_TARGET_OPERAND(shared); @@ -647,6 +646,25 @@ GBinSymbol *g_target_operand_get_symbol(const GTargetOperand *operand, phys_t *d * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_target_operand_share_manager(void) +{ + return _target_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Initialise les mécanismes de partage d'opérandes de ciblage. * * * * Retour : Bilan de l'opération. * diff --git a/src/common/sort.c b/src/common/sort.c index 7da9a29..014d6c7 100644 --- a/src/common/sort.c +++ b/src/common/sort.c @@ -35,6 +35,37 @@ * Paramètres : a = premier élément à consulter et comparer. * * b = second élément à consulter et comparer. * * * +* Description : Compare un booléen avec une autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int sort_boolean(bool a, bool b) +{ + int result; /* Bilan à renvoyer */ + + if (a && !b) + result = 1; + + else if (!a && b) + result = -1; + + else + result = 0; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier élément à consulter et comparer. * +* b = second élément à consulter et comparer. * +* * * Description : Compare une valeur avec une autre. * * * * Retour : Bilan de la comparaison. * @@ -63,6 +94,41 @@ int sort_unsigned_long(unsigned long a, unsigned long b) /****************************************************************************** * * +* Paramètres : a = premier élément à consulter et comparer. * +* b = second élément à consulter et comparer. * +* compar = méthode de comparaison entre éléments. * +* * +* Description : Compare un pointeur avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int sort_pointer(const void *a, const void *b, __compar_fn_t compar) +{ + int result; /* Bilan à renvoyer */ + + if (a != NULL && b == NULL) + result = 1; + + else if (a == NULL && b != NULL) + result = -1; + + else if (a == NULL && b == NULL) + result = 0; + + else + result = compar(a, b); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : key = élément de comparaison à retrouver ou approcher. * * base = adresse du tableau à parcourir. * * nmemb = nombre d'éléments présents au total. * diff --git a/src/common/sort.h b/src/common/sort.h index fb47a5e..a887543 100644 --- a/src/common/sort.h +++ b/src/common/sort.h @@ -30,9 +30,15 @@ +/* Compare un booléen avec une autre. */ +int sort_boolean(bool, bool); + /* Compare une valeur avec une autre. */ int sort_unsigned_long(unsigned long, unsigned long); +/* Compare un pointeur avec un autre. */ +int sort_pointer(const void *, const void *, __compar_fn_t); + /* Effectue une recherche dichotomique dans un tableau. */ bool bsearch_index(const void *, const void *, size_t, size_t, __compar_fn_t, size_t *); diff --git a/src/core/processors.c b/src/core/processors.c index 6de2c09..d968d4f 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -31,6 +31,7 @@ #include "../arch/immediate.h" #include "../arch/target.h" +#include "../arch/register.h" #include "../arch/arm/v7/core.h" #include "../arch/arm/v7/processor.h" #include "../arch/dalvik/core.h" @@ -145,6 +146,7 @@ bool load_hard_coded_processors_definitions(void) result = init_imm_operand_sharing(); result &= init_target_operand_sharing(); + result &= init_register_operand_sharing(); result &= register_processor_type("armv7", "ARM v7", G_TYPE_ARMV7_PROCESSOR, #ifdef DEBUG_DUMP_STATS @@ -197,6 +199,7 @@ void unload_processors_definitions(void) _processors_definitions = NULL; _processors_definitions_count = 0; + exit_register_operand_sharing(); exit_target_operand_sharing(); exit_imm_operand_sharing(); -- cgit v0.11.2-87-g4458