summaryrefslogtreecommitdiff
path: root/src/arch/immediate.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-01-16 21:12:08 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-01-16 21:12:08 (GMT)
commit52ac5b1b340335f56ceb599dba63164a26f10b10 (patch)
tree275104896dffa65e7887284857fa8fed831e9ea8 /src/arch/immediate.c
parent2ddb5c26af896b10517a89abf0c9498c598b7697 (diff)
Changed the display of a segment containing the value of an immediate.
Diffstat (limited to 'src/arch/immediate.c')
-rw-r--r--src/arch/immediate.c86
1 files changed, 80 insertions, 6 deletions
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index 4c9ea84..288b364 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -24,6 +24,7 @@
#include "immediate.h"
+#include <assert.h>
#include <inttypes.h>
#include <malloc.h>
#include <stdarg.h>
@@ -71,6 +72,7 @@ struct _GImmOperand
} signed_imm;
bool zpad; /* Ajoute des 0 à l'impression */
+ ImmOperandDisplay def_display; /* Type par défaut d'affichage */
ImmOperandDisplay display; /* Format général d'affichage */
};
@@ -81,6 +83,11 @@ struct _GImmOperandClass
{
GArchOperandClass parent; /* Classe parente */
+ /* Signaux */
+
+ void (* value_changed) (GImmOperand *);
+ void (* output_changed) (GImmOperand *);
+
};
@@ -96,9 +103,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 *);
-/* Construit la chaîne de caractères correspondant à l'opérande. */
-static size_t g_imm_operand_to_string(const GImmOperand *, AsmSyntax, char [VMPA_MAX_SIZE]);
-
/* Traduit un opérande en version humainement lisible. */
static void g_imm_operand_print(const GImmOperand *, GBufferLine *, AsmSyntax);
@@ -134,6 +138,22 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
operand->print = (operand_print_fc)g_imm_operand_print;
+ g_signal_new("value-changed",
+ G_TYPE_IMM_OPERAND,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GImmOperandClass, value_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_signal_new("output-changed",
+ G_TYPE_IMM_OPERAND,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GImmOperandClass, output_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
}
@@ -575,6 +595,8 @@ bool g_imm_operand_set_value(GImmOperand *operand, MemoryDataSize size, uint64_t
operand->size = size;
operand->raw = value;
+ g_signal_emit_by_name(operand, "value-changed");
+
return true;
}
@@ -597,6 +619,8 @@ void g_imm_operand_pad(GImmOperand *operand, bool state)
{
operand->zpad = state;
+ g_signal_emit_by_name(operand, "output-changed");
+
}
@@ -621,6 +645,45 @@ bool g_imm_operand_does_padding(const GImmOperand *operand)
/******************************************************************************
* *
+* Paramètres : operand = structure dont le contenu par défaut est à définir.*
+* display = format global d'un affichage de valeur. *
+* *
+* Description : Définit le format textuel par défaut de la valeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_imm_operand_set_default_display(GImmOperand *operand, ImmOperandDisplay display)
+{
+ operand->def_display = display;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = structure dont le contenu est à consulter. *
+* *
+* Description : Indique le format textuel par défaut de la valeur. *
+* *
+* Retour : Format global d'un affichage de valeur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+ImmOperandDisplay g_imm_operand_get_default_display(const GImmOperand *operand)
+{
+ return operand->def_display;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = structure dont le contenu est à définir. *
* display = format global d'un affichage de valeur. *
* *
@@ -636,6 +699,8 @@ void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display)
{
operand->display = display;
+ g_signal_emit_by_name(operand, "output-changed");
+
}
@@ -730,13 +795,14 @@ bool g_imm_operand_is_null(const GImmOperand *operand)
* *
******************************************************************************/
-static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, char value[VMPA_MAX_SIZE])
+size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, char value[IMM_MAX_SIZE])
{
size_t result; /* Longueur à retourner */
unsigned int range; /* Catégorie de la taille */
const char *prefix; /* Entrée en matière */
const char *suffix; /* Sortie de matière */
const char *alternate; /* Préfixe de forme alternative*/
+ const char *intro; /* Introduction du formatage */
const char *zpad; /* Remplissage par des zéros */
const char *lmod; /* Modification de longueur */
const char *conv; /* Opérateur de conversion */
@@ -783,6 +849,12 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt
break;
}
+ /* Va-t-on réellement avoir besoin d'un formatage ? */
+ if (operand->display != IOD_BIN)
+ intro = "%";
+ else
+ intro = "";
+
/* Drapeau de remplissage ? */
switch (operand->display)
{
@@ -838,7 +910,7 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt
/* Impression finale */
- snprintf(format, sizeof(format), "%s%s%%%s%s%s%s", prefix, alternate, zpad, lmod, conv, suffix);
+ snprintf(format, sizeof(format), "%s%s%s%s%s%s%s", prefix, alternate, intro, zpad, lmod, conv, suffix);
switch (operand->size)
{
@@ -888,6 +960,8 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt
}
+ assert(((int)result) > 0);
+
return result;
}
@@ -909,7 +983,7 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt
static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, AsmSyntax syntax)
{
- char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */
+ char value[IMM_MAX_SIZE]; /* Chaîne à imprimer */
size_t len; /* Taille de l'élément inséré */
GBufferSegment *segment; /* Nouveau segment mis en place*/