diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
commit | acd355c4c5ae25fb9cac64b8dc17407a2bcc979b (patch) | |
tree | d5b43201049116cd9734ff554e61ed8a7e0084cc /src/arch/arm/v7/operands/reglist.c | |
parent | 4691a434a34a19317156a761967f719e408b73bb (diff) |
Refined the whole share system for operands.
Diffstat (limited to 'src/arch/arm/v7/operands/reglist.c')
-rw-r--r-- | src/arch/arm/v7/operands/reglist.c | 271 |
1 files changed, 264 insertions, 7 deletions
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)); + +} |