From a1d7bc97071a4d22bb633359c749e3de84682024 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 4 Feb 2020 22:51:50 +0100 Subject: Reduced the size required for register operands. --- plugins/pychrysalide/arch/operands/register.c | 41 ++++++++++++++++++++++++ src/arch/operands/register-int.h | 46 ++++++++++++++++++++++++++- src/arch/operands/register.c | 26 +++++++++++++-- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/plugins/pychrysalide/arch/operands/register.c b/plugins/pychrysalide/arch/operands/register.c index 1873d9c..300fd99 100644 --- a/plugins/pychrysalide/arch/operands/register.c +++ b/plugins/pychrysalide/arch/operands/register.c @@ -60,6 +60,9 @@ static int py_register_operand_init(PyObject *, PyObject *, PyObject *); /* Fournit le registre associé à l'opérande. */ static PyObject *py_register_operand_get_register(PyObject *, void *); +/* Indique le type d'accès réalisé sur l'opérande. */ +static PyObject *py_register_operand_is_written(PyObject *, void *); + /* ---------------------------------------------------------------------------------- */ @@ -264,6 +267,43 @@ static PyObject *py_register_operand_get_register(PyObject *self, void *closure) /****************************************************************************** * * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique le type d'accès réalisé sur l'opérande. * +* * +* Retour : Type d'accès : True en cas d'écriture, False sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_register_operand_is_written(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GRegisterOperand *operand; /* Version GLib du type */ + bool status; /* Statut de la ligne */ + +#define REGISTER_OPERAND_IS_WRITTEN_ATTRIB PYTHON_IS_DEF_FULL \ +( \ + written, py_register_operand, \ + "Kind of access for the register when its instruction is executed." \ +) + + operand = G_REGISTER_OPERAND(pygobject_get(self)); + + status = g_register_operand_is_written(operand); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -282,6 +322,7 @@ PyTypeObject *get_python_register_operand_type(void) static PyGetSetDef py_register_operand_getseters[] = { REGISTER_OPERAND_REGISTER_ATTRIB, + REGISTER_OPERAND_IS_WRITTEN_ATTRIB, { NULL } }; diff --git a/src/arch/operands/register-int.h b/src/arch/operands/register-int.h index c728be7..bf3e9d4 100644 --- a/src/arch/operands/register-int.h +++ b/src/arch/operands/register-int.h @@ -29,19 +29,63 @@ #include "../operand-int.h" +#include "../../glibext/objhole.h" +/* Informations glissées dans la structure GObject de GArchInstruction */ +typedef union _regop_obj_extra +{ + struct + { + bool is_written; /* Changement de contenu */ + + }; + + gint lock; /* Gestion d'accès aux fanions */ + +} regop_obj_extra; + /* Définition d'un opérande visant un registre (instance) */ struct _GRegisterOperand { GArchOperand parent; /* Instance parente */ GArchRegister *reg; /* Registre représenté */ - bool is_written; /* Changement de contenu */ + +#if __SIZEOF_INT__ == __SIZEOF_LONG__ + + /** + * L'inclusion des informations suivantes dépend de l'architecture. + * + * Si la structure GObject possède un trou, on remplit de préférence + * ce dernier. + */ + + regop_obj_extra extra; /* Externalisation embarquée */ + +#endif }; +/** + * Accès aux informations éventuellement déportées. + */ + +#if __SIZEOF_INT__ == __SIZEOF_LONG__ + +# define INIT_REG_OP_EXTRA(op) op->extra.lock = 0 + +# define GET_REG_OP_EXTRA(op) &op->extra + +#else + +# define INIT_REG_OP_EXTRA(op) INIT_GOBJECT_EXTRA(G_OBJECT(op)) + +# define GET_REG_OP_EXTRA(op) GET_GOBJECT_EXTRA(G_OBJECT(op), regop_obj_extra) + +#endif + /* Définition d'un opérande visant un registre (classe) */ struct _GRegisterOperandClass { diff --git a/src/arch/operands/register.c b/src/arch/operands/register.c index d755dbb..81608a3 100644 --- a/src/arch/operands/register.c +++ b/src/arch/operands/register.c @@ -121,7 +121,8 @@ static void g_register_operand_class_init(GRegisterOperandClass *klass) static void g_register_operand_init(GRegisterOperand *operand) { operand->reg = NULL; - operand->is_written = false; + + INIT_REG_OP_EXTRA(operand); } @@ -250,7 +251,15 @@ GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand) void g_register_operand_mark_as_written(GRegisterOperand *operand) { - operand->is_written = true; + regop_obj_extra *extra; /* Données insérées à modifier */ + + extra = GET_REG_OP_EXTRA(operand); + + g_bit_lock(&extra->lock, HOLE_LOCK_BIT); + + extra->is_written = true; + + g_bit_unlock(&extra->lock, HOLE_LOCK_BIT); } @@ -269,7 +278,18 @@ void g_register_operand_mark_as_written(GRegisterOperand *operand) bool g_register_operand_is_written(const GRegisterOperand *operand) { - return operand->is_written; + bool result; /* Statut à retourner */ + regop_obj_extra *extra; /* Données insérées à modifier */ + + extra = GET_REG_OP_EXTRA(operand); + + g_bit_lock(&extra->lock, HOLE_LOCK_BIT); + + result = extra->is_written; + + g_bit_unlock(&extra->lock, HOLE_LOCK_BIT); + + return result; } -- cgit v0.11.2-87-g4458