Skip to content

Commit

Permalink
getBranchVramGeneric should return an unsigned value (#49)
Browse files Browse the repository at this point in the history
* getBranchVramGeneric should return an unsigned value

* Add test

* Revert "Add test"

This reverts commit 55e7bc1.
  • Loading branch information
descawed authored Dec 25, 2023
1 parent 7d0de27 commit b92e43e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cplusplus/include/instructions/InstructionBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion cplusplus/src/instructions/InstructionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/usage_c_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion include/instructions/RabbitizerInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rabbitizer/rabbitizer_type_Instruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions rust/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<u32> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b92e43e

Please sign in to comment.