mirror of
https://github.com/Decompollaborate/rabbitizer.git
synced 2025-02-19 15:40:55 +00:00
InstrCategory.fromStr
This commit is contained in:
parent
5d0f9ad8f6
commit
6fad5e740a
32
include/instructions/RabbitizerInstrCategory.h
Normal file
32
include/instructions/RabbitizerInstrCategory.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#ifndef RABBITIZER_INSTRCATEGORY_H
|
||||
#define RABBITIZER_INSTRCATEGORY_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_CATEGORY(name) RABBITIZER_INSTRCAT_##name
|
||||
|
||||
typedef enum RabbitizerInstrCategory {
|
||||
#include "instructions/InstrCategory.inc"
|
||||
|
||||
RABBITIZER_DEF_INSTR_CATEGORY(MAX),
|
||||
} RabbitizerInstrCategory;
|
||||
|
||||
#undef RABBITIZER_DEF_INSTR_CATEGORY
|
||||
|
||||
extern const char *const RabbitizerInstrCategory_Names[];
|
||||
|
||||
RabbitizerInstrCategory RabbitizerInstrCategory_fromStr(const char *name);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -13,23 +13,13 @@
|
||||
|
||||
#include "RabbitizerInstrId.h"
|
||||
#include "RabbitizerInstrDescriptor.h"
|
||||
#include "RabbitizerInstrCategory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_CATEGORY(name) RABBITIZER_INSTRCAT_##name
|
||||
|
||||
typedef enum RabbitizerInstrCategory {
|
||||
#include "instructions/InstrCategory.inc"
|
||||
|
||||
RABBITIZER_DEF_INSTR_CATEGORY(MAX),
|
||||
} RabbitizerInstrCategory;
|
||||
|
||||
#undef RABBITIZER_DEF_INSTR_CATEGORY
|
||||
|
||||
|
||||
typedef struct RabbitizerInstruction {
|
||||
uint32_t word;
|
||||
uint32_t _mandatorybits;
|
||||
|
@ -13,3 +13,6 @@ class InstrCategory:
|
||||
RSP: Enum
|
||||
R5900: Enum
|
||||
MAX: Enum
|
||||
|
||||
@staticmethod
|
||||
def fromStr(name: str | None) -> Enum|None: ...
|
||||
|
@ -16,7 +16,34 @@ RabbitizerEnumMetadata rabbitizer_enum_InstrCategory_enumvalues[] = {
|
||||
|
||||
#undef RABBITIZER_DEF_INSTR_CATEGORY
|
||||
|
||||
|
||||
static PyObject *rabbitizer_enum_InstrCategory_fromStr(UNUSED PyObject *self, PyObject *args, PyObject *kwds) {
|
||||
static char *kwlist[] = { "name", NULL };
|
||||
const char *name = NULL;
|
||||
RabbitizerInstrCategory instrCategory;
|
||||
PyObject *ret;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "z", kwlist, &name)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
instrCategory = RabbitizerInstrCategory_fromStr(name);
|
||||
if ((int)instrCategory < 0) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
ret = rabbitizer_enum_InstrCategory_enumvalues[instrCategory].instance;
|
||||
Py_INCREF(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#define METHOD_NO_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_enum_InstrCategory_##name, METH_NOARGS, PyDoc_STR(docs) }
|
||||
#define METHOD_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_enum_InstrCategory_##name, METH_VARARGS | METH_KEYWORDS, PyDoc_STR(docs) }
|
||||
|
||||
static PyMethodDef rabbitizer_enum_InstrCategory_methods[] = {
|
||||
METHOD_ARGS(fromStr, ""),
|
||||
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
|
2
setup.py
2
setup.py
@ -15,7 +15,7 @@ setup(
|
||||
"src/instructions/RabbitizerInstructionCpu/RabbitizerInstructionCpu_OperandType.c",
|
||||
"src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp.c", "src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp_ProcessUniqueId.c", "src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp_OperandType.c",
|
||||
"src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900.c", "src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900_ProcessUniqueId.c", "src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900_OperandType.c",
|
||||
"src/instructions/RabbitizerInstrDescriptor.c", "src/instructions/RabbitizerInstrId.c", "src/instructions/RabbitizerRegister.c", "src/instructions/RabbitizerInstrSuffix.c",
|
||||
"src/instructions/RabbitizerInstrDescriptor.c", "src/instructions/RabbitizerInstrId.c", "src/instructions/RabbitizerRegister.c", "src/instructions/RabbitizerInstrSuffix.c", "src/instructions/RabbitizerInstrCategory.c",
|
||||
"src/analysis/RabbitizerTrackedRegisterState.c", "src/analysis/RabbitizerRegistersTracker.c", "src/analysis/RabbitizerLoPairingInfo.c",
|
||||
"src/common/Utils.c", "src/common/RabbitizerVersion.c", "src/common/RabbitizerConfig.c"],
|
||||
include_dirs=["include", "rabbitizer"],
|
||||
|
31
src/instructions/RabbitizerInstrCategory.c
Normal file
31
src/instructions/RabbitizerInstrCategory.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#include "instructions/RabbitizerInstrCategory.h"
|
||||
|
||||
//#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define RABBITIZER_DEF_INSTR_CATEGORY(name) [RABBITIZER_INSTRCAT_##name] = #name
|
||||
|
||||
const char *const RabbitizerInstrCategory_Names[] = {
|
||||
#include "instructions/InstrCategory.inc"
|
||||
};
|
||||
|
||||
#undef RABBITIZER_DEF_INSTR_CATEGORY
|
||||
|
||||
|
||||
RabbitizerInstrCategory RabbitizerInstrCategory_fromStr(const char *name) {
|
||||
if (name == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < RABBITIZER_INSTRCAT_MAX; i++) {
|
||||
if (strcmp(RabbitizerInstrCategory_Names[i], name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user