mirror of
https://github.com/Decompollaborate/rabbitizer.git
synced 2025-02-06 03:39:56 +00:00
Change how instr_id is exposed to python
This commit is contained in:
parent
b561f3f4b9
commit
edc2fe221e
40
rabbitizer/rabbitizer_global_instr_id.c
Normal file
40
rabbitizer/rabbitizer_global_instr_id.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
/**
|
||||
* Wrapper to expose the enums of instructions/RabbitizerInstrId.h
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "structmember.h"
|
||||
|
||||
#include "instructions/RabbitizerInstrId.h"
|
||||
|
||||
static PyObject *rabbitizer_global_instr_id_get_closure_id(PyObject *self, RabbitizerInstrId closure) {
|
||||
(void)self;
|
||||
return PyLong_FromLong(closure);
|
||||
}
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) \
|
||||
{ #prefix "_" #name, (getter) rabbitizer_global_instr_id_get_closure_id, (setter) NULL, "", (void*)RABBITIZER_INSTR_ID_##prefix##_##name }
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) \
|
||||
{ #prefix "_" #name, (getter) rabbitizer_global_instr_id_get_closure_id, (setter) NULL, "", (void*)RABBITIZER_INSTR_ID_##prefix##_##name }
|
||||
|
||||
|
||||
static PyGetSetDef rabbitizer_global_instr_id_GetSets[] = {
|
||||
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
PyTypeObject rabbitizer_global_instr_id_TypeObject = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "rabbitizer.instr_id",
|
||||
.tp_doc = PyDoc_STR(""),
|
||||
.tp_basicsize = sizeof(PyObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_new = PyType_GenericNew,
|
||||
.tp_getset = rabbitizer_global_instr_id_GetSets,
|
||||
};
|
@ -29,12 +29,12 @@ typedef struct ModuleAttribute {
|
||||
|
||||
#define MODULE_ATTRIBUTE_TYPE(name) { {.type = &rabbitizer_type_##name##_TypeObject}, MODULE_ATTRIBUTE_CAT_TYPE, #name, false, NULL }
|
||||
#define MODULE_ATTRIBUTE_INIT(name) { {.init = rabbitizer_submodule_##name##_Init}, MODULE_ATTRIBUTE_CAT_INIT, #name, false, NULL }
|
||||
#define MODULE_ATTRIBUTE_GLBOAL(name) { {.global = &rabbitizer_global_##name##_TypeObject}, MODULE_ATTRIBUTE_CAT_GLOBAL, #name, false, NULL }
|
||||
#define MODULE_ATTRIBUTE_GLOBAL(name) { {.global = &rabbitizer_global_##name##_TypeObject}, MODULE_ATTRIBUTE_CAT_GLOBAL, #name, false, NULL }
|
||||
|
||||
static ModuleAttributes rabbitizer_module_attributes[] = {
|
||||
MODULE_ATTRIBUTE_GLOBAL(config),
|
||||
MODULE_ATTRIBUTE_GLOBAL(instr_id),
|
||||
MODULE_ATTRIBUTE_TYPE(Instr),
|
||||
MODULE_ATTRIBUTE_INIT(instr_id),
|
||||
MODULE_ATTRIBUTE_GLBOAL(config),
|
||||
};
|
||||
|
||||
static int rabbitizer_module_attributes_Ready(void) {
|
||||
|
@ -5,9 +5,7 @@
|
||||
#include <Python.h>
|
||||
#include "structmember.h"
|
||||
|
||||
extern PyTypeObject rabbitizer_global_config_TypeObject;
|
||||
extern PyTypeObject rabbitizer_global_instr_id_TypeObject;
|
||||
|
||||
extern PyTypeObject rabbitizer_type_Instr_TypeObject;
|
||||
|
||||
extern PyTypeObject rabbitizer_global_config_TypeObject;
|
||||
|
||||
PyObject *rabbitizer_submodule_instr_id_Init(void);
|
||||
|
@ -1,78 +0,0 @@
|
||||
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
/**
|
||||
* Wrapper to expose the enums of instructions/RabbitizerInstrId.h
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "structmember.h"
|
||||
|
||||
#include "instructions/RabbitizerInstrId.h"
|
||||
|
||||
static PyObject *instr_id__cpu_get_value(PyObject *self, void *closure) {
|
||||
(void)self;
|
||||
return Py_BuildValue("i", (RabbitizerInstrId)closure);
|
||||
}
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) \
|
||||
{#name, (getter) instr_id__cpu_get_value, (setter) NULL, "", (void*)RABBITIZER_INSTR_ID_##prefix##_##name}
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) \
|
||||
{#name, (getter) instr_id__cpu_get_value, (setter) NULL, "", (void*)RABBITIZER_INSTR_ID_##prefix##_##name}
|
||||
|
||||
|
||||
static PyGetSetDef instr_id__cpu_getsetters[] = {
|
||||
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#undef RABBITIZER_DEF_INSTR_ID
|
||||
#undef RABBITIZER_DEF_INSTR_ID_ALTNAME
|
||||
|
||||
|
||||
PyTypeObject rabbitizer_type_instr_id__cpu = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "rabbitizer.instr_id.cpu",
|
||||
.tp_doc = PyDoc_STR(""),
|
||||
.tp_basicsize = sizeof(PyObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_new = PyType_GenericNew,
|
||||
.tp_getset = instr_id__cpu_getsetters,
|
||||
};
|
||||
|
||||
|
||||
// TODO: RSP
|
||||
|
||||
|
||||
static PyModuleDef rabbitizer_submodule_instr_id = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
.m_name = "rabbitizer.instr_id",
|
||||
.m_doc = "",
|
||||
.m_size = -1,
|
||||
};
|
||||
|
||||
PyObject *rabbitizer_submodule_instr_id_Init(void) {
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&rabbitizer_submodule_instr_id);
|
||||
if (submodule == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&rabbitizer_type_instr_id__cpu) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *cpuIds = PyObject_CallObject((PyObject*)&rabbitizer_type_instr_id__cpu, NULL);
|
||||
|
||||
if (PyModule_AddObject(submodule, "cpu", (PyObject *) cpuIds) < 0) {
|
||||
Py_DECREF(cpuIds);
|
||||
Py_DECREF(submodule);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return submodule;
|
||||
}
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ setup(
|
||||
# the qualified name of the extension module to build
|
||||
'rabbitizer',
|
||||
# the files to compile into our module relative to ``setup.py``
|
||||
["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_type_Instr.c", "rabbitizer/rabbitizer_submodule_instr_id.c", "rabbitizer/rabbitizer_global_config.c",
|
||||
["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_type_Instr.c", "rabbitizer/rabbitizer_global_instr_id.c", "rabbitizer/rabbitizer_global_config.c",
|
||||
"src/instructions/RabbitizerInstr/RabbitizerInstr_Disassemble.c", "src/instructions/RabbitizerInstr/RabbitizerInstr_ProcessUniqueId.c", "src/instructions/RabbitizerInstr/RabbitizerInstr.c", "src/instructions/RabbitizerInstr/RabbitizerInstr_Examination.c",
|
||||
"src/instructions/RabbitizerInstrDescriptor.c", "src/instructions/RabbitizerInstrId.c", "src/instructions/RabbitizerRegister.c",
|
||||
"src/common/Utils.c", "src/common/RabbitizerConfig.c"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user