outputsToGprZero

This commit is contained in:
angie 2022-12-19 19:04:26 -03:00
parent 75fe4e4fe3
commit 2e74fc914f
7 changed files with 40 additions and 11 deletions

View File

@ -161,6 +161,7 @@ namespace rabbitizer {
int32_t getBranchOffsetGeneric() const;
int32_t getBranchVramGeneric() const;
int8_t getDestinationGpr() const;
bool outputsToGprZero() const;
std::string getOpcodeName() const;

View File

@ -728,6 +728,10 @@ int8_t InstructionBase::getDestinationGpr() const {
return RabbitizerInstruction_getDestinationGpr(&this->instr);
}
bool InstructionBase::outputsToGprZero() const {
return RabbitizerInstruction_outputsToGprZero(&this->instr);
}
std::string InstructionBase::getOpcodeName() const {
return InstrId::getOpcodeName(getUniqueId());
}

View File

@ -178,6 +178,8 @@ NODISCARD NON_NULL(1) PURE
int32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
int8_t RabbitizerInstruction_getDestinationGpr(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_outputsToGprZero(const RabbitizerInstruction *self);
/* General getters */

View File

@ -52,6 +52,7 @@ class Instruction:
def getBranchOffsetGeneric(self) -> int: ...
def getBranchVramGeneric(self) -> int: ...
def getDestinationGpr(self) -> Enum|None: ...
def outputsToGprZero(self) -> bool: ...
def getOpcodeName(self) -> str: ...
def blankOut(self) -> None: ...

View File

@ -171,6 +171,14 @@ static PyGetSetDef rabbitizer_type_Instruction_getsetters[] = {
return PyLong_FromLong(RabbitizerInstruction_##name(&self->instr)); \
}
#define DEF_METHOD_BOOL(name) \
static PyObject *rabbitizer_type_Instruction_##name(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { \
if (RabbitizerInstruction_##name(&self->instr)) { \
Py_RETURN_TRUE; \
} \
Py_RETURN_FALSE; \
}
DEF_METHOD_GET_UINT(getRaw)
static PyObject *rabbitizer_type_Instruction_getImmediate(PyRabbitizerInstruction *self, UNUSED PyObject *closure) {
return PyLong_FromUnsignedLong(RAB_INSTR_GET_immediate(&self->instr));
@ -207,20 +215,13 @@ static PyObject *rabbitizer_type_Instruction_getDestinationGpr(PyRabbitizerInstr
RETURN_GPR(reg);
}
DEF_METHOD_BOOL(outputsToGprZero)
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, UNUSED PyObject *closure) { \
if (RabbitizerInstruction_##name(&self->instr)) { \
Py_RETURN_TRUE; \
} \
Py_RETURN_FALSE; \
}
DEF_METHOD_BOOL(isImplemented)
DEF_METHOD_BOOL(isLikelyHandwritten)
DEF_METHOD_BOOL(isNop)
@ -452,6 +453,7 @@ static PyMethodDef rabbitizer_type_Instruction_methods[] = {
METHOD_NO_ARGS(getBranchOffsetGeneric, ""),
METHOD_NO_ARGS(getBranchVramGeneric, ""),
METHOD_NO_ARGS(getDestinationGpr, ""),
METHOD_NO_ARGS(outputsToGprZero, ""),
METHOD_NO_ARGS(getOpcodeName, ""),
METHOD_NO_ARGS(blankOut, ""),

View File

@ -53,6 +53,7 @@ extern "C" {
-> i32;
fn RabbitizerInstruction_getBranchVramGeneric(self_: *const Instruction) -> i32;
fn RabbitizerInstruction_getDestinationGpr(self_: *const Instruction) -> i8;
fn RabbitizerInstruction_outputsToGprZero(self_: *const Instruction) -> bool;
fn RabbitizerInstruction_blankOut(self_: *mut Instruction);
fn RabbitizerInstruction_isImplemented(self_: *const Instruction) -> bool;
fn RabbitizerInstruction_isLikelyHandwritten(self_: *const Instruction) -> bool;
@ -433,9 +434,19 @@ impl Instruction {
RabbitizerInstruction_getBranchVramGeneric(self)
}
}
pub fn destination_gpr(&self) -> i8 {
pub fn destination_gpr(&self) -> Option<u32> {
unsafe {
RabbitizerInstruction_getDestinationGpr(self)
let reg: i8 = RabbitizerInstruction_getDestinationGpr(self);
if reg < 0 {
return None;
}
Some(reg as u32)
}
}
pub fn outputs_to_gpr_zero(&self) -> bool {
unsafe {
RabbitizerInstruction_outputsToGprZero(self)
}
}
pub fn opcode_name(&self) -> &'static str {

View File

@ -92,6 +92,14 @@ int8_t RabbitizerInstruction_getDestinationGpr(const RabbitizerInstruction *self
return -1;
}
/**
* @brief Returns `true` if the GPR which is modified by this register is $zero, `false` otherwise.
* Returns `false` if this instruction does not modify a GPR.
*/
bool RabbitizerInstruction_outputsToGprZero(const RabbitizerInstruction *self) {
return RabbitizerInstruction_getDestinationGpr(self) == 0;
}
/* General getters */
void RabbitizerInstruction_blankOut(RabbitizerInstruction *self) {