summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/operands/register.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/operands/register.c')
-rw-r--r--plugins/pychrysalide/arch/operands/register.c196
1 files changed, 5 insertions, 191 deletions
diff --git a/plugins/pychrysalide/arch/operands/register.c b/plugins/pychrysalide/arch/operands/register.c
index 2a48a0f..707524a 100644
--- a/plugins/pychrysalide/arch/operands/register.c
+++ b/plugins/pychrysalide/arch/operands/register.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* register.c - équivalent Python du fichier "arch/operands/register.c"
*
- * Copyright (C) 2019-2020 Cyrille Bagard
+ * Copyright (C) 2019-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -30,25 +30,19 @@
#include <i18n.h>
#include <arch/operands/register-int.h>
-#include <plugins/dt.h>
#include "../operand.h"
#include "../register.h"
#include "../../access.h"
#include "../../helpers.h"
-#include "../../glibext/bufferline.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_register_operand_new(PyTypeObject *, PyObject *, PyObject *);
-
-/* Initialise la classe des descriptions de fichier binaire. */
-static void py_register_operand_init_gclass(GRegisterOperandClass *, gpointer);
+CREATE_DYN_CONSTRUCTOR(register_operand, G_TYPE_REGISTER_OPERAND);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_register_operand_init(PyObject *, PyObject *, PyObject *);
@@ -58,12 +52,6 @@ static int py_register_operand_init(PyObject *, PyObject *, PyObject *);
/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
-/* Compare un opérande avec un autre. */
-static PyObject *py_register_operand___cmp__(PyObject *, PyObject *);
-
-/* Traduit un opérande en version humainement lisible. */
-static PyObject *py_register_operand__print(PyObject *, PyObject *);
-
/* Fournit le registre associé à l'opérande. */
static PyObject *py_register_operand_get_register(PyObject *, void *);
@@ -76,86 +64,6 @@ static PyObject *py_register_operand_get_register(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_register_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_register_operand_type();
-
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_REGISTER_OPERAND, type->tp_name,
- (GClassInitFunc)py_register_operand_init_gclass, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- simple_way:
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
-* *
-* Description : Initialise la classe des descriptions de fichier binaire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void py_register_operand_init_gclass(GRegisterOperandClass *class, gpointer unused)
-{
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -182,7 +90,7 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
"\n" \
" RegisterOperand(reg)" \
"\n" \
- "Where reg is an architecture register defined from a subclass of" \
+ "Where *reg* is an architecture register defined from a subclass of" \
" pychrysalide.arch.ArchRegister."
/* Récupération des paramètres */
@@ -199,8 +107,8 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
operand = G_REGISTER_OPERAND(pygobject_get(self));
- g_object_ref(G_OBJECT(reg));
- operand->reg = reg;
+ if (!g_register_operand_create(operand, reg))
+ return -1;
return 0;
@@ -215,98 +123,6 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
/******************************************************************************
* *
-* Paramètres : self = serveur à manipuler. *
-* args = arguments associés à l'appel. *
-* *
-* Description : Compare un opérande avec un autre. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_register_operand___cmp__(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Bilan à retourner */
- GRegisterOperand *other; /* Autre opérande à manipuler */
- int ret; /* Bilan de lecture des args. */
- GRegisterOperand *operand; /* Elément à manipuler */
- int status; /* Bilan de comparaison */
-
-#define REGISTER_OPERAND_CMP_METHOD PYTHON_METHOD_DEF \
-( \
- __cmp__, "$self, other, /", \
- METH_VARARGS, py_register_operand, \
- "Implementation of the required method used to compare the" \
- " operand with another one. This second object is always" \
- " a pychrysalide.arch.RegisterOperand instance.\n" \
- "\n" \
- "See the parent class for more information about this method." \
-)
-
- ret = PyArg_ParseTuple(args, "O&", convert_to_register_operand, &other);
- if (!ret) return NULL;
-
- operand = G_REGISTER_OPERAND(pygobject_get(self));
-
- status = g_arch_operand_compare(G_ARCH_OPERAND(operand), G_ARCH_OPERAND(other));
-
- result = PyLong_FromLong(status);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = serveur à manipuler. *
-* args = arguments associés à l'appel. *
-* *
-* Description : Traduit un opérande en version humainement lisible. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_register_operand__print(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Bilan à retourner */
- GBufferLine *line; /* Ligne fournie à peupler */
- int ret; /* Bilan de lecture des args. */
- GRegisterOperand *operand; /* Elément à manipuler */
-
-#define REGISTER_OPERAND_PRINT_METHOD PYTHON_METHOD_DEF \
-( \
- _print, "$self, line, /", \
- METH_VARARGS, py_register_operand, \
- "Implementation of the required method used to print the operand" \
- " into a rendering line, which is a provided" \
- " pychrysalide.glibext.BufferLine instance.\n" \
- "\n" \
- "See the parent class for more information about this method." \
-)
-
- ret = PyArg_ParseTuple(args, "O&", convert_to_buffer_line, &line);
- if (!ret) return NULL;
-
- operand = G_REGISTER_OPERAND(pygobject_get(self));
-
- g_arch_operand_print(G_ARCH_OPERAND(operand), line);
-
- result = Py_None;
- Py_INCREF(result);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -367,8 +183,6 @@ static PyObject *py_register_operand_get_register(PyObject *self, void *closure)
PyTypeObject *get_python_register_operand_type(void)
{
static PyMethodDef py_register_operand_methods[] = {
- REGISTER_OPERAND_CMP_METHOD,
- REGISTER_OPERAND_PRINT_METHOD,
{ NULL }
};