Skip to content

Commit

Permalink
Merge pull request #59 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.9.5
  • Loading branch information
AngheloAlf authored Apr 3, 2024
2 parents 70a8166 + 6923a39 commit e281d46
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 24 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.5] - 2024-04-03

### Changed

- Consider r5900's `paddub` as a possible move instruction.
- Internal rework to avoid allocating memory when calculating required buffer
size for disassembly.
- This is part of the `RabbitizerInstruction_getSizeForBuffer` function.
- This change may help recent Windows specific issues.

## [1.9.4] - 2024-03-18

### Changed
Expand Down Expand Up @@ -568,6 +578,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First version

[unreleased]: https://github.com/Decompollaborate/rabbitizer/compare/master...develop
[1.9.5]: https://github.com/Decompollaborate/rabbitizer/compare/1.9.4...1.9.5
[1.9.4]: https://github.com/Decompollaborate/rabbitizer/compare/1.9.3...1.9.4
[1.9.3]: https://github.com/Decompollaborate/rabbitizer/compare/1.9.2...1.9.3
[1.9.2]: https://github.com/Decompollaborate/rabbitizer/compare/1.9.1...1.9.2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[package]
name = "rabbitizer"
# Version should be synced with include/common/RabbitizerVersion.h
version = "1.9.4"
version = "1.9.5"
edition = "2021"
authors = ["Anghelo Carvajal <[email protected]>"]
description = "MIPS instruction decoder"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ WARNINGS += -Werror=type-limits
WARNINGS_CXX :=

ifeq ($(CC),gcc)
WARNINGS += -Wno-cast-function-type -Wformat-truncation -Wformat-overflow
WARNINGS += -Wno-cast-function-type -Wformat-truncation -Wformat-overflow -Wno-nonnull-compare
endif

ifeq ($(DEBUG),0)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ If you use a `requirements.txt` file in your repository, then you can add this
library with the following line:

```txt
rabbitizer>=1.9.4,<2.0.0
rabbitizer>=1.9.5,<2.0.0
```

### Development version
Expand Down Expand Up @@ -96,7 +96,7 @@ cargo add rabbitizer
Or you can add it manually to your `Cargo.toml`:

```toml
rabbitizer = "1.9.4"
rabbitizer = "1.9.5"
```

See this crate at <https://crates.io/crates/rabbitizer>.
Expand Down
2 changes: 1 addition & 1 deletion include/common/RabbitizerVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
// Header version
#define RAB_VERSION_MAJOR 1
#define RAB_VERSION_MINOR 9
#define RAB_VERSION_PATCH 4
#define RAB_VERSION_PATCH 5

#define RAB_VERSION_STR RAB_STRINGIFY(RAB_VERSION_MAJOR) "." RAB_STRINGIFY(RAB_VERSION_MINOR) "." RAB_STRINGIFY(RAB_VERSION_PATCH)

Expand Down
20 changes: 15 additions & 5 deletions include/common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,41 @@ typedef enum RabTrinaryValue {
#define RABUTILS_BUFFER_ADVANCE(buffer, totalSize, expression) \
do { \
size_t __tempSize = (size_t)(expression); \
(buffer) += __tempSize; \
if ((buffer) != NULL) { \
(buffer) += __tempSize; \
} \
(totalSize) += __tempSize; \
} while (0)

#define RABUTILS_BUFFER_WRITE_CHAR(buffer, totalSize, character) \
do { \
*(buffer) = (character); \
if ((buffer) != NULL) { \
*(buffer) = (character); \
} \
RABUTILS_BUFFER_ADVANCE(buffer, totalSize, 1); \
} while (0)

#define RABUTILS_BUFFER_SPRINTF(buffer, totalSize, format, ...) \
do { \
int _len = sprintf(buffer, format, __VA_ARGS__); \
int _len; \
if (buffer != NULL) { \
_len = sprintf(buffer, format, __VA_ARGS__); \
} else { \
_len = snprintf(NULL, 0, format, __VA_ARGS__); \
} \
assert(_len > 0); \
RABUTILS_BUFFER_ADVANCE(buffer, totalSize, _len); \
} while (0)

#define RABUTILS_BUFFER_CPY(buffer, totalSize, string) \
do { \
size_t _tempSize = strlen(string); \
memcpy(buffer, string, _tempSize); \
if ((buffer) != NULL) { \
memcpy(buffer, string, _tempSize); \
} \
RABUTILS_BUFFER_ADVANCE(buffer, totalSize, _tempSize); \
} while (0)


CONST NODISCARD
int32_t RabbitizerUtils_From2Complement(uint32_t number, int bits);
NON_NULL(1)
Expand Down
4 changes: 2 additions & 2 deletions include/generated/InstrDescriptor_Descriptors_array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[project]
name = "rabbitizer"
# Version should be synced with include/common/RabbitizerVersion.h
version = "1.9.4"
version = "1.9.5"
description = "MIPS instruction decoder"
# license = "MIT"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
extraCompileArgs += ["-Werror=vla", "-Werror=switch", "-Werror=implicit-fallthrough", "-Werror=unused-function", "-Werror=unused-parameter", "-Werror=shadow", "-Werror=switch"]
extraCompileArgs += ["-Werror=implicit-function-declaration", "-Werror=incompatible-pointer-types"]
extraCompileArgs += ["-Werror"]
extraCompileArgs += ["-Wno-nonnull-compare"]

setup(
ext_modules=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@

size_t RabbitizerOperandType_getBufferSize(RabbitizerOperandType operand, const RabbitizerInstruction *instr,
size_t immOverrideLength) {
char *auxBuffer = calloc(immOverrideLength * 2 + 2, sizeof(char));
char *immOverride = calloc(immOverrideLength + 2, sizeof(char));
OperandCallback callback;
size_t size;

assert(operand > RAB_OPERAND_ALL_INVALID);
assert(operand < RAB_OPERAND_ALL_MAX);

callback = instrOpercandCallbacks[operand];
assert(callback != NULL);

size = callback(instr, auxBuffer, immOverride, immOverrideLength);

free(auxBuffer);
free(immOverride);

return size;
return callback(instr, NULL, NULL, immOverrideLength);
}

size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInstruction *self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ size_t RabbitizerOperandType_process_cpu_label(const RabbitizerInstruction *self
size_t immOverrideLength) {
size_t totalSize = 0;

if ((dst == NULL) && (immOverrideLength > 0)) {
return immOverrideLength;
}

if ((immOverride != NULL) && (immOverrideLength > 0)) {
memcpy(dst, immOverride, immOverrideLength);
return immOverrideLength;
Expand All @@ -209,6 +213,10 @@ size_t RabbitizerOperandType_process_cpu_immediate(const RabbitizerInstruction *
size_t totalSize = 0;
int32_t number;

if ((dst == NULL) && (immOverrideLength > 0)) {
return immOverrideLength;
}

if ((immOverride != NULL) && (immOverrideLength > 0)) {
memcpy(dst, immOverride, immOverrideLength);
return immOverrideLength;
Expand Down Expand Up @@ -241,6 +249,10 @@ size_t RabbitizerOperandType_process_cpu_branch_target_label(const RabbitizerIns
const char *immOverride, size_t immOverrideLength) {
size_t totalSize = 0;

if ((dst == NULL) && (immOverrideLength > 0)) {
return immOverrideLength;
}

if ((immOverride != NULL) && (immOverrideLength > 0)) {
memcpy(dst, immOverride, immOverrideLength);
return immOverrideLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ size_t RabbitizerOperandType_process_r5900_immediate5(const RabbitizerInstructio
size_t totalSize = 0;
int32_t number;

if ((dst == NULL) && (immOverrideLength > 0)) {
return immOverrideLength;
}

if ((immOverride != NULL) && (immOverrideLength > 0)) {
memcpy(dst, immOverride, immOverrideLength);
return immOverrideLength;
Expand Down Expand Up @@ -525,6 +529,10 @@ size_t RabbitizerOperandType_process_r5900_immediate15(const RabbitizerInstructi
size_t totalSize = 0;
int32_t number;

if ((dst == NULL) && (immOverrideLength > 0)) {
return immOverrideLength;
}

if ((immOverride != NULL) && (immOverrideLength > 0)) {
memcpy(dst, immOverride, immOverrideLength);
return immOverrideLength;
Expand Down
3 changes: 2 additions & 1 deletion tables/tables/instr_id/r5900/r5900_mmi_1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
.operands={RAB_OPERAND_cpu_rd, RAB_OPERAND_cpu_rs, RAB_OPERAND_cpu_rt},
.modifiesRd=true,
.readsRs=true,
.readsRt=true
.readsRt=true,
.maybeIsMove=true
) // Parallel ADD Unsigned saturation Byte
RABBITIZER_DEF_INSTR_ID(
r5900, 0x19, psubub,
Expand Down
1 change: 1 addition & 0 deletions tables/tables/instr_id/rsp/rsp_special.inc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
.instrType=RABBITIZER_INSTR_TYPE_R,
.modifiesRd=true,
.readsRs=true,
.maybeIsMove=true,
.isPseudo=true
) // Move
RABBITIZER_DEF_INSTR_ID(
Expand Down
2 changes: 1 addition & 1 deletion tests/c/build_info_checks/version_number.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int main() {
continue;
}

fread(buffer, sizeof(char), fileSize, file);
assert(fread(buffer, sizeof(char), fileSize, file) == (size_t)fileSize);

errorCount += doVersionCheck(path, buffer);

Expand Down
12 changes: 12 additions & 0 deletions tests/c/logic_checks/descriptor_logic_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ int main() {

// A instruction should not have both doesLoad and doesStore
LOGIC_ERROR(uniqueId, errorCount, !(descriptor->doesLoad && descriptor->doesStore));

switch (uniqueId) {
case RABBITIZER_INSTR_ID_cpu_move:
case RABBITIZER_INSTR_ID_rsp_move:
// move pseudos should be considered as move instructions.
LOGIC_ERROR(uniqueId, errorCount, descriptor->maybeIsMove);
break;

default:
LOGIC_ERROR_A_IMPLIES_B(uniqueId, errorCount, descriptor->maybeIsMove, RabbitizerInstrDescriptor_hasOperandAlias(descriptor, RAB_OPERAND_cpu_rd) && RabbitizerInstrDescriptor_hasOperandAlias(descriptor, RAB_OPERAND_cpu_rs) && RabbitizerInstrDescriptor_hasOperandAlias(descriptor, RAB_OPERAND_cpu_rt));
break;
}
}

if (errorCount != 0) {
Expand Down

0 comments on commit e281d46

Please sign in to comment.