From 34f2e2e6a5569872a1f872a7bf9f5cca321f0cb8 Mon Sep 17 00:00:00 2001 From: angie Date: Thu, 13 Oct 2022 16:45:01 -0300 Subject: [PATCH] Remove getImmediate and getInstrIndex --- include/instructions/RabbitizerInstruction.h | 4 ---- rabbitizer/rabbitizer.pyi | 1 + rabbitizer/rabbitizer_type_Instruction.c | 20 ++++++++++--------- src/analysis/RabbitizerRegistersTracker.c | 4 ++-- .../RabbitizerInstruction.c | 11 ++-------- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/include/instructions/RabbitizerInstruction.h b/include/instructions/RabbitizerInstruction.h index 17e3bab..78cd6c8 100644 --- a/include/instructions/RabbitizerInstruction.h +++ b/include/instructions/RabbitizerInstruction.h @@ -170,13 +170,9 @@ void RabbitizerInstruction_processUniqueId(RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE uint32_t RabbitizerInstruction_getRaw(const RabbitizerInstruction *self); -NODISCARD NON_NULL(1) PURE -uint32_t RabbitizerInstruction_getImmediate(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE int32_t RabbitizerInstruction_getProcessedImmediate(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE -uint32_t RabbitizerInstruction_getInstrIndex(const RabbitizerInstruction *self); -NODISCARD NON_NULL(1) PURE uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE diff --git a/rabbitizer/rabbitizer.pyi b/rabbitizer/rabbitizer.pyi index 7681b25..06b4a7f 100644 --- a/rabbitizer/rabbitizer.pyi +++ b/rabbitizer/rabbitizer.pyi @@ -44,6 +44,7 @@ class Instruction: def __init__(self, word: int, vram: int=0, category: Enum=InstrCategory.CPU) -> None: ... def getRaw(self) -> int: ... + #! deprecated def getImmediate(self) -> int: ... def getProcessedImmediate(self) -> int: ... def getInstrIndexAsVram(self) -> int: ... diff --git a/rabbitizer/rabbitizer_type_Instruction.c b/rabbitizer/rabbitizer_type_Instruction.c index 040be44..e40be2d 100644 --- a/rabbitizer/rabbitizer_type_Instruction.c +++ b/rabbitizer/rabbitizer_type_Instruction.c @@ -68,7 +68,7 @@ static PyMemberDef rabbitizer_type_Instruction_members[] = { #define DEF_MEMBER_GET_UINT(name) \ - static PyObject *rabbitizer_type_Instruction_member_get_##name(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { \ + static PyObject *rabbitizer_type_Instruction_member_get_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \ return PyLong_FromUnsignedLong(RAB_INSTR_GET_##name(&self->instr)); \ } @@ -109,7 +109,7 @@ DEF_MEMBER_GET_REGGPR(rd) DEF_MEMBER_GET_UINT(sa) -static PyObject *rabbitizer_type_Instruction_member_get_uniqueId(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { +static PyObject *rabbitizer_type_Instruction_member_get_uniqueId(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { PyObject *enumInstance = rabbitizer_enum_InstrId_enumvalues[self->instr.uniqueId].instance; if (enumInstance == NULL) { @@ -138,17 +138,19 @@ static PyGetSetDef rabbitizer_type_Instruction_getsetters[] = { #define DEF_METHOD_GET_UINT(name) \ - static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { \ + static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \ return PyLong_FromUnsignedLong(RabbitizerInstruction_##name(&self->instr)); \ } #define DEF_METHOD_GET_INT(name) \ - static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { \ + static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \ return PyLong_FromLong(RabbitizerInstruction_##name(&self->instr)); \ } DEF_METHOD_GET_UINT(getRaw) -DEF_METHOD_GET_UINT(getImmediate) +static PyObject *rabbitizer_type_Instruction_getImmediate(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { + return PyLong_FromUnsignedLong(RAB_INSTR_GET_immediate(&self->instr)); +} DEF_METHOD_GET_INT(getProcessedImmediate) DEF_METHOD_GET_UINT(getInstrIndexAsVram) DEF_METHOD_GET_INT(getBranchOffset) @@ -168,14 +170,14 @@ static PyObject *rabbitizer_type_Instruction_getGenericBranchOffset(PyRabbitizer return PyLong_FromLong(RabbitizerInstruction_getGenericBranchOffset(&self->instr, currentVram)); } -static PyObject *rabbitizer_type_Instruction_blankOut(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { +static PyObject *rabbitizer_type_Instruction_blankOut(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { RabbitizerInstruction_blankOut(&self->instr); Py_RETURN_NONE; } #define DEF_METHOD_BOOL(name) \ - static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { \ + static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \ if (RabbitizerInstruction_##name(&self->instr)) { \ Py_RETURN_TRUE; \ } \ @@ -190,7 +192,7 @@ DEF_METHOD_BOOL(isJrRa) DEF_METHOD_BOOL(isJrNotRa) DEF_METHOD_BOOL(hasDelaySlot) -static PyObject *rabbitizer_type_Instruction_mapInstrToType(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { +static PyObject *rabbitizer_type_Instruction_mapInstrToType(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { const char *type = RabbitizerInstruction_mapInstrToType(&self->instr); if (type != NULL) { @@ -292,7 +294,7 @@ static PyObject *rabbitizer_type_Instruction_hasOperandAlias(PyRabbitizerInstruc DEF_METHOD_BOOL(isValid) #define DEF_DESCRIPTOR_METHOD_BOOL(name) \ - static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, PyObject *Py_UNUSED(ignored)) { \ + static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \ if (RabbitizerInstrDescriptor_##name(self->instr.descriptor)) { \ Py_RETURN_TRUE; \ } \ diff --git a/src/analysis/RabbitizerRegistersTracker.c b/src/analysis/RabbitizerRegistersTracker.c index c73fcd6..372c96a 100644 --- a/src/analysis/RabbitizerRegistersTracker.c +++ b/src/analysis/RabbitizerRegistersTracker.c @@ -259,7 +259,7 @@ void RabbitizerRegistersTracker_processLui(RabbitizerRegistersTracker *self, con state = &self->registers[RAB_INSTR_GET_rt(instr)]; RabbitizerTrackedRegisterState_clear(state); - RabbitizerTrackedRegisterState_setHi(state, RabbitizerInstruction_getImmediate(instr), instrOffset); + RabbitizerTrackedRegisterState_setHi(state, RabbitizerInstruction_getProcessedImmediate(instr), instrOffset); if (prevInstr != NULL) { // If the previous instructions is a branch likely, then nulify @@ -276,7 +276,7 @@ void RabbitizerRegistersTracker_processGpLoad(RabbitizerRegistersTracker *self, state = &self->registers[RAB_INSTR_GET_rt(instr)]; RabbitizerTrackedRegisterState_clear(state); - RabbitizerTrackedRegisterState_setGpLoad(state, RabbitizerInstruction_getImmediate(instr), instrOffset); + RabbitizerTrackedRegisterState_setGpLoad(state, RabbitizerInstruction_getProcessedImmediate(instr), instrOffset); } bool RabbitizerRegistersTracker_getLuiOffsetForConstant(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset) { diff --git a/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c b/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c index 5e0bf05..2757702 100644 --- a/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c +++ b/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c @@ -32,9 +32,6 @@ uint32_t RabbitizerInstruction_getRaw(const RabbitizerInstruction *self) { return self->word; } -uint32_t RabbitizerInstruction_getImmediate(const RabbitizerInstruction *self) { - return RAB_INSTR_GET_immediate(self); -} int32_t RabbitizerInstruction_getProcessedImmediate(const RabbitizerInstruction *self) { if (RabbitizerInstrDescriptor_isUnsigned(self->descriptor)) { return RAB_INSTR_GET_immediate(self); @@ -42,12 +39,8 @@ int32_t RabbitizerInstruction_getProcessedImmediate(const RabbitizerInstruction return RabbitizerUtils_From2Complement(RAB_INSTR_GET_immediate(self), 16); } -uint32_t RabbitizerInstruction_getInstrIndex(const RabbitizerInstruction *self) { - return RAB_INSTR_GET_instr_index(self); -} - uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction *self) { - uint32_t vram = RabbitizerInstruction_getInstrIndex(self) << 2; + uint32_t vram = RAB_INSTR_GET_instr_index(self) << 2; if (self->vram == 0) { vram |= 0x80000000; @@ -59,7 +52,7 @@ uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction * } int32_t RabbitizerInstruction_getBranchOffset(const RabbitizerInstruction *self) { - int32_t diff = RabbitizerUtils_From2Complement(RabbitizerInstruction_getImmediate(self), 16); + int32_t diff = RabbitizerUtils_From2Complement(RAB_INSTR_GET_immediate(self), 16); return diff * 4 + 4; }