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.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/plugins/pychrysalide/arch/operands/register.c b/plugins/pychrysalide/arch/operands/register.c
index 300fd99..ac91945 100644
--- a/plugins/pychrysalide/arch/operands/register.c
+++ b/plugins/pychrysalide/arch/operands/register.c
@@ -37,6 +37,7 @@
#include "../register.h"
#include "../../access.h"
#include "../../helpers.h"
+#include "../../glibext/bufferline.h"
@@ -57,6 +58,12 @@ 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 *);
@@ -220,6 +227,98 @@ 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. *
* *
@@ -317,6 +416,8 @@ static PyObject *py_register_operand_is_written(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 }
};
@@ -384,3 +485,48 @@ bool ensure_python_register_operand_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en opérande de registre. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_register_operand(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_register_operand_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to register operand");
+ break;
+
+ case 1:
+ *((GRegisterOperand **)dst) = G_REGISTER_OPERAND(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}