From b92e43ef518f1320fc8562b7000338a653c508e0 Mon Sep 17 00:00:00 2001 From: descawed Date: Mon, 25 Dec 2023 12:58:47 -0500 Subject: [PATCH] getBranchVramGeneric should return an unsigned value (#49) * getBranchVramGeneric should return an unsigned value * Add test * Revert "Add test" This reverts commit 55e7bc12bf14ab79f054a628271c32c918601cef. --- cplusplus/include/instructions/InstructionBase.hpp | 2 +- cplusplus/src/instructions/InstructionBase.cpp | 2 +- docs/usage_c_api.md | 4 ++-- include/instructions/RabbitizerInstruction.h | 2 +- rabbitizer/rabbitizer_type_Instruction.c | 2 +- rust/src/instruction.rs | 4 ++-- .../RabbitizerInstruction/RabbitizerInstruction.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cplusplus/include/instructions/InstructionBase.hpp b/cplusplus/include/instructions/InstructionBase.hpp index 99908cf..00d22dc 100644 --- a/cplusplus/include/instructions/InstructionBase.hpp +++ b/cplusplus/include/instructions/InstructionBase.hpp @@ -176,7 +176,7 @@ namespace rabbitizer { //! @deprecated int32_t getGenericBranchOffset(uint32_t currentVram) const; int32_t getBranchOffsetGeneric() const; - int32_t getBranchVramGeneric() const; + uint32_t getBranchVramGeneric() const; int8_t getDestinationGpr() const; bool outputsToGprZero() const; diff --git a/cplusplus/src/instructions/InstructionBase.cpp b/cplusplus/src/instructions/InstructionBase.cpp index 61bb908..04d3478 100644 --- a/cplusplus/src/instructions/InstructionBase.cpp +++ b/cplusplus/src/instructions/InstructionBase.cpp @@ -741,7 +741,7 @@ int32_t InstructionBase::getBranchOffsetGeneric() const { return RabbitizerInstruction_getBranchOffsetGeneric(&this->instr); } -int32_t InstructionBase::getBranchVramGeneric() const { +uint32_t InstructionBase::getBranchVramGeneric() const { #ifdef RAB_SANITY_CHECKS if (!hasOperandAlias(OperandType::cpu_branch_target_label) && !hasOperandAlias(OperandType::cpu_label)) { // TODO: make a rabbitizer exception class diff --git a/docs/usage_c_api.md b/docs/usage_c_api.md index 33c2151..818efe4 100644 --- a/docs/usage_c_api.md +++ b/docs/usage_c_api.md @@ -378,7 +378,7 @@ following code: ```c if (RabbitizerInstrDescriptor_isBranch(instr.descriptor)) { - int32_t vramTarget = RabbitizerInstruction_getBranchVramGeneric(&instr); + uint32_t vramTarget = RabbitizerInstruction_getBranchVramGeneric(&instr); sprintf(immOverride, ".L%08X", vramTarget); } else if (RabbitizerInstrDescriptor_canBeHi(instr.descriptor)) { @@ -472,7 +472,7 @@ int main(int argc, char *argv[]) { printf("The word %08X corresponds to the instruction (with immediate overriden):\n", word); if (RabbitizerInstrDescriptor_isBranch(instr.descriptor)) { - int32_t vramTarget = RabbitizerInstruction_getBranchVramGeneric(&instr); + uint32_t vramTarget = RabbitizerInstruction_getBranchVramGeneric(&instr); sprintf(immOverride, ".L%08X", vramTarget); } else if (RabbitizerInstrDescriptor_canBeHi(instr.descriptor)) { diff --git a/include/instructions/RabbitizerInstruction.h b/include/instructions/RabbitizerInstruction.h index 470d33f..48f153e 100644 --- a/include/instructions/RabbitizerInstruction.h +++ b/include/instructions/RabbitizerInstruction.h @@ -217,7 +217,7 @@ int32_t RabbitizerInstruction_getGenericBranchOffset(const RabbitizerInstruction NODISCARD NON_NULL(1) PURE int32_t RabbitizerInstruction_getBranchOffsetGeneric(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE -int32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self); +uint32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE int8_t RabbitizerInstruction_getDestinationGpr(const RabbitizerInstruction *self); NODISCARD NON_NULL(1) PURE diff --git a/rabbitizer/rabbitizer_type_Instruction.c b/rabbitizer/rabbitizer_type_Instruction.c index 58093eb..b455d99 100644 --- a/rabbitizer/rabbitizer_type_Instruction.c +++ b/rabbitizer/rabbitizer_type_Instruction.c @@ -312,7 +312,7 @@ static PyObject *rabbitizer_type_Instruction_getGenericBranchOffset(PyRabbitizer } DEF_METHOD_GET_INT(getBranchOffsetGeneric) -DEF_METHOD_GET_INT(getBranchVramGeneric) +DEF_METHOD_GET_UINT(getBranchVramGeneric) static PyObject *rabbitizer_type_Instruction_getDestinationGpr(PyRabbitizerInstruction *self, UNUSED PyObject *closure) { int8_t reg = RabbitizerInstruction_getDestinationGpr(&self->instr); diff --git a/rust/src/instruction.rs b/rust/src/instruction.rs index ed56a22..2fbb216 100644 --- a/rust/src/instruction.rs +++ b/rust/src/instruction.rs @@ -69,7 +69,7 @@ extern "C" { fn RabbitizerInstruction_getBranchOffset(self_: *const Instruction) -> i32; fn RabbitizerInstruction_getBranchOffsetGeneric(self_: *const Instruction) -> i32; - fn RabbitizerInstruction_getBranchVramGeneric(self_: *const Instruction) -> i32; + fn RabbitizerInstruction_getBranchVramGeneric(self_: *const Instruction) -> u32; fn RabbitizerInstruction_getDestinationGpr(self_: *const Instruction) -> i8; fn RabbitizerInstruction_outputsToGprZero(self_: *const Instruction) -> bool; fn RabbitizerInstruction_blankOut(self_: *mut Instruction); @@ -491,7 +491,7 @@ impl Instruction { unsafe { RabbitizerInstruction_getBranchOffsetGeneric(self) } } - pub fn branch_vram_generic(&self) -> i32 { + pub fn branch_vram_generic(&self) -> u32 { unsafe { RabbitizerInstruction_getBranchVramGeneric(self) } } pub fn destination_gpr(&self) -> Option { diff --git a/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c b/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c index 573c62a..5a778e3 100644 --- a/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c +++ b/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c @@ -76,7 +76,7 @@ int32_t RabbitizerInstruction_getBranchOffsetGeneric(const RabbitizerInstruction return RabbitizerInstruction_getBranchOffset(self); } -int32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self) { +uint32_t RabbitizerInstruction_getBranchVramGeneric(const RabbitizerInstruction *self) { if (RabbitizerInstruction_hasOperandAlias(self, RAB_OPERAND_cpu_label)) { return RabbitizerInstruction_getInstrIndexAsVram(self); }