summaryrefslogtreecommitdiff
path: root/src/arch/immediate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/immediate.c')
-rw-r--r--src/arch/immediate.c296
1 files changed, 47 insertions, 249 deletions
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index 9c807db..25630bf 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -38,16 +38,12 @@
#include "operand-int.h"
-#include "sharing/manager.h"
#include "../common/asm.h"
#include "../common/extstr.h"
#include "../format/format.h"
-/* ------------------ MANIPULATION D'OPERANDES DE VALEUR IMMEDIATE ------------------ */
-
-
/* Définition d'un opérande de valeur numérique (instance) */
struct _GImmOperand
{
@@ -96,9 +92,6 @@ static void g_imm_operand_dispose(GImmOperand *);
/* Procède à la libération totale de la mémoire. */
static void g_imm_operand_finalize(GImmOperand *);
-/* Réalise une copie minimale d'un contenu partagé. */
-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 GImmOperand *);
@@ -116,23 +109,6 @@ static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinar
-/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */
-
-
-/* Gestionnaire des partages d'instances */
-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 */
-/* ---------------------------------------------------------------------------------- */
-
-
/* Indique le type défini pour un opérande de valeur numérique. */
G_DEFINE_TYPE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND);
@@ -161,12 +137,6 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
object->dispose = (GObjectFinalizeFunc/* ! */)g_imm_operand_dispose;
object->finalize = (GObjectFinalizeFunc)g_imm_operand_finalize;
- 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;
operand->build_tooltip = (operand_build_tooltip_fc)g_imm_operand_build_tooltip;
@@ -252,8 +222,7 @@ static void g_imm_operand_finalize(GImmOperand *operand)
GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian)
{
- GArchOperand *result; /* Opérande à retourner */
- GImmOperand fake; /* Transport d'informations */
+ GImmOperand *result; /* Opérande à retourner */
uint8_t uval8; /* Valeur sur 8 bits */
uint16_t uval16; /* Valeur sur 16 bits */
uint32_t uval32; /* Valeur sur 32 bits */
@@ -263,70 +232,70 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten
int32_t sval32; /* Valeur sur 32 bits */
int64_t sval64; /* Valeur sur 64 bits */
- g_imm_operand_init(&fake);
+ result = g_object_new(G_TYPE_IMM_OPERAND, NULL);
- fake.size = size;
+ result->size = size;
switch (size)
{
case MDS_4_BITS_UNSIGNED:
if (!g_binary_content_read_u4(content, addr, low, &uval8))
goto gionfd_error;
- fake.raw = uval8;
+ result->raw = uval8;
break;
case MDS_8_BITS_UNSIGNED:
if (!g_binary_content_read_u8(content, addr, &uval8))
goto gionfd_error;
- fake.raw = uval8;
+ result->raw = uval8;
break;
case MDS_16_BITS_UNSIGNED:
if (!g_binary_content_read_u16(content, addr, endian, &uval16))
goto gionfd_error;
- fake.raw = uval16;
+ result->raw = uval16;
break;
case MDS_32_BITS_UNSIGNED:
if (!g_binary_content_read_u32(content, addr, endian, &uval32))
goto gionfd_error;
- fake.raw = uval32;
+ result->raw = uval32;
break;
case MDS_64_BITS_UNSIGNED:
if (!g_binary_content_read_u64(content, addr, endian, &uval64))
goto gionfd_error;
- fake.raw = uval64;
+ result->raw = uval64;
break;
case MDS_4_BITS_SIGNED:
if (!g_binary_content_read_s4(content, addr, low, &sval8))
goto gionfd_error;
- fake.raw = sval8;
+ result->raw = sval8;
break;
case MDS_8_BITS_SIGNED:
if (!g_binary_content_read_s8(content, addr, &sval8))
goto gionfd_error;
- fake.raw = sval8;
+ result->raw = sval8;
break;
case MDS_16_BITS_SIGNED:
if (!g_binary_content_read_s16(content, addr, endian, &sval16))
goto gionfd_error;
- fake.raw = sval16;
+ result->raw = sval16;
break;
case MDS_32_BITS_SIGNED:
if (!g_binary_content_read_s32(content, addr, endian, &sval32))
goto gionfd_error;
- fake.raw = sval32;
+ result->raw = sval32;
break;
case MDS_64_BITS_SIGNED:
if (!g_binary_content_read_s64(content, addr, endian, &sval64))
goto gionfd_error;
- fake.raw = sval64;
+ result->raw = sval64;
break;
case MDS_UNDEFINED:
@@ -335,12 +304,12 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten
}
- result = G_ARCH_OPERAND(g_share_manager_build(_imm_operand_manager, (GSharedInstance *)&fake));
-
- return result;
+ return G_ARCH_OPERAND(result);
gionfd_error:
+ g_object_unref(G_OBJECT(result));
+
return NULL;
}
@@ -361,49 +330,21 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten
GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, uint64_t value)
{
- GArchOperand *result; /* Opérande à retourner */
- GImmOperand fake; /* Transport d'informations */
+ GImmOperand *result; /* Opérande à retourner */
if (size == MDS_UNDEFINED)
result = NULL;
else
{
- g_imm_operand_init(&fake);
-
- fake.size = size;
- fake.raw = value;
+ result = g_object_new(G_TYPE_IMM_OPERAND, NULL);
- result = G_ARCH_OPERAND(g_share_manager_build(_imm_operand_manager, (GSharedInstance *)&fake));
+ result->size = size;
+ result->raw = value;
}
- return 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_imm_operand_define_template(const GImmOperand *operand, GImmOperand *template)
-{
- template->raw = operand->raw;
- template->size = operand->size;
-
- template->def_display = operand->def_display;
- template->display = operand->display;
- template->misc = operand->misc;
+ return (result != NULL ? G_ARCH_OPERAND(result) : NULL);
}
@@ -627,12 +568,12 @@ uint64_t g_imm_operand_get_raw_value(const GImmOperand *operand)
}
+
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT]*
-* size = taille de l'opérande souhaitée. *
-* value = valeur sur x bits à venir récupérer. *
-* container = propriétaire d'origine à tenir au courant. *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* size = taille de l'opérande souhaitée. *
+* value = valeur sur x bits à venir récupérer. *
* *
* Description : Définit la nouvelle valeur de l'opérande à une valeur. *
* *
@@ -642,32 +583,20 @@ 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)
+void g_imm_operand_set_value(GImmOperand *operand, MemoryDataSize size, uint64_t value)
{
- GSharedInstance *shared; /* Instace de travail partagée */
- GImmOperand template; /* Transport d'informations */
-
assert(size != MDS_UNDEFINED);
- shared = G_SHARED_INSTANCE(*operand);
-
- g_shared_instance_define_template(shared, (GSharedInstance *)&template);
-
- template.size = size;
- template.raw = value;
-
- shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container);
-
- *operand = G_IMM_OPERAND(shared);
+ operand->size = size;
+ operand->raw = value;
}
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT]*
-* state = true si des zéro sont à ajouter, false sinon. *
-* container = propriétaire d'origine à tenir au courant. *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* state = true si des zéro sont à ajouter, false sinon. *
* *
* Description : Précise si des zéro doivent compléter l'affichage ou non. *
* *
@@ -677,20 +606,9 @@ void g_imm_operand_set_value(GImmOperand **operand, MemoryDataSize size, uint64_
* *
******************************************************************************/
-void g_imm_operand_pad_by_default(GImmOperand **operand, bool state, GShareContainer *container)
+void g_imm_operand_pad_by_default(GImmOperand *operand, bool state)
{
- GSharedInstance *shared; /* Instace de travail partagée */
- GImmOperand template; /* Transport d'informations */
-
- shared = G_SHARED_INSTANCE(*operand);
-
- g_shared_instance_define_template(shared, (GSharedInstance *)&template);
-
- IMM_SET_DEF_ZERO_PADDING(&template, state);
-
- shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container);
-
- *operand = G_IMM_OPERAND(shared);
+ IMM_SET_DEF_ZERO_PADDING(operand, state);
}
@@ -717,11 +635,11 @@ bool g_imm_operand_does_padding_by_default(const GImmOperand *operand)
}
+
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT]*
-* state = true si des zéro sont à ajouter, false sinon. *
-* container = propriétaire d'origine à tenir au courant. *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* state = true si des zéro sont à ajouter, false sinon. *
* *
* Description : Précise si des zéro doivent compléter l'affichage ou non. *
* *
@@ -731,21 +649,10 @@ bool g_imm_operand_does_padding_by_default(const GImmOperand *operand)
* *
******************************************************************************/
-void g_imm_operand_pad(GImmOperand **operand, bool state, GShareContainer *container)
+void g_imm_operand_pad(GImmOperand *operand, bool state)
{
- GSharedInstance *shared; /* Instace de travail partagée */
- GImmOperand template; /* Transport d'informations */
-
- shared = G_SHARED_INSTANCE(*operand);
-
- g_shared_instance_define_template(shared, (GSharedInstance *)&template);
-
- IMM_SET_ZERO_PADDING(&template);
- IMM_SET_ZERO_PADDING_VALUE(&template, state);
-
- shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container);
-
- *operand = G_IMM_OPERAND(shared);
+ IMM_SET_ZERO_PADDING(operand);
+ IMM_SET_ZERO_PADDING_VALUE(operand, state);
}
@@ -811,9 +718,8 @@ static bool g_imm_operand_does_padding_for_display(const GImmOperand *operand, I
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT]*
-* display = format global d'un affichage de valeur. *
-* container = propriétaire d'origine à tenir au courant. *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* display = format global d'un affichage de valeur. *
* *
* Description : Définit le format textuel par défaut de la valeur. *
* *
@@ -823,20 +729,9 @@ 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)
+void g_imm_operand_set_default_display(GImmOperand *operand, ImmOperandDisplay display)
{
- GSharedInstance *shared; /* Instace de travail partagée */
- GImmOperand template; /* Transport d'informations */
-
- shared = G_SHARED_INSTANCE(*operand);
-
- g_shared_instance_define_template(shared, (GSharedInstance *)&template);
-
- template.def_display = display;
-
- shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container);
-
- *operand = G_IMM_OPERAND(shared);
+ operand->def_display = display;
}
@@ -862,9 +757,8 @@ ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand)
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à actualiser. [OUT]*
-* display = format global d'un affichage de valeur. *
-* container = propriétaire d'origine à tenir au courant. *
+* Paramètres : operand = structure dont le contenu est à actualiser. [OUT] *
+* display = format global d'un affichage de valeur. *
* *
* Description : Définit la grande ligne du format textuel de la valeur. *
* *
@@ -874,21 +768,10 @@ ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand)
* *
******************************************************************************/
-void g_imm_operand_set_display(GImmOperand **operand, ImmOperandDisplay display, GShareContainer *container)
+void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display)
{
- GSharedInstance *shared; /* Instace de travail partagée */
- GImmOperand template; /* Transport d'informations */
-
- shared = G_SHARED_INSTANCE(*operand);
-
- g_shared_instance_define_template(shared, (GSharedInstance *)&template);
-
- IMM_SET_DISPLAY(&template);
- template.display = display;
-
- shared = g_share_manager_update(_imm_operand_manager, shared, (GSharedInstance *)&template, container);
-
- *operand = G_IMM_OPERAND(shared);
+ IMM_SET_DISPLAY(operand);
+ operand->display = display;
}
@@ -1474,88 +1357,3 @@ bool g_imm_operand_to_off_t(const GImmOperand *operand, off_t *value, bool *nega
return false;
}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* 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_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. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool init_imm_operand_sharing(void)
-{
- _imm_operand_manager = g_share_manager_new(G_TYPE_IMM_OPERAND);
-
- return true;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Imprime des statistiques quant aux partages dans l'archi. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-#ifdef DEBUG_DUMP_STATS
-void dump_imm_operand_share_stats(void)
-{
- g_share_manager_dump_stats(_imm_operand_manager);
-
-}
-#endif
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Supprime les mécanismes de partage des opérandes immédiates. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void exit_imm_operand_sharing(void)
-{
- g_object_unref(G_OBJECT(_imm_operand_manager));
-
-}