diff options
Diffstat (limited to 'src/arch/dalvik/operands/args.c')
| -rw-r--r-- | src/arch/dalvik/operands/args.c | 222 | 
1 files changed, 214 insertions, 8 deletions
| diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c index 6e1725c..9e75604 100644 --- a/src/arch/dalvik/operands/args.c +++ b/src/arch/dalvik/operands/args.c @@ -24,13 +24,18 @@  #include "args.h" +#include <assert.h>  #include <malloc.h>  #include "../../operand-int.h" +#include "../../sharing/manager.h" +/* --------------------- MANIPULATION D'OPERANDES INDIVIDUELLES --------------------- */ + +  /* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */  struct _GDalvikArgsOperand  { @@ -62,11 +67,33 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *);  /* Procède à la libération totale de la mémoire. */  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 *); + +/* Indique l'objet partagé correspond à une description donnée. */ +static gboolean g_dalvik_args_operand_compare_info(const GDalvikArgsOperand *, const GDalvikArgsOperand *); + +/* Compare un opérande avec un autre. */ +static bool 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); +/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */ + + +/* Gestionnaire des partages d'instances */ +static GShareManager *_dalvik_args_operand_manager = NULL; + + + +/* ---------------------------------------------------------------------------------- */ +/*                       MANIPULATION D'OPERANDES INDIVIDUELLES                       */ +/* ---------------------------------------------------------------------------------- */ + +  /* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */  G_DEFINE_TYPE(GDalvikArgsOperand, g_dalvik_args_operand, G_TYPE_ARCH_OPERAND); @@ -94,6 +121,10 @@ 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 = (init_shared_fc)g_dalvik_args_operand_do_init; +    operand->cmp_info = (compare_shared_info_fc)g_dalvik_args_operand_compare_info; + +    operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare;      operand->print = (operand_print_fc)g_dalvik_args_operand_print;  } @@ -174,11 +205,107 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand)  GArchOperand *g_dalvik_args_operand_new(void)  { -    GDalvikArgsOperand *result;             /* Structure à retourner       */ +    GArchOperand *result;                   /* Structure à retourner       */ + +    result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_args_operand_manager, NULL)); + +    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_args_operand_do_init(GDalvikArgsOperand *operand, const GDalvikArgsOperand *fake) +{ +    size_t i;                               /* Boucle de parcours          */ + +    if (fake == NULL) +    { +        operand->args = NULL; +        operand->count = 0; +    } + +    else +    { +        operand->args = (GArchOperand **)calloc(fake->count, sizeof(GArchOperand *)); + +        for (i = 0; i < fake->count; i++) +            operand->args[i] = fake->args[i]; + +    } + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = objet partagé à consulter.                         * +*                fake    = coquille vide contenant les infos à comparer.      * +*                                                                             * +*  Description : Indique l'objet partagé correspond à une description donnée. * +*                                                                             * +*  Retour      : TRUE si les détails centraux sont partagés, FALSE sinon.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static gboolean g_dalvik_args_operand_compare_info(const GDalvikArgsOperand *operand, const GDalvikArgsOperand *fake) +{ +    gboolean result;                        /* Bilan à retourner           */ + +    result = g_dalvik_args_operand_compare(operand, fake); + +    return 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 bool g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b) +{ +    bool result;                            /* Bilan à renvoyer            */ +    size_t i;                               /* Boucle de parcours          */ + +    if (b == NULL) +        result = (a->count == 0); -    result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL); +    else +    { +        result = (a->count == b->count); + +        for (i = 0; i < a->count && result; i++) +            result = g_arch_operand_compare(a->args[i], b->args[i]); + +    } -    return G_ARCH_OPERAND(result); +    return result;  } @@ -236,12 +363,25 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *operand, GBuff  *                                                                             *  ******************************************************************************/ -void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg) +GDalvikArgsOperand *g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg, GShareContainer *container)  { -    operand->args = (GArchOperand **)realloc(operand->args, -                                             ++operand->count * sizeof(GArchOperand *)); +    GSharedInstance *result;                /* Nouvelle version à renvoyer */ +    GDalvikArgsOperand fake;                /* Transport d'informations    */ +    size_t i;                               /* Boucle de parcours          */ + +    fake.count = operand->count + 1; +    fake.args = (GArchOperand **)calloc(fake.count, sizeof(GArchOperand *)); + +    for (i = 0; i < operand->count; i++) +        fake.args[i] = operand->args[i]; -    operand->args[operand->count - 1] = arg; +    fake.args[i] = arg; + +    result = g_share_manager_update(_dalvik_args_operand_manager, G_SHARED_INSTANCE(operand), &fake, container); + +    free(fake.args); + +    return G_DALVIK_ARGS_OPERAND(result);  } @@ -280,8 +420,74 @@ size_t g_dalvik_args_count(const GDalvikArgsOperand *operand)  GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_t index)  { -    /* BUG_ON(index >= operand->count) */ +    assert(index < operand->count);      return operand->args[index];  } + + + +/* ---------------------------------------------------------------------------------- */ +/*                            PARTAGES DE CONTENUS UNIQUES                            */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Met en place les mécanismes de partage des opérandes Dalvik. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool init_dalvik_args_operand_sharing(void) +{ +    _dalvik_args_operand_manager = g_share_manager_new(G_TYPE_DALVIK_ARGS_OPERAND); + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Imprime des statistiques quant aux partages dans l'archi.    * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void dump_dalvik_args_operand_share_stats(void) +{ +    g_share_manager_dump_stats(_dalvik_args_operand_manager); + +} +#endif + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Supprime les mécanismes de partage des opérandes Dalvik.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void exit_dalvik_args_operand_sharing(void) +{ +    g_object_unref(G_OBJECT(_dalvik_args_operand_manager)); + +} | 
