mirror of
https://github.com/Decompollaborate/rabbitizer.git
synced 2025-01-30 06:32:43 +00:00
Expose Utils module
This commit is contained in:
parent
43e8815ad5
commit
cf86945db5
11
rabbitizer/Utils.pyi
Normal file
11
rabbitizer/Utils.pyi
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: © 2022 Decompollaborate
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class Utils:
|
||||
@staticmethod
|
||||
def from2Complement(number: int, bits: int) -> int: ...
|
@ -5,6 +5,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .Utils import *
|
||||
|
||||
from .Enum import *
|
||||
from .InstrCategory import *
|
||||
from .InstrId import *
|
||||
|
@ -19,7 +19,7 @@ RabbitizerEnumMetadata rabbitizer_enum_Abi_enumvalues[] = {
|
||||
|
||||
|
||||
static PyObject *rabbitizer_enum_Abi_fromStr(UNUSED PyObject *self, PyObject *args, PyObject *kwds) {
|
||||
static char *kwlist[] = { "name", NULL} ;
|
||||
static char *kwlist[] = { "name", NULL };
|
||||
const char *name = NULL;
|
||||
RabbitizerAbi abi;
|
||||
PyObject *ret;
|
||||
|
@ -33,6 +33,7 @@ typedef struct ModuleAttribute {
|
||||
#define MODULE_ATTRIBUTE_GLOBAL(name) { {.global = &rabbitizer_global_##name##_TypeObject}, MODULE_ATTRIBUTE_CAT_GLOBAL, #name, false, NULL }
|
||||
|
||||
static ModuleAttributes rabbitizer_module_attributes[] = {
|
||||
MODULE_ATTRIBUTE_INIT(Utils),
|
||||
MODULE_ATTRIBUTE_GLOBAL(config),
|
||||
MODULE_ATTRIBUTE_TYPE(Enum),
|
||||
MODULE_ATTRIBUTE_ENUM(Abi),
|
||||
|
@ -19,6 +19,8 @@ extern RabbitizerEnumMetadata rabbitizer_enum_InstrId_enumvalues[];
|
||||
int rabbitizer_enum_Abi_Check(PyObject *o);
|
||||
|
||||
|
||||
PyObject *rabbitizer_submodule_Utils_Init(void);
|
||||
|
||||
extern PyTypeObject rabbitizer_global_config_TypeObject;
|
||||
|
||||
extern PyTypeObject rabbitizer_type_Enum_TypeObject;
|
||||
|
49
rabbitizer/rabbitizer_submodule_Utils.c
Normal file
49
rabbitizer/rabbitizer_submodule_Utils.c
Normal file
@ -0,0 +1,49 @@
|
||||
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#include "rabbitizer_module.h"
|
||||
|
||||
#include "common/Utils.h"
|
||||
|
||||
|
||||
static PyObject *rabbitizer_submodule_Utils_from2Complement(UNUSED PyObject *self, PyObject *args, PyObject *kwds) {
|
||||
static char *kwlist[] = { "number", "bits", NULL };
|
||||
uint32_t number = 0;
|
||||
int bits = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ii", kwlist, &number, &bits)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyLong_FromLong(RabbitizerUtils_From2Complement(number, bits));
|
||||
}
|
||||
|
||||
|
||||
#define METHOD_NO_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_submodule_Utils_##name, METH_NOARGS, PyDoc_STR(docs) }
|
||||
#define METHOD_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_submodule_Utils_##name, METH_VARARGS | METH_KEYWORDS, PyDoc_STR(docs) }
|
||||
|
||||
static PyMethodDef rabbitizer_submodule_Utils_methods[] = {
|
||||
METHOD_ARGS(from2Complement, ""),
|
||||
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
|
||||
static PyModuleDef rabbitizer_submodule_Utils_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
.m_name = "rabbitizer.Utils",
|
||||
.m_doc = "",
|
||||
.m_size = -1,
|
||||
.m_methods = rabbitizer_submodule_Utils_methods,
|
||||
};
|
||||
|
||||
PyObject *rabbitizer_submodule_Utils_Init(void) {
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&rabbitizer_submodule_Utils_module);
|
||||
if (submodule == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return submodule;
|
||||
}
|
2
setup.py
2
setup.py
@ -8,7 +8,7 @@ setup(
|
||||
ext_modules=[
|
||||
Extension(
|
||||
"rabbitizer",
|
||||
["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_type_Instruction.c", "rabbitizer/rabbitizer_global_config.c",
|
||||
["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_submodule_Utils.c", "rabbitizer/rabbitizer_type_Instruction.c", "rabbitizer/rabbitizer_global_config.c",
|
||||
"rabbitizer/enums/rabbitizer_type_Enum.c", "rabbitizer/enums/enums_utils.c", "rabbitizer/enums/rabbitizer_enum_InstrCategory.c", "rabbitizer/enums/rabbitizer_enum_InstrId.c", "rabbitizer/enums/rabbitizer_enum_Abi.c",
|
||||
"src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction_ProcessUniqueId.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction_Examination.c",
|
||||
"src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp.c", "src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp_ProcessUniqueId.c",
|
||||
|
Loading…
x
Reference in New Issue
Block a user