mirror of
https://github.com/Decompollaborate/rabbitizer.git
synced 2025-01-29 21:32:45 +00:00
getDestinationGpr
This commit is contained in:
parent
7cec779b85
commit
71d241150f
@ -160,6 +160,7 @@ namespace rabbitizer {
|
||||
int32_t getGenericBranchOffset(uint32_t currentVram) const;
|
||||
int32_t getBranchOffsetGeneric() const;
|
||||
int32_t getBranchVramGeneric() const;
|
||||
int8_t getDestinationGpr() const;
|
||||
|
||||
|
||||
std::string getOpcodeName() const;
|
||||
|
@ -724,6 +724,10 @@ int32_t InstructionBase::getBranchVramGeneric() const {
|
||||
return RabbitizerInstruction_getBranchVramGeneric(&this->instr);
|
||||
}
|
||||
|
||||
int8_t InstructionBase::getDestinationGpr() const {
|
||||
return RabbitizerInstruction_getDestinationGpr(&this->instr);
|
||||
}
|
||||
|
||||
std::string InstructionBase::getOpcodeName() const {
|
||||
return InstrId::getOpcodeName(getUniqueId());
|
||||
}
|
||||
|
@ -183,6 +183,8 @@ NODISCARD NON_NULL(1) PURE
|
||||
int32_t RabbitizerInstruction_getBranchOffsetGeneric(const RabbitizerInstruction *self);
|
||||
NODISCARD NON_NULL(1) PURE
|
||||
int32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self);
|
||||
NODISCARD NON_NULL(1) PURE
|
||||
int8_t RabbitizerInstruction_getDestinationGpr(const RabbitizerInstruction *self);
|
||||
|
||||
/* General getters */
|
||||
|
||||
|
@ -51,6 +51,7 @@ class Instruction:
|
||||
def getGenericBranchOffset(self, currentVram: int) -> int: ... #! deprecated
|
||||
def getBranchOffsetGeneric(self) -> int: ...
|
||||
def getBranchVramGeneric(self) -> int: ...
|
||||
def getDestinationGpr(self) -> Enum|None: ...
|
||||
def getOpcodeName(self) -> str: ...
|
||||
|
||||
def blankOut(self) -> None: ...
|
||||
|
@ -72,6 +72,30 @@ static PyMemberDef rabbitizer_type_Instruction_members[] = {
|
||||
return PyLong_FromUnsignedLong(RAB_INSTR_GET_##name(&self->instr)); \
|
||||
}
|
||||
|
||||
#define RETURN_GPR(reg) \
|
||||
do { \
|
||||
PyObject *enumInstance = NULL; \
|
||||
\
|
||||
switch (RabbitizerConfig_Cfg.regNames.gprAbiNames) { \
|
||||
case RABBITIZER_ABI_N32: \
|
||||
case RABBITIZER_ABI_N64: \
|
||||
enumInstance = rabbitizer_enum_RegGprN32_enumvalues[reg].instance; \
|
||||
break; \
|
||||
\
|
||||
default: \
|
||||
enumInstance = rabbitizer_enum_RegGprO32_enumvalues[reg].instance; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
if (enumInstance == NULL) { \
|
||||
PyErr_SetString(PyExc_RuntimeError, "Internal error: invalid RegGpr enum value"); \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
Py_INCREF(enumInstance); \
|
||||
return enumInstance; \
|
||||
} while (0)
|
||||
|
||||
#define DEF_MEMBER_GET_REGGPR(name) \
|
||||
static PyObject *rabbitizer_type_Instruction_member_get_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \
|
||||
uint32_t reg; \
|
||||
@ -173,6 +197,16 @@ static PyObject *rabbitizer_type_Instruction_getGenericBranchOffset(PyRabbitizer
|
||||
DEF_METHOD_GET_INT(getBranchOffsetGeneric)
|
||||
DEF_METHOD_GET_INT(getBranchVramGeneric)
|
||||
|
||||
static PyObject *rabbitizer_type_Instruction_getDestinationGpr(PyRabbitizerInstruction *self, UNUSED PyObject *closure) {
|
||||
int8_t reg = RabbitizerInstruction_getDestinationGpr(&self->instr);
|
||||
|
||||
if (reg < 0) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
RETURN_GPR(reg);
|
||||
}
|
||||
|
||||
static PyObject *rabbitizer_type_Instruction_blankOut(PyRabbitizerInstruction *self, UNUSED PyObject *closure) {
|
||||
RabbitizerInstruction_blankOut(&self->instr);
|
||||
Py_RETURN_NONE;
|
||||
@ -403,6 +437,7 @@ static PyMethodDef rabbitizer_type_Instruction_methods[] = {
|
||||
METHOD_ARGS(getGenericBranchOffset, ""),
|
||||
METHOD_NO_ARGS(getBranchOffsetGeneric, ""),
|
||||
METHOD_NO_ARGS(getBranchVramGeneric, ""),
|
||||
METHOD_NO_ARGS(getDestinationGpr, ""),
|
||||
METHOD_NO_ARGS(getOpcodeName, ""),
|
||||
|
||||
METHOD_NO_ARGS(blankOut, ""),
|
||||
|
@ -78,6 +78,20 @@ int32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *
|
||||
return RabbitizerInstruction_getBranchOffset(self) + self->vram;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the general purpose register (GPR) which this instruction modifies,
|
||||
* or a negative value if the instruction does not modify the state of any GPR
|
||||
*/
|
||||
int8_t RabbitizerInstruction_getDestinationGpr(const RabbitizerInstruction *self) {
|
||||
if (RabbitizerInstrDescriptor_modifiesRd(self->descriptor)) {
|
||||
return RAB_INSTR_GET_rd(self);
|
||||
}
|
||||
if (RabbitizerInstrDescriptor_modifiesRt(self->descriptor)) {
|
||||
return RAB_INSTR_GET_rt(self);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* General getters */
|
||||
|
||||
void RabbitizerInstruction_blankOut(RabbitizerInstruction *self) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user