Merge pull request #3 from Decompollaborate/develop

1.0.1
This commit is contained in:
Anghelo Carvajal 2022-07-12 19:25:18 -04:00 committed by GitHub
commit ebb4b84fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 507 additions and 220 deletions

23
.clang-format Normal file
View File

@ -0,0 +1,23 @@
IndentWidth: 4
Language: Cpp
UseTab: Never
ColumnLimit: 160
PointerAlignment: Right
BreakBeforeBraces: Attach
SpaceAfterCStyleCast: false
Cpp11BracedListStyle: false
IndentCaseLabels: true
BinPackArguments: true
BinPackParameters: true
AlignAfterOpenBracket: Align
AlignOperands: true
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: None
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlignEscapedNewlines: Left
AlignTrailingComments: true
SortIncludes: false

9
.clang-tidy Normal file
View File

@ -0,0 +1,9 @@
Checks: 'readability-*,-readability-magic-numbers,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,bugprone*,-bugprone-branch-clone,modernize*,performance*,portability*,diagnostic-*,analyzer-*,misc*,-misc-no-recursion'
WarningsAsErrors: ''
HeaderFilterRegex: '(src|include)\/.*\.h$'
FormatStyle: 'file'
CheckOptions:
# Require argument names to match exactly (instead of allowing a name to be a prefix/suffix of another)
# Note: 'true' is expected by clang-tidy 12+ but '1' is used for compatibility with older versions
- key: readability-inconsistent-declaration-parameter-name.Strict
value: 1

View File

@ -9,13 +9,17 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- name: Build wheels
uses: pypa/cibuildwheel@v2.5.0
env:
CIBW_ARCHS_WINDOWS: "auto"
CIBW_ARCHS_LINUX: "auto"
CIBW_ARCHS_MACOS: "all"
- uses: actions/upload-artifact@v2
with:

84
Makefile Normal file
View File

@ -0,0 +1,84 @@
# Build options can be changed by modifying the makefile or by building with 'make SETTING=value'.
DEBUG ?= 0
WERROR ?= 0
ASAN ?= 0
EXPERIMENTAL ?= 0
CC := clang
IINC := -I include
CSTD := -std=c11
CFLAGS :=
LDFLAGS :=
WARNINGS := -Wall -Wextra
# WARNINGS := -Wall -Wextra -Wpedantic -Wpadded # binary constants :s
WARNINGS += -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werror=unused-function -Werror=unused-parameter -Werror=shadow
ifeq ($(CC),gcc)
WARNINGS += -Wno-cast-function-type
endif
ifeq ($(DEBUG),0)
OPTFLAGS := -O2 -g
else
OPTFLAGS := -O0 -g3
CFLAGS += -DDEVELOPMENT=1
endif
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
endif
ifneq ($(EXPERIMENTAL),0)
CFLAGS += -DEXPERIMENTAL
endif
SRC_DIRS := $(shell find src -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
H_FILES := $(foreach dir,$(IINC),$(wildcard $(dir)/**/*.h))
O_FILES := $(foreach f,$(C_FILES:.c=.o),build/$f)
DEP_FILES := $(O_FILES:%.o=%.d)
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
#### Main Targets ###
all: tests
clean:
$(RM) -rf build
distclean: clean
$(RM) -rf dist rabbitizer.egg-info .mypy_cache
format:
clang-format-11 -i -style=file $(C_FILES)
tidy:
clang-tidy-11 -p . --fix --fix-errors $(C_FILES) $(H_FILES) -- $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS)
tests: build/test.elf
.PHONY: all clean distclean format tidy tests
.DEFAULT_GOAL := all
.SECONDARY:
#### Various Recipes ####
build/%.elf: %.c $(O_FILES)
$(CC) -MMD $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) $(LDFLAGS) -o $@ $^
build/%.o: %.c
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
$(CC) -MMD -c $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
-include $(DEP_FILES)

View File

@ -5,6 +5,7 @@
#define RABBITIZER_REGISTERS_TRACKER_H
#pragma once
#include "common/Utils.h"
#include "RabbitizerTrackedRegisterState.h"
#include "instructions/RabbitizerInstruction.h"
@ -14,22 +15,35 @@ typedef struct RabbitizerRegistersTracker {
} RabbitizerRegistersTracker;
NON_NULL(1)
void RabbitizerRegistersTracker_init(RabbitizerRegistersTracker *self, const RabbitizerRegistersTracker *other);
NON_NULL(1)
void RabbitizerRegistersTracker_destroy(RabbitizerRegistersTracker *self);
NON_NULL(1, 2)
bool RabbitizerRegistersTracker_moveRegisters(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr);
NON_NULL(1, 2)
void RabbitizerRegistersTracker_overwriteRegisters(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset);
NON_NULL(1, 2, 3)
void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, const RabbitizerInstruction *prevInstr);
bool RabbitizerRegistersTracker_getAddressIfCanSetType(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, uint32_t *dstAddress);
bool RabbitizerRegistersTracker_getJrInfo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset, uint32_t *dstAddress);
NON_NULL(1, 2, 4)
bool RabbitizerRegistersTracker_getAddressIfCanSetType(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, uint32_t *dstAddress);
NON_NULL(1, 2, 3, 4)
bool RabbitizerRegistersTracker_getJrInfo(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset, uint32_t *dstAddress);
// prevInstr can be NULL
NON_NULL(1, 2)
void RabbitizerRegistersTracker_processLui(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, const RabbitizerInstruction *prevInstr);
bool RabbitizerRegistersTracker_getLuiOffsetForConstant(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset);
NON_NULL(1, 2, 3)
bool RabbitizerRegistersTracker_getLuiOffsetForConstant(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset);
NON_NULL(1, 2)
void RabbitizerRegistersTracker_processConstant(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, uint32_t value, int offset);
NON_NULL(1, 2, 4, 5)
bool RabbitizerRegistersTracker_getLuiOffsetForLo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, int *dstOffset, bool *dstIsGp);
NON_NULL(1, 2)
void RabbitizerRegistersTracker_processLo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, uint32_t value, int offset);
bool RabbitizerRegistersTracker_hasLoButNoHi(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr);
NON_NULL(1, 2)
bool RabbitizerRegistersTracker_hasLoButNoHi(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr);
#endif

View File

@ -8,6 +8,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "common/Utils.h"
typedef struct RabbitizerTrackedRegisterState {
int registerNum;
@ -25,22 +27,34 @@ typedef struct RabbitizerTrackedRegisterState {
} RabbitizerTrackedRegisterState;
NON_NULL(1)
void RabbitizerTrackedRegisterState_init(RabbitizerTrackedRegisterState *self, int registerNum);
NON_NULL(1)
void RabbitizerTrackedRegisterState_destroy(RabbitizerTrackedRegisterState *self);
NON_NULL(1)
void RabbitizerTrackedRegisterState_clear(RabbitizerTrackedRegisterState *self);
NON_NULL(1)
void RabbitizerTrackedRegisterState_clearHi(RabbitizerTrackedRegisterState *self);
NON_NULL(1)
void RabbitizerTrackedRegisterState_clearLo(RabbitizerTrackedRegisterState *self);
NON_NULL(1, 2)
void RabbitizerTrackedRegisterState_copyState(RabbitizerTrackedRegisterState *self, const RabbitizerTrackedRegisterState *other);
NON_NULL(1)
void RabbitizerTrackedRegisterState_setHi(RabbitizerTrackedRegisterState *self, uint32_t value, int offset);
NON_NULL(1)
void RabbitizerTrackedRegisterState_setLo(RabbitizerTrackedRegisterState *self, uint32_t value, int offset);
NON_NULL(1)
void RabbitizerTrackedRegisterState_deref(RabbitizerTrackedRegisterState *self, int offset);
NON_NULL(1, 2)
void RabbitizerTrackedRegisterState_dereferenceState(RabbitizerTrackedRegisterState *self, const RabbitizerTrackedRegisterState *other, int offset);
NODISCARD NON_NULL(1) PURE
bool RabbitizerTrackedRegisterState_hasAnyValue(const RabbitizerTrackedRegisterState *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerTrackedRegisterState_wasSetInCurrentOffset(const RabbitizerTrackedRegisterState *self, int offset);

View File

@ -12,30 +12,39 @@
#define __attribute__(x)
#endif
#if __STDC_VERSION__ >= 202300L
#if __STDC_VERSION__ >= 202000L
#define CONST [[gnu::const]]
#define DEPRECATED(reason) [[deprecated (reason)]]
#define FALLTHROUGH [[fallthrough]]
#define NODISCARD(reason) [[nodiscard (reason)]]
#define NODISCARD [[nodiscard]]
#define NORETURN [[noreturn]]
#define NON_NULL(...) [[gnu::nonnull (__VA_ARGS__)]]
#define PURE [[gnu::pure]]
#define RETURNS_NON_NULL [[gnu::returns_nonnull]]
#define UNUSED [[maybe_unused]]
#else
#define CONST __attribute__((const))
#define DEPRECATED(reason) __attribute__((deprecated (reason)))
#define FALLTHROUGH __attribute__((fallthrough))
#define NODISCARD(reason) __attribute__((warn_unused_result))
#define NODISCARD __attribute__((warn_unused_result))
#define NORETURN _Noreturn
#define NON_NULL(...) __attribute__((nonnull (__VA_ARGS__)))
#define PURE __attribute__((pure))
#define RETURNS_NON_NULL __attribute__((returns_nonnull))
#define UNUSED __attribute__((unused))
#endif
#if defined(_MSC_VER)
# define UNREACHABLE __assume(0)
#else
#elif defined(__GNUC__) || defined(__clang__)
# define UNREACHABLE __builtin_unreachable()
#else
# define UNREACHABLE
#endif
#define PURE __attribute__((pure))
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof((arr)[0]))
#define MASK(v, w) ((v) & ((1 << (w)) - 1))
@ -58,7 +67,39 @@
#define BITREPACK_RIGHT(fullword, v, s, w) (SHIFTL((v), (s), (w)) | MASK((fullword), (s)))
#define RABUTILS_BUFFER_ADVANCE(buffer, totalSize, expression) \
do { \
size_t __tempSize = expression; \
(buffer) += __tempSize; \
(totalSize) += __tempSize; \
} while (0)
#define RABUTILS_BUFFER_WRITE_CHAR(buffer, totalSize, character) \
do { \
*(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__); \
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); \
RABUTILS_BUFFER_ADVANCE(buffer, totalSize, _tempSize); \
} while (0)
CONST NODISCARD
int32_t RabbitizerUtils_From2Complement(uint32_t number, int bits);
NON_NULL(1)
size_t RabbitizerUtils_CharFill(char *dst, int count, char fillchar);
NON_NULL(1, 3)
size_t RabbitizerUtils_escapeString(char *dst, size_t dstSize, const char *src, size_t srcSize);
#endif

View File

@ -7,6 +7,7 @@
#include <stdbool.h>
#include "common/Utils.h"
#include "RabbitizerOperandType.h"
#include "RabbitizerInstrId.h"
@ -64,37 +65,61 @@ typedef struct RabbitizerInstrDescriptor {
extern const RabbitizerInstrDescriptor RabbitizerInstrDescriptor_Descriptors[];
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isUnknownType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isJType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isIType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isRType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isRegimmType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isBranch(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isBranchLikely(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isJump(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isTrap(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isFloat(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isDouble(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isUnsigned(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesRt(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesRd(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_notEmitedByCompilers(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_canBeHi(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_canBeLo(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_doesLink(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_doesDereference(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_doesLoad(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_doesStore(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_maybeIsMove(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isPseudo(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
RabbitizerArchitectureVersion RabbitizerInstrDescriptor_getArchitectureVersion(const RabbitizerInstrDescriptor *self);
#endif

View File

@ -5,6 +5,8 @@
#define RABBITIZER_INSTRID_H
#pragma once
#include "common/Utils.h"
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) \
RABBITIZER_INSTR_ID_##prefix##_##name
@ -29,6 +31,7 @@ typedef enum RabbitizerInstrId {
extern const char *RabbitizerInstrId_Names[];
CONST NODISCARD RETURNS_NON_NULL
const char *RabbitizerInstrId_getOpcodeName(RabbitizerInstrId uniqueId);
#endif

View File

@ -104,18 +104,27 @@ typedef struct RabbitizerInstruction {
#define RAB_INSTR_PACK_nd(word, value) (BITREPACK((word), (value), 17, 1))
NON_NULL(1)
void RabbitizerInstruction_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram);
NON_NULL(1)
void RabbitizerInstruction_destroy(RabbitizerInstruction* self);
/* Process uniqueId */
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Normal(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Special(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Regimm(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Coprocessor0(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Coprocessor1(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId_Coprocessor2(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstruction_processUniqueId(RabbitizerInstruction *self);
/* Process uniqueId */
@ -123,40 +132,60 @@ void RabbitizerInstruction_processUniqueId(RabbitizerInstruction *self);
/* General getters */
NODISCARD NON_NULL(1) PURE
uint32_t RabbitizerInstruction_getRaw(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
uint32_t RabbitizerInstruction_getImmediate(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
int32_t RabbitizerInstruction_getProcessedImmediate(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
uint32_t RabbitizerInstruction_getInstrIndex(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
int32_t RabbitizerInstruction_getBranchOffset(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
int32_t RabbitizerInstruction_getGenericBranchOffset(const RabbitizerInstruction *self, uint32_t currentVram);
/* General getters */
NON_NULL(1)
void RabbitizerInstruction_blankOut(RabbitizerInstruction *self);
/* Instruction examination */
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isImplemented(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isLikelyHandwritten(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isNop(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isUnconditionalBranch(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isJrRa(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isJrNotRa(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_hasDelaySlot(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
const char *RabbitizerInstruction_mapInstrToType(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1, 2) PURE
bool RabbitizerInstruction_sameOpcode(const RabbitizerInstruction *self, const RabbitizerInstruction *other);
NODISCARD NON_NULL(1, 2) PURE
bool RabbitizerInstruction_sameOpcodeButDifferentArguments(const RabbitizerInstruction *self, const RabbitizerInstruction *other);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_hasOperand(const RabbitizerInstruction *self, RabbitizerOperandType operand);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_hasOperandAlias(const RabbitizerInstruction *self, RabbitizerOperandType operand);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_isValid(const RabbitizerInstruction *self);
/* Instruction examination */
@ -164,18 +193,27 @@ bool RabbitizerInstruction_isValid(const RabbitizerInstruction *self);
/* Disassembly */
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_mustDisasmAsData(const RabbitizerInstruction *self);
size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust);
size_t RabbitizerInstruction_disassembleOperands(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust);
NODISCARD NON_NULL(1) PURE
size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInstruction *self, size_t immOverrideLength);
NON_NULL(1, 2)
size_t RabbitizerInstruction_disassembleOperands(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength);
NODISCARD NON_NULL(1) PURE
size_t RabbitizerInstruction_getSizeForBufferInstrDisasm(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust);
NON_NULL(1, 2)
size_t RabbitizerInstruction_disassembleInstruction(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust);
NODISCARD NON_NULL(1) PURE
size_t RabbitizerInstruction_getSizeForBufferDataDisasm(const RabbitizerInstruction *self, int extraLJust);
NON_NULL(1, 2)
size_t RabbitizerInstruction_disassembleAsData(const RabbitizerInstruction *self, char *dst, int extraLJust);
NODISCARD NON_NULL(1) PURE
size_t RabbitizerInstruction_getSizeForBuffer(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust);
NON_NULL(1, 2)
size_t RabbitizerInstruction_disassemble(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust);
/* Disassembly */

View File

@ -30,19 +30,27 @@
#define RAB_INSTR_RSP_PACK_offset(word, value) (BITREPACK((word), value, 0, 7))
NON_NULL(1)
void RabbitizerInstructionRsp_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram);
NON_NULL(1)
void RabbitizerInstructionRsp_destroy(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstructionRsp_processUniqueId_Normal(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstructionRsp_processUniqueId_Special(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstructionRsp_processUniqueId_Regimm(RabbitizerInstruction *self);
NON_NULL(1)
void RabbitizerInstructionRsp_processUniqueId(RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
uint16_t RabbitizerInstructionRsp_GetOffsetVector(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
uint8_t RabbitizerInstructionRsp_processVectorElement(const RabbitizerInstruction *self, uint8_t element);

View File

@ -7,6 +7,8 @@
#include <stdint.h>
#include "common/Utils.h"
#define RABBITIZER_DEF_REG(prefix, name, numeric) \
RABBITIZER_REG_##prefix##_##name
@ -63,10 +65,10 @@ typedef enum RabbitizerRegister_RspVector {
#undef RABBITIZER_DEF_REG
#undef RABBITIZER_DEF_REG_NODOLLAR
extern const char *RabbitizerRegister_GprO32_Names[][2];
extern const char *RabbitizerRegister_GprN32_Names[][2];
extern const char *RabbitizerRegister_Cop0_Names[][2];
extern const char *RabbitizerRegister_Cop0_Names[][2];
extern const char *RabbitizerRegister_Cop1O32_Names[][2];
extern const char *RabbitizerRegister_Cop1N32_Names[][2];
extern const char *RabbitizerRegister_Cop1N64_Names[][2];
@ -76,13 +78,21 @@ extern const char *RabbitizerRegister_RspCop0_Names[][2];
extern const char *RabbitizerRegister_RspVector_Names[][2];
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameGpr(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameCop0(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameCop1(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameCop1Control(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameCop2(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameRspGpr(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameRspCop0(uint8_t regValue);
NODISCARD PURE RETURNS_NON_NULL
const char *RabbitizerRegister_getNameRspVector(uint8_t regValue);
#endif

View File

@ -2,7 +2,8 @@
# SPDX-License-Identifier: MIT
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
skip = ["cp36-*"]

View File

@ -15,7 +15,7 @@ class Abi:
N64: Enum
@staticmethod
def fromStr(name: str) -> Enum: ...
def fromStr(name: str | None) -> Enum: ...
class _RabbitizerConfig:

View File

@ -9,3 +9,6 @@ from __future__ import annotations
class Utils:
@staticmethod
def from2Complement(number: int, bits: int) -> int: ...
@staticmethod
def escapeString(src: str) -> str: ...

View File

@ -24,7 +24,7 @@ static PyObject *rabbitizer_enum_Abi_fromStr(UNUSED PyObject *self, PyObject *ar
RabbitizerAbi abi;
PyObject *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &name)) {
if (!PyArg_ParseTupleAndKeywords(args, kwds, "z", kwlist, &name)) {
return NULL;
}

View File

@ -11,16 +11,14 @@
#define DEF_MEMBER_GET_BOOL(category, name) \
static PyObject *rabbitizer_global_config_get_##category##_##name(PyObject *self, PyObject *Py_UNUSED(ignored)) { \
(void)self; \
static PyObject *rabbitizer_global_config_get_##category##_##name(UNUSED PyObject *self, UNUSED PyObject *closure) { \
if (RabbitizerConfig_Cfg.category.name) { \
Py_RETURN_TRUE; \
} \
Py_RETURN_FALSE; \
}
#define DEF_MEMBER_SET_BOOL(category, name) \
static int rabbitizer_global_config_set_##category##_##name(PyObject *self, PyObject *value, void *Py_UNUSED(closure)) { \
(void)self; \
static int rabbitizer_global_config_set_##category##_##name(UNUSED PyObject *self, PyObject *value, UNUSED void *closure) { \
if (value == NULL) { \
PyErr_SetString(PyExc_TypeError, "Cannot delete '" #category "." #name "' attribute"); \
return -1; \
@ -35,14 +33,12 @@
#define DEF_MEMBER_GET_INT(category, name) \
static PyObject *rabbitizer_global_config_get_##category##_##name(PyObject *self, PyObject *Py_UNUSED(ignored)) { \
(void)self; \
static PyObject *rabbitizer_global_config_get_##category##_##name(UNUSED PyObject *self, UNUSED PyObject *closure) { \
return PyLong_FromLong(RabbitizerConfig_Cfg.category.name); \
}
#define DEF_MEMBER_SET_INT(category, name, rangeCheck, minVal, maxVal) \
static int rabbitizer_global_config_set_##category##_##name(PyObject *self, PyObject *value, void *Py_UNUSED(closure)) { \
static int rabbitizer_global_config_set_##category##_##name(UNUSED PyObject *self, PyObject *value, UNUSED void *closure) { \
long val; \
(void)self; \
if (value == NULL) { \
PyErr_SetString(PyExc_TypeError, "Cannot delete '" #category "_" #name "' attribute"); \
return -1; \

View File

@ -18,12 +18,44 @@ static PyObject *rabbitizer_submodule_Utils_from2Complement(UNUSED PyObject *sel
return PyLong_FromLong(RabbitizerUtils_From2Complement(number, bits));
}
static PyObject *rabbitizer_submodule_Utils_escapeString(UNUSED PyObject *self, PyObject *args, PyObject *kwds) {
static char *kwlist[] = { "src", NULL };
const char *src = NULL;
Py_ssize_t srcSize = 0;
char *dst;
size_t dstSize;
size_t wroteBytes;
PyObject *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", kwlist, &src, &srcSize)) {
return NULL;
}
dstSize = 2 * srcSize;
dst = malloc(dstSize * sizeof(char));
if (dst == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Internal error on 'escapeString'");
return NULL;
}
wroteBytes = RabbitizerUtils_escapeString(dst, dstSize, src, srcSize);
if (wroteBytes > dstSize) {
PyErr_SetString(PyExc_RuntimeError, "Internal error on 'escapeString'");
return NULL;
}
ret = PyUnicode_FromStringAndSize(dst, wroteBytes);
free(dst);
return ret;
}
#define METHOD_NO_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_submodule_Utils_##name, METH_NOARGS, PyDoc_STR(docs) }
#define METHOD_ARGS(name, docs) { #name, (PyCFunction) rabbitizer_submodule_Utils_##name, METH_VARARGS | METH_KEYWORDS, PyDoc_STR(docs) }
static PyMethodDef rabbitizer_submodule_Utils_methods[] = {
METHOD_ARGS(from2Complement, ""),
METHOD_ARGS(escapeString, ""),
{ 0 },
};

View File

@ -3,7 +3,7 @@
[metadata]
name = rabbitizer
version = 1.0.0
version = 1.0.1
author = Decompollaborate
license = MIT
description = MIPS instruction decoder

View File

@ -9,11 +9,12 @@
#include "common/RabbitizerConfig.h"
#include "instructions/RabbitizerRegister.h"
// TODO: abi checks
void RabbitizerRegistersTracker_init(RabbitizerRegistersTracker *self, const RabbitizerRegistersTracker *other) {
for (size_t i = 0; i < ARRAY_COUNT(self->registers); i++) {
size_t i;
for (i = 0; i < ARRAY_COUNT(self->registers); i++) {
RabbitizerTrackedRegisterState_init(&self->registers[i], i);
if (other != NULL) {
RabbitizerTrackedRegisterState_copyState(&self->registers[i], &other->registers[i]);
@ -27,7 +28,6 @@ void RabbitizerRegistersTracker_destroy(RabbitizerRegistersTracker *self) {
}
}
bool RabbitizerRegistersTracker_moveRegisters(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr) {
RabbitizerTrackedRegisterState *dstState;
RabbitizerTrackedRegisterState *srcState;
@ -105,7 +105,8 @@ void RabbitizerRegistersTracker_overwriteRegisters(RabbitizerRegistersTracker *s
default:
break;
}
} else if (RabbitizerInstrDescriptor_isRType(instr->descriptor) || (RabbitizerInstrDescriptor_isBranch(instr->descriptor) && RabbitizerInstrDescriptor_isIType(instr->descriptor))) {
} else if (RabbitizerInstrDescriptor_isRType(instr->descriptor) ||
(RabbitizerInstrDescriptor_isBranch(instr->descriptor) && RabbitizerInstrDescriptor_isIType(instr->descriptor))) {
// $at usually is a one-use reg
uint8_t at = 0;
@ -137,11 +138,11 @@ void RabbitizerRegistersTracker_overwriteRegisters(RabbitizerRegistersTracker *s
if (shouldRemove) {
state = &self->registers[reg];
#if 0
#if 0
if (state->hasLuiValue) {
self->_printDebugInfo_clearRegister(instr, reg)
}
#endif
#endif
RabbitizerTrackedRegisterState_clearHi(state);
if (!RabbitizerTrackedRegisterState_wasSetInCurrentOffset(state, instrOffset)) {
@ -150,7 +151,8 @@ void RabbitizerRegistersTracker_overwriteRegisters(RabbitizerRegistersTracker *s
}
}
void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersTracker *self, UNUSED const RabbitizerInstruction *instr, const RabbitizerInstruction *prevInstr) {
void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersTracker *self, UNUSED const RabbitizerInstruction *instr,
const RabbitizerInstruction *prevInstr) {
RabbitizerTrackedRegisterState *state = NULL;
if (!RabbitizerInstrDescriptor_doesLink(prevInstr->descriptor)) {
@ -179,11 +181,11 @@ void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersT
case RABBITIZER_REG_GPR_O32_t9:
case RABBITIZER_REG_GPR_O32_ra:
state = &self->registers[reg];
#if 0
#if 0
if (state.hasLuiValue) {
self->_printDebugInfo_clearRegister(instr, reg)
}
#endif
#endif
RabbitizerTrackedRegisterState_clear(state);
break;
@ -213,11 +215,11 @@ void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersT
case RABBITIZER_REG_GPR_N32_t9:
case RABBITIZER_REG_GPR_N32_ra:
state = &self->registers[reg];
#if 0
#if 0
if (state.hasLuiValue) {
self->_printDebugInfo_clearRegister(instr, reg)
}
#endif
#endif
RabbitizerTrackedRegisterState_clear(state);
break;
@ -228,8 +230,9 @@ void RabbitizerRegistersTracker_unsetRegistersAfterFuncCall(RabbitizerRegistersT
}
}
bool RabbitizerRegistersTracker_getAddressIfCanSetType(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, uint32_t *dstAddress) {
RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
bool RabbitizerRegistersTracker_getAddressIfCanSetType(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset,
uint32_t *dstAddress) {
const RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
if (!state->hasLoValue) {
return false;
@ -243,8 +246,8 @@ bool RabbitizerRegistersTracker_getAddressIfCanSetType(RabbitizerRegistersTracke
return false;
}
bool RabbitizerRegistersTracker_getJrInfo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset, uint32_t *dstAddress) {
RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
bool RabbitizerRegistersTracker_getJrInfo(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset, uint32_t *dstAddress) {
const RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
if (!state->hasLoValue || !state->dereferenced) {
return false;
@ -255,9 +258,9 @@ bool RabbitizerRegistersTracker_getJrInfo(RabbitizerRegistersTracker *self, cons
return true;
}
// prevInstr can be NULL
void RabbitizerRegistersTracker_processLui(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, const RabbitizerInstruction *prevInstr) {
void RabbitizerRegistersTracker_processLui(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset,
const RabbitizerInstruction *prevInstr) {
RabbitizerTrackedRegisterState *state = NULL;
assert(RabbitizerInstrDescriptor_canBeHi(instr->descriptor));
@ -273,8 +276,8 @@ void RabbitizerRegistersTracker_processLui(RabbitizerRegistersTracker *self, con
}
}
bool RabbitizerRegistersTracker_getLuiOffsetForConstant(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset) {
RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
bool RabbitizerRegistersTracker_getLuiOffsetForConstant(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int *dstOffset) {
const RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
if (!state->hasLuiValue) {
return false;
@ -290,8 +293,10 @@ void RabbitizerRegistersTracker_processConstant(RabbitizerRegistersTracker *self
RabbitizerTrackedRegisterState_setLo(stateDst, value, offset);
}
bool RabbitizerRegistersTracker_getLuiOffsetForLo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, int *dstOffset, bool *dstIsGp) {
RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
// TODO: this function should not be changing the state of the tracker
bool RabbitizerRegistersTracker_getLuiOffsetForLo(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr, int instrOffset, int *dstOffset,
bool *dstIsGp) {
const RabbitizerTrackedRegisterState *state = &self->registers[RAB_INSTR_GET_rs(instr)];
if (state->hasLuiValue && !state->luiSetOnBranchLikely) {
*dstOffset = state->luiOffset;
@ -333,8 +338,8 @@ void RabbitizerRegistersTracker_processLo(RabbitizerRegistersTracker *self, cons
}
}
bool RabbitizerRegistersTracker_hasLoButNoHi(RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr) {
RabbitizerTrackedRegisterState *state;
bool RabbitizerRegistersTracker_hasLoButNoHi(const RabbitizerRegistersTracker *self, const RabbitizerInstruction *instr) {
const RabbitizerTrackedRegisterState *state;
assert(instr != NULL);
@ -342,7 +347,6 @@ bool RabbitizerRegistersTracker_hasLoButNoHi(RabbitizerRegistersTracker *self, c
return state->hasLoValue && !state->hasLuiValue;
}
#if 0
def _printDebugInfo_clearRegister(self, instr: rabbitizer.Instruction, reg: int, currentVram: int|None=None) -> None:
if not common.GlobalConfig.PRINT_SYMBOL_FINDER_DEBUG_INFO:

View File

@ -7,7 +7,6 @@
#include "common/Utils.h"
void RabbitizerTrackedRegisterState_init(RabbitizerTrackedRegisterState *self, int registerNum) {
self->registerNum = registerNum;
@ -26,7 +25,6 @@ void RabbitizerTrackedRegisterState_init(RabbitizerTrackedRegisterState *self, i
void RabbitizerTrackedRegisterState_destroy(UNUSED RabbitizerTrackedRegisterState *self) {
}
void RabbitizerTrackedRegisterState_clear(RabbitizerTrackedRegisterState *self) {
self->hasLuiValue = false;
self->luiOffset = 0;
@ -52,7 +50,6 @@ void RabbitizerTrackedRegisterState_clearLo(RabbitizerTrackedRegisterState *self
self->value = 0;
}
void RabbitizerTrackedRegisterState_copyState(RabbitizerTrackedRegisterState *self, const RabbitizerTrackedRegisterState *other) {
self->hasLuiValue = other->hasLuiValue;
self->luiOffset = other->luiOffset;
@ -66,7 +63,6 @@ void RabbitizerTrackedRegisterState_copyState(RabbitizerTrackedRegisterState *se
self->value = other->value;
}
void RabbitizerTrackedRegisterState_setHi(RabbitizerTrackedRegisterState *self, uint32_t value, int offset) {
self->hasLuiValue = true;
self->luiOffset = offset;
@ -81,7 +77,6 @@ void RabbitizerTrackedRegisterState_setLo(RabbitizerTrackedRegisterState *self,
self->dereferenceOffset = 0;
}
void RabbitizerTrackedRegisterState_deref(RabbitizerTrackedRegisterState *self, int offset) {
self->dereferenced = true;
self->dereferenceOffset = offset;
@ -95,7 +90,6 @@ void RabbitizerTrackedRegisterState_dereferenceState(RabbitizerTrackedRegisterSt
RabbitizerTrackedRegisterState_deref(self, offset);
}
bool RabbitizerTrackedRegisterState_hasAnyValue(const RabbitizerTrackedRegisterState *self) {
return self->hasLuiValue || self->hasLoValue;
}

View File

@ -5,9 +5,8 @@
#include <string.h>
RabbitizerAbi RabbitizerAbi_fromStr(const char *name) {
if (strcmp(name, "32") == 0 || strcmp(name, "o32") == 0 || strcmp(name, "O32") == 0) {
if (name == NULL || strcmp(name, "32") == 0 || strcmp(name, "o32") == 0 || strcmp(name, "O32") == 0) {
return RABBITIZER_ABI_O32;
}
if (strcmp(name, "n32") == 0 || strcmp(name, "N32") == 0) {
@ -19,7 +18,6 @@ RabbitizerAbi RabbitizerAbi_fromStr(const char *name) {
return RABBITIZER_ABI_NUMERIC;
}
RabbitizerConfig RabbitizerConfig_Cfg = {
.regNames = {
.namedRegisters = true,

View File

@ -6,7 +6,6 @@
#include <stdbool.h>
#include <string.h>
int32_t RabbitizerUtils_From2Complement(uint32_t number, int bits) {
bool isNegative = number & (1 << (bits - 1));
@ -26,3 +25,48 @@ size_t RabbitizerUtils_CharFill(char *dst, int count, char fillchar) {
return count;
}
size_t RabbitizerUtils_escapeString(char *dst, size_t dstSize, const char *src, size_t srcSize) {
size_t srcPos = 0;
size_t dstpos = 0;
for (; srcPos < srcSize && dstpos < dstSize; srcPos++, src++) {
switch (*src) {
case '\a':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, 'a');
break;
case '\t':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, 't');
break;
case '\n':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, 'n');
break;
case '\f':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, 'f');
break;
case '\r':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, 'r');
break;
case '"':
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '\\');
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, '"');
break;
default:
RABUTILS_BUFFER_WRITE_CHAR(dst, dstpos, *src);
break;
}
}
return dstpos;
}

View File

@ -5,23 +5,18 @@
#include "instructions/RabbitizerInstruction.h"
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) [RABBITIZER_INSTR_ID_##prefix##_##name] = { __VA_ARGS__ }
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) \
[RABBITIZER_INSTR_ID_##prefix##_##name] = { __VA_ARGS__ }
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) \
[RABBITIZER_INSTR_ID_##prefix##_##name] = { __VA_ARGS__ }
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) [RABBITIZER_INSTR_ID_##prefix##_##name] = { __VA_ARGS__ }
const RabbitizerInstrDescriptor RabbitizerInstrDescriptor_Descriptors[] = {
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
#include "instructions/instr_id/RabbitizerInstrId_rsp.inc"
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
#include "instructions/instr_id/RabbitizerInstrId_rsp.inc"
};
#undef RABBITIZER_DEF_INSTR_ID
#undef RABBITIZER_DEF_INSTR_ID_ALTNAME
bool RabbitizerInstrDescriptor_isUnknownType(const RabbitizerInstrDescriptor *self) {
return self->instrType == RABBITIZER_INSTR_TYPE_UNKNOWN;
}

View File

@ -5,23 +5,18 @@
#include <assert.h>
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) [RABBITIZER_INSTR_ID_##prefix##_##name] = #name
#define RABBITIZER_DEF_INSTR_ID(prefix, name, ...) \
[RABBITIZER_INSTR_ID_##prefix##_##name] = #name
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) \
[RABBITIZER_INSTR_ID_##prefix##_##name] = #altname
#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, name, altname, ...) [RABBITIZER_INSTR_ID_##prefix##_##name] = #altname
const char *RabbitizerInstrId_Names[] = {
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
#include "instructions/instr_id/RabbitizerInstrId_rsp.inc"
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"
#include "instructions/instr_id/RabbitizerInstrId_rsp.inc"
};
#undef RABBITIZER_DEF_INSTR_ID
#undef RABBITIZER_DEF_INSTR_ID_ALTNAME
const char *RabbitizerInstrId_getOpcodeName(RabbitizerInstrId uniqueId) {
assert(uniqueId >= RABBITIZER_INSTR_ID_cpu_INVALID && uniqueId < RABBITIZER_INSTR_ID_ALL_MAX);
assert(uniqueId != RABBITIZER_INSTR_ID_cpu_MAX);

View File

@ -9,7 +9,6 @@
#include "instructions/RabbitizerRegister.h"
#include "instructions/RabbitizerInstructionRsp.h"
void RabbitizerInstruction_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram) {
self->word = word;
self->_mandatorybits = 0;
@ -23,11 +22,9 @@ void RabbitizerInstruction_init(RabbitizerInstruction *self, uint32_t word, uint
self->category = RABBITIZER_INSTRCAT_CPU;
}
void RabbitizerInstruction_destroy(RabbitizerInstruction *self) {
(void)self;
void RabbitizerInstruction_destroy(UNUSED RabbitizerInstruction *self) {
}
/* General getters */
uint32_t RabbitizerInstruction_getRaw(const RabbitizerInstruction *self) {
@ -55,7 +52,7 @@ uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction *
vram |= 0x80000000;
} else {
// Jumps are PC-region branches. The upper bits are filled with the address in the delay slot
vram |= (self->vram+4) & 0xFF000000;
vram |= (self->vram + 4) & 0xFF000000;
}
return vram;
}
@ -63,7 +60,7 @@ uint32_t RabbitizerInstruction_getInstrIndexAsVram(const RabbitizerInstruction *
int32_t RabbitizerInstruction_getBranchOffset(const RabbitizerInstruction *self) {
int32_t diff = RabbitizerUtils_From2Complement(RabbitizerInstruction_getImmediate(self), 16);
return diff*4 + 4;
return diff * 4 + 4;
}
int32_t RabbitizerInstruction_getGenericBranchOffset(const RabbitizerInstruction *self, uint32_t currentVram) {
@ -75,7 +72,6 @@ int32_t RabbitizerInstruction_getGenericBranchOffset(const RabbitizerInstruction
/* General getters */
void RabbitizerInstruction_blankOut(RabbitizerInstruction *self) {
size_t i;
@ -192,7 +188,7 @@ void RabbitizerInstruction_blankOut(RabbitizerInstruction *self) {
case RABBITIZER_OPERAND_TYPE_RSP_offset_rs:
self->word = RAB_INSTR_RSP_PACK_offset(self->word, 0);
self->word = RAB_INSTR_PACK_rs(self->word, 0);;
self->word = RAB_INSTR_PACK_rs(self->word, 0);
break;
case RABBITIZER_OPERAND_TYPE_INVALID:

View File

@ -12,38 +12,8 @@
#include "common/RabbitizerConfig.h"
#include "instructions/RabbitizerRegister.h"
#define RABUTILS_BUFFER_ADVANCE(buffer, totalSize, expression) \
do { \
size_t __tempSize = expression; \
(buffer) += __tempSize; \
(totalSize) += __tempSize; \
} while(0)
#define RABUTILS_BUFFER_WRITE_CHAR(buffer, totalSize, character) \
do { \
*(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__); \
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); \
RABUTILS_BUFFER_ADVANCE(buffer, totalSize, _tempSize); \
} while(0)
typedef size_t (*OperandCallback)(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength);
size_t RabbitizerOperandType_processRs(const RabbitizerInstruction *self, char *dst, UNUSED const char *immOverride, UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
const char *reg = RabbitizerRegister_getNameGpr(RAB_INSTR_GET_rs(self));
@ -119,14 +89,14 @@ size_t RabbitizerOperandType_processCop2t(const RabbitizerInstruction *self, cha
size_t RabbitizerOperandType_processSa(const RabbitizerInstruction *self, char *dst, UNUSED const char *immOverride, UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
// TODO: consider making this a proper configuration
#if 0
// TODO: consider making this a proper configuration
#if 0
if (RAB_INSTR_GET_sa(self) < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", RAB_INSTR_GET_sa(self));
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", RAB_INSTR_GET_sa(self));
}
#endif
#endif
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", RAB_INSTR_GET_sa(self));
return totalSize;
}
@ -134,14 +104,14 @@ size_t RabbitizerOperandType_processSa(const RabbitizerInstruction *self, char *
size_t RabbitizerOperandType_processOp(const RabbitizerInstruction *self, char *dst, UNUSED const char *immOverride, UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
// TODO: consider making this a proper configuration
#if 0
// TODO: consider making this a proper configuration
#if 0
if (RAB_INSTR_GET_op(self) < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", RAB_INSTR_GET_op(self));
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", RAB_INSTR_GET_op(self));
}
#endif
#endif
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%02X", RAB_INSTR_GET_op(self));
return totalSize;
}
@ -206,12 +176,12 @@ size_t RabbitizerOperandType_processImmediate(const RabbitizerInstruction *self,
size_t RabbitizerOperandType_processImmediateBase(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength) {
size_t totalSize = 0;
// TODO: consider making this a proper configuration
#if 0
// TODO: consider making this a proper configuration
#if 0
if (immOverride != NULL || RAB_INSTR_GET_immediate(self) != 0) {
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerOperandType_processImmediate(self, dst, immOverride, immOverrideLength));
}
#endif
#endif
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerOperandType_processImmediate(self, dst, immOverride, immOverrideLength));
RABUTILS_BUFFER_WRITE_CHAR(dst, totalSize, '(');
@ -331,39 +301,38 @@ size_t RabbitizerOperandTypeRsp_processOffsetVs(const RabbitizerInstruction *sel
}
const OperandCallback instrOpercandCallbacks[] = {
[RABBITIZER_OPERAND_TYPE_rs] = RabbitizerOperandType_processRs,
[RABBITIZER_OPERAND_TYPE_rt] = RabbitizerOperandType_processRt,
[RABBITIZER_OPERAND_TYPE_rd] = RabbitizerOperandType_processRd,
[RABBITIZER_OPERAND_TYPE_cop0d] = RabbitizerOperandType_processCop0d,
[RABBITIZER_OPERAND_TYPE_fs] = RabbitizerOperandType_processFs,
[RABBITIZER_OPERAND_TYPE_ft] = RabbitizerOperandType_processFt,
[RABBITIZER_OPERAND_TYPE_fd] = RabbitizerOperandType_processFd,
[RABBITIZER_OPERAND_TYPE_cop1cs] = RabbitizerOperandType_processCop1Cs,
[RABBITIZER_OPERAND_TYPE_cop2t] = RabbitizerOperandType_processCop2t,
[RABBITIZER_OPERAND_TYPE_sa] = RabbitizerOperandType_processSa,
[RABBITIZER_OPERAND_TYPE_op] = RabbitizerOperandType_processOp,
[RABBITIZER_OPERAND_TYPE_code] = RabbitizerOperandType_processCode,
[RABBITIZER_OPERAND_TYPE_LABEL] = RabbitizerOperandType_processLabel,
[RABBITIZER_OPERAND_TYPE_IMM] = RabbitizerOperandType_processImmediate,
[RABBITIZER_OPERAND_TYPE_IMM_base] = RabbitizerOperandType_processImmediateBase,
[RABBITIZER_OPERAND_TYPE_rs] = RabbitizerOperandType_processRs,
[RABBITIZER_OPERAND_TYPE_rt] = RabbitizerOperandType_processRt,
[RABBITIZER_OPERAND_TYPE_rd] = RabbitizerOperandType_processRd,
[RABBITIZER_OPERAND_TYPE_cop0d] = RabbitizerOperandType_processCop0d,
[RABBITIZER_OPERAND_TYPE_fs] = RabbitizerOperandType_processFs,
[RABBITIZER_OPERAND_TYPE_ft] = RabbitizerOperandType_processFt,
[RABBITIZER_OPERAND_TYPE_fd] = RabbitizerOperandType_processFd,
[RABBITIZER_OPERAND_TYPE_cop1cs] = RabbitizerOperandType_processCop1Cs,
[RABBITIZER_OPERAND_TYPE_cop2t] = RabbitizerOperandType_processCop2t,
[RABBITIZER_OPERAND_TYPE_sa] = RabbitizerOperandType_processSa,
[RABBITIZER_OPERAND_TYPE_op] = RabbitizerOperandType_processOp,
[RABBITIZER_OPERAND_TYPE_code] = RabbitizerOperandType_processCode,
[RABBITIZER_OPERAND_TYPE_LABEL] = RabbitizerOperandType_processLabel,
[RABBITIZER_OPERAND_TYPE_IMM] = RabbitizerOperandType_processImmediate,
[RABBITIZER_OPERAND_TYPE_IMM_base] = RabbitizerOperandType_processImmediateBase,
// rsp
[RABBITIZER_OPERAND_TYPE_RSP_rs] = RabbitizerOperandTypeRsp_processRs,
[RABBITIZER_OPERAND_TYPE_RSP_rt] = RabbitizerOperandTypeRsp_processRt,
[RABBITIZER_OPERAND_TYPE_RSP_rd] = RabbitizerOperandTypeRsp_processRd,
[RABBITIZER_OPERAND_TYPE_RSP_cop0d] = RabbitizerOperandTypeRsp_processCop0d,
[RABBITIZER_OPERAND_TYPE_RSP_vs] = RabbitizerOperandTypeRsp_processVs,
[RABBITIZER_OPERAND_TYPE_RSP_vt] = RabbitizerOperandTypeRsp_processVt,
[RABBITIZER_OPERAND_TYPE_RSP_vd] = RabbitizerOperandTypeRsp_processVd,
[RABBITIZER_OPERAND_TYPE_RSP_vt_elementhigh] = RabbitizerOperandTypeRsp_processVtElementhigh,
[RABBITIZER_OPERAND_TYPE_RSP_vt_elementlow] = RabbitizerOperandTypeRsp_processVtElementlow,
[RABBITIZER_OPERAND_TYPE_RSP_vd_vs] = RabbitizerOperandTypeRsp_processVdVs,
[RABBITIZER_OPERAND_TYPE_RSP_vd_index] = RabbitizerOperandTypeRsp_processVdIndex,
[RABBITIZER_OPERAND_TYPE_RSP_offset_rs] = RabbitizerOperandTypeRsp_processOffsetVs,
[RABBITIZER_OPERAND_TYPE_RSP_rs] = RabbitizerOperandTypeRsp_processRs,
[RABBITIZER_OPERAND_TYPE_RSP_rt] = RabbitizerOperandTypeRsp_processRt,
[RABBITIZER_OPERAND_TYPE_RSP_rd] = RabbitizerOperandTypeRsp_processRd,
[RABBITIZER_OPERAND_TYPE_RSP_cop0d] = RabbitizerOperandTypeRsp_processCop0d,
[RABBITIZER_OPERAND_TYPE_RSP_vs] = RabbitizerOperandTypeRsp_processVs,
[RABBITIZER_OPERAND_TYPE_RSP_vt] = RabbitizerOperandTypeRsp_processVt,
[RABBITIZER_OPERAND_TYPE_RSP_vd] = RabbitizerOperandTypeRsp_processVd,
[RABBITIZER_OPERAND_TYPE_RSP_vt_elementhigh] = RabbitizerOperandTypeRsp_processVtElementhigh,
[RABBITIZER_OPERAND_TYPE_RSP_vt_elementlow] = RabbitizerOperandTypeRsp_processVtElementlow,
[RABBITIZER_OPERAND_TYPE_RSP_vd_vs] = RabbitizerOperandTypeRsp_processVdVs,
[RABBITIZER_OPERAND_TYPE_RSP_vd_index] = RabbitizerOperandTypeRsp_processVdIndex,
[RABBITIZER_OPERAND_TYPE_RSP_offset_rs] = RabbitizerOperandTypeRsp_processOffsetVs,
};
size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust) {
size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInstruction *self, size_t immOverrideLength) {
size_t totalSize = 0;
for (size_t i = 0; i < ARRAY_COUNT(self->descriptor->operands) && self->descriptor->operands[i] != RABBITIZER_OPERAND_TYPE_INVALID; i++) {
@ -379,7 +348,7 @@ size_t RabbitizerInstruction_getSizeForBufferOperandsDisasm(const RabbitizerInst
return totalSize;
}
size_t RabbitizerInstruction_disassembleOperands(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust) {
size_t RabbitizerInstruction_disassembleOperands(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength) {
size_t totalSize = 0;
for (size_t i = 0; i < ARRAY_COUNT(self->descriptor->operands) && self->descriptor->operands[i] != RABBITIZER_OPERAND_TYPE_INVALID; i++) {
@ -405,7 +374,6 @@ size_t RabbitizerInstruction_disassembleOperands(const RabbitizerInstruction *se
return totalSize;
}
size_t RabbitizerInstruction_getSizeForBufferInstrDisasm(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust) {
size_t totalSize = 0;
size_t opcodeNameLength;
@ -422,12 +390,13 @@ size_t RabbitizerInstruction_getSizeForBufferInstrDisasm(const RabbitizerInstruc
totalSize += extraLJust;
totalSize++;
totalSize += RabbitizerInstruction_getSizeForBufferOperandsDisasm(self, immOverrideLength, extraLJust);
totalSize += RabbitizerInstruction_getSizeForBufferOperandsDisasm(self, immOverrideLength);
return totalSize;
}
size_t RabbitizerInstruction_disassembleInstruction(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust) {
size_t RabbitizerInstruction_disassembleInstruction(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength,
int extraLJust) {
size_t totalSize = 0;
const char *opcodeName = RabbitizerInstrId_getOpcodeName(self->uniqueId);
@ -442,13 +411,12 @@ size_t RabbitizerInstruction_disassembleInstruction(const RabbitizerInstruction
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerUtils_CharFill(dst, RabbitizerConfig_Cfg.misc.opcodeLJust + extraLJust - totalSize, ' '));
RABUTILS_BUFFER_WRITE_CHAR(dst, totalSize, ' ');
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerInstruction_disassembleOperands(self, dst, immOverride, immOverrideLength, extraLJust));
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerInstruction_disassembleOperands(self, dst, immOverride, immOverrideLength));
*dst = '\0';
return totalSize;
}
size_t RabbitizerInstruction_getSizeForBufferDataDisasm(UNUSED const RabbitizerInstruction *self, int extraLJust) {
size_t totalSize = 0;
@ -458,7 +426,6 @@ size_t RabbitizerInstruction_getSizeForBufferDataDisasm(UNUSED const RabbitizerI
return totalSize;
}
size_t RabbitizerInstruction_disassembleAsData(const RabbitizerInstruction *self, char *dst, int extraLJust) {
size_t totalSize = 0;
@ -470,7 +437,6 @@ size_t RabbitizerInstruction_disassembleAsData(const RabbitizerInstruction *self
return totalSize;
}
bool RabbitizerInstruction_mustDisasmAsData(const RabbitizerInstruction *self) {
if (RabbitizerConfig_Cfg.toolchainTweaks.sn64DivFix) {
if (self->uniqueId == RABBITIZER_INSTR_ID_cpu_break) {
@ -484,7 +450,6 @@ bool RabbitizerInstruction_mustDisasmAsData(const RabbitizerInstruction *self) {
return false;
}
size_t RabbitizerInstruction_getSizeForBuffer(const RabbitizerInstruction *self, size_t immOverrideLength, int extraLJust) {
if (!RabbitizerInstruction_isImplemented(self) || RabbitizerInstruction_mustDisasmAsData(self)) {
size_t totalSize = RabbitizerInstruction_getSizeForBufferDataDisasm(self, extraLJust);
@ -497,10 +462,9 @@ size_t RabbitizerInstruction_getSizeForBuffer(const RabbitizerInstruction *self,
return totalSize;
}
return RabbitizerInstruction_getSizeForBufferInstrDisasm(self,immOverrideLength, extraLJust);
return RabbitizerInstruction_getSizeForBufferInstrDisasm(self, immOverrideLength, extraLJust);
}
size_t RabbitizerInstruction_disassemble(const RabbitizerInstruction *self, char *dst, const char *immOverride, size_t immOverrideLength, int extraLJust) {
assert(dst != NULL);
@ -510,7 +474,7 @@ size_t RabbitizerInstruction_disassemble(const RabbitizerInstruction *self, char
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerInstruction_disassembleAsData(self, dst, extraLJust));
if (RabbitizerConfig_Cfg.misc.unknownInstrComment) {
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerUtils_CharFill(dst, 40-totalSize, ' '));
RABUTILS_BUFFER_ADVANCE(dst, totalSize, RabbitizerUtils_CharFill(dst, 40 - totalSize, ' '));
RABUTILS_BUFFER_WRITE_CHAR(dst, totalSize, ' ');
RABUTILS_BUFFER_WRITE_CHAR(dst, totalSize, '#');

View File

@ -9,7 +9,6 @@
#include "instructions/RabbitizerInstructionRsp.h"
#include "instructions/RabbitizerRegister.h"
bool RabbitizerInstruction_isImplemented(const RabbitizerInstruction *self) {
if (self->uniqueId == RABBITIZER_INSTR_ID_cpu_INVALID) {
return false;
@ -120,7 +119,6 @@ bool RabbitizerInstruction_sameOpcodeButDifferentArguments(const RabbitizerInstr
return RabbitizerInstruction_getRaw(self) != RabbitizerInstruction_getRaw(other);
}
bool RabbitizerInstruction_hasOperand(const RabbitizerInstruction *self, RabbitizerOperandType operand) {
size_t i;
@ -187,7 +185,6 @@ bool RabbitizerInstruction_hasOperandAlias(const RabbitizerInstruction *self, Ra
}
break;
/* rsp */
case RABBITIZER_OPERAND_TYPE_RSP_rs:
if (RabbitizerInstruction_hasOperand(self, RABBITIZER_OPERAND_TYPE_rs)) {
@ -213,10 +210,10 @@ bool RabbitizerInstruction_hasOperandAlias(const RabbitizerInstruction *self, Ra
case RABBITIZER_OPERAND_TYPE_RSP_cop0d:
break;
// case RABBITIZER_OPERAND_TYPE_RSP_elementhigh:
// case RABBITIZER_OPERAND_TYPE_RSP_elementlow:
// case RABBITIZER_OPERAND_TYPE_RSP_index:
// case RABBITIZER_OPERAND_TYPE_RSP_offset:
// case RABBITIZER_OPERAND_TYPE_RSP_elementhigh:
// case RABBITIZER_OPERAND_TYPE_RSP_elementlow:
// case RABBITIZER_OPERAND_TYPE_RSP_index:
// case RABBITIZER_OPERAND_TYPE_RSP_offset:
case RABBITIZER_OPERAND_TYPE_RSP_vs:
if (RabbitizerInstruction_hasOperand(self, RABBITIZER_OPERAND_TYPE_RSP_vd_vs)) {
@ -274,7 +271,7 @@ bool RabbitizerInstruction_hasOperandAlias(const RabbitizerInstruction *self, Ra
return true;
}
break;
/* rsp */
/* rsp */
case RABBITIZER_OPERAND_TYPE_INVALID:
case RABBITIZER_OPERAND_TYPE_MAX:
@ -285,7 +282,6 @@ bool RabbitizerInstruction_hasOperandAlias(const RabbitizerInstruction *self, Ra
return RabbitizerInstruction_hasOperand(self, operand);
}
bool RabbitizerInstruction_isValid(const RabbitizerInstruction *self) {
size_t i;
uint32_t validbits;
@ -356,7 +352,6 @@ bool RabbitizerInstruction_isValid(const RabbitizerInstruction *self) {
validbits = RAB_INSTR_PACK_rs(validbits, ~0);
break;
case RABBITIZER_OPERAND_TYPE_RSP_rs:
validbits = RAB_INSTR_PACK_rs(validbits, ~0);
break;

View File

@ -7,6 +7,8 @@
#include "instructions/RabbitizerRegister.h"
// NOLINTBEGIN(readability-magic-numbers)
void RabbitizerInstruction_processUniqueId_Normal(RabbitizerInstruction *self) {
uint32_t opcode = RAB_INSTR_GET_opcode(self);
@ -172,7 +174,7 @@ void RabbitizerInstruction_processUniqueId_Normal(RabbitizerInstruction *self) {
break;
case 0b111010:
self->uniqueId = RABBITIZER_INSTR_ID_cpu_swc2;
// 0b111011: "",
// 0b111011: "",
break;
case 0b111100:
self->uniqueId = RABBITIZER_INSTR_ID_cpu_scd;
@ -224,7 +226,6 @@ void RabbitizerInstruction_processUniqueId_Normal(RabbitizerInstruction *self) {
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstruction_processUniqueId_Special(RabbitizerInstruction *self) {
uint32_t function = RAB_INSTR_GET_function(self);
@ -389,7 +390,7 @@ void RabbitizerInstruction_processUniqueId_Special(RabbitizerInstruction *self)
case 0b110110:
self->uniqueId = RABBITIZER_INSTR_ID_cpu_tne;
break;
// 0b110_111: "",
// 0b110_111: "",
case 0b111000:
self->uniqueId = RABBITIZER_INSTR_ID_cpu_dsll;
@ -483,7 +484,6 @@ void RabbitizerInstruction_processUniqueId_Special(RabbitizerInstruction *self)
}
}
void RabbitizerInstruction_processUniqueId_Regimm(RabbitizerInstruction *self) {
uint32_t rt = RAB_INSTR_GET_rt(self);
@ -544,7 +544,6 @@ void RabbitizerInstruction_processUniqueId_Regimm(RabbitizerInstruction *self) {
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstruction_processUniqueId_Coprocessor0(RabbitizerInstruction *self) {
uint32_t fmt = RAB_INSTR_GET_fmt(self);
uint32_t tf;
@ -574,7 +573,7 @@ void RabbitizerInstruction_processUniqueId_Coprocessor0(RabbitizerInstruction *s
case 0b00110:
self->uniqueId = RABBITIZER_INSTR_ID_cpu_ctc0;
break;
// 0b00_111: "",
// 0b00_111: "",
case 0b01000:
tf = RAB_INSTR_GET_tf(self);
@ -626,7 +625,6 @@ void RabbitizerInstruction_processUniqueId_Coprocessor0(RabbitizerInstruction *s
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstruction_processUniqueId_Coprocessor1(RabbitizerInstruction *self) {
uint8_t fmt = RAB_INSTR_GET_fmt(self);
uint8_t fc;
@ -967,15 +965,12 @@ void RabbitizerInstruction_processUniqueId_Coprocessor1(RabbitizerInstruction *s
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstruction_processUniqueId_Coprocessor2(RabbitizerInstruction *self) {
self->_handwrittenCategory = true;
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstruction_processUniqueId(RabbitizerInstruction *self) {
uint32_t opcode = RAB_INSTR_GET_opcode(self);
@ -1002,3 +997,5 @@ void RabbitizerInstruction_processUniqueId(RabbitizerInstruction *self) {
break;
}
}
// NOLINTEND(readability-magic-numbers)

View File

@ -3,7 +3,6 @@
#include "instructions/RabbitizerInstructionRsp.h"
void RabbitizerInstructionRsp_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram) {
RabbitizerInstruction_init(self, word, vram);
@ -18,7 +17,6 @@ void RabbitizerInstructionRsp_destroy(RabbitizerInstruction *self) {
RabbitizerInstruction_destroy(self);
}
uint16_t RabbitizerInstructionRsp_GetOffsetVector(const RabbitizerInstruction *self) {
uint16_t offset = RAB_INSTR_RSP_GET_OFFSET_VECTOR_RAW(self);
@ -57,9 +55,7 @@ uint16_t RabbitizerInstructionRsp_GetOffsetVector(const RabbitizerInstruction *s
}
}
uint8_t RabbitizerInstructionRsp_processVectorElement(const RabbitizerInstruction *self, uint8_t element) {
(void)self;
uint8_t RabbitizerInstructionRsp_processVectorElement(UNUSED const RabbitizerInstruction *self, uint8_t element) {
if ((element & 0x8) == 0x8) {
return element & 7;
}

View File

@ -6,6 +6,8 @@
#include "common/RabbitizerConfig.h"
// NOLINTBEGIN(readability-magic-numbers)
void RabbitizerInstructionRsp_processUniqueId_Normal(RabbitizerInstruction *self) {
uint32_t opcode = RAB_INSTR_GET_opcode(self);
uint32_t rd;
@ -221,7 +223,6 @@ void RabbitizerInstructionRsp_processUniqueId_Normal(RabbitizerInstruction *self
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstructionRsp_processUniqueId_Special(RabbitizerInstruction *self) {
uint32_t function = RAB_INSTR_GET_function(self);
@ -333,7 +334,6 @@ void RabbitizerInstructionRsp_processUniqueId_Special(RabbitizerInstruction *sel
}
}
void RabbitizerInstructionRsp_processUniqueId_Regimm(RabbitizerInstruction *self) {
uint32_t rt = RAB_INSTR_GET_rt(self);
@ -362,7 +362,6 @@ void RabbitizerInstructionRsp_processUniqueId_Regimm(RabbitizerInstruction *self
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstructionRsp_processUniqueId_Coprocessor0(RabbitizerInstruction *self) {
uint32_t fmt = RAB_INSTR_GET_fmt(self);
@ -385,9 +384,8 @@ void RabbitizerInstructionRsp_processUniqueId_Coprocessor0(RabbitizerInstruction
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstructionRsp_processUniqueId_Coprocessor2(RabbitizerInstruction *self) {
uint32_t aux = SHIFTR(self->word, 25, 1);
uint32_t aux = SHIFTR(self->word, 25, 1);
uint32_t elementhigh;
uint32_t function;
@ -566,7 +564,6 @@ void RabbitizerInstructionRsp_processUniqueId_Coprocessor2(RabbitizerInstruction
self->descriptor = &RabbitizerInstrDescriptor_Descriptors[self->uniqueId];
}
void RabbitizerInstructionRsp_processUniqueId(RabbitizerInstruction *self) {
uint32_t opcode = RAB_INSTR_GET_opcode(self);
@ -585,7 +582,7 @@ void RabbitizerInstructionRsp_processUniqueId(RabbitizerInstruction *self) {
case 0x10:
RabbitizerInstructionRsp_processUniqueId_Coprocessor0(self);
break;
//case 0x11:
// case 0x11:
// RabbitizerInstructionRsp_processUniqueId_Coprocessor1(self);
// break;
case 0x12:
@ -593,3 +590,5 @@ void RabbitizerInstructionRsp_processUniqueId(RabbitizerInstruction *self) {
break;
}
}
// NOLINTEND(readability-magic-numbers)

View File

@ -8,60 +8,56 @@
#include "common/Utils.h"
#include "common/RabbitizerConfig.h"
#define RABBITIZER_DEF_REG(prefix, name, numeric) [RABBITIZER_REG_##prefix##_##name] = { "$" #numeric, "$" #name }
#define RABBITIZER_DEF_REG(prefix, name, numeric) \
[RABBITIZER_REG_##prefix##_##name] = { "$" #numeric, "$" #name }
#define RABBITIZER_DEF_REG_NODOLLAR(prefix, name, numeric) \
[RABBITIZER_REG_##prefix##_##name] = { "$" #numeric, #name }
#define RABBITIZER_DEF_REG_NODOLLAR(prefix, name, numeric) [RABBITIZER_REG_##prefix##_##name] = { "$" #numeric, #name }
// numeric, named
const char *RabbitizerRegister_GprO32_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_GprO32.inc"
#include "instructions/registers/RabbitizerRegister_GprO32.inc"
};
const char *RabbitizerRegister_GprN32_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_GprN32.inc"
#include "instructions/registers/RabbitizerRegister_GprN32.inc"
};
const char *RabbitizerRegister_Cop0_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop0.inc"
#include "instructions/registers/RabbitizerRegister_Cop0.inc"
};
const char *RabbitizerRegister_Cop1O32_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop1O32.inc"
#include "instructions/registers/RabbitizerRegister_Cop1O32.inc"
};
const char *RabbitizerRegister_Cop1N32_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop1N32.inc"
#include "instructions/registers/RabbitizerRegister_Cop1N32.inc"
};
const char *RabbitizerRegister_Cop1N64_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop1N64.inc"
#include "instructions/registers/RabbitizerRegister_Cop1N64.inc"
};
const char *RabbitizerRegister_Cop1Control_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop1Control.inc"
#include "instructions/registers/RabbitizerRegister_Cop1Control.inc"
};
const char *RabbitizerRegister_Cop2_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_Cop2.inc"
#include "instructions/registers/RabbitizerRegister_Cop2.inc"
};
const char *RabbitizerRegister_RspGpr_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_RspGpr.inc"
#include "instructions/registers/RabbitizerRegister_RspGpr.inc"
};
const char *RabbitizerRegister_RspCop0_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_RspCop0.inc"
#include "instructions/registers/RabbitizerRegister_RspCop0.inc"
};
const char *RabbitizerRegister_RspVector_Names[][2] = {
#include "instructions/registers/RabbitizerRegister_RspVector.inc"
#include "instructions/registers/RabbitizerRegister_RspVector.inc"
};
const char *RabbitizerRegister_getNameGpr(uint8_t regValue) {
assert(regValue < ARRAY_COUNT(RabbitizerRegister_GprO32_Names));
@ -82,7 +78,8 @@ const char *RabbitizerRegister_getNameGpr(uint8_t regValue) {
const char *RabbitizerRegister_getNameCop0(uint8_t regValue) {
assert(regValue < ARRAY_COUNT(RabbitizerRegister_Cop0_Names));
return RabbitizerRegister_Cop0_Names[regValue][RabbitizerConfig_Cfg.regNames.namedRegisters && RabbitizerConfig_Cfg.regNames.vr4300Cop0NamedRegisters ? 1 : 0];
return RabbitizerRegister_Cop0_Names[regValue]
[RabbitizerConfig_Cfg.regNames.namedRegisters && RabbitizerConfig_Cfg.regNames.vr4300Cop0NamedRegisters ? 1 : 0];
}
const char *RabbitizerRegister_getNameCop1(uint8_t regValue) {
@ -125,7 +122,8 @@ const char *RabbitizerRegister_getNameRspGpr(uint8_t regValue) {
const char *RabbitizerRegister_getNameRspCop0(uint8_t regValue) {
assert(regValue < ARRAY_COUNT(RabbitizerRegister_RspCop0_Names));
return RabbitizerRegister_RspCop0_Names[regValue][RabbitizerConfig_Cfg.regNames.namedRegisters && RabbitizerConfig_Cfg.regNames.vr4300RspCop0NamedRegisters ? 1 : 0];
return RabbitizerRegister_RspCop0_Names[regValue]
[RabbitizerConfig_Cfg.regNames.namedRegisters && RabbitizerConfig_Cfg.regNames.vr4300RspCop0NamedRegisters ? 1 : 0];
}
const char *RabbitizerRegister_getNameRspVector(uint8_t regValue) {

9
test.c
View File

@ -5,6 +5,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -17,7 +18,7 @@ int main() {
// word = 0x8D4A7E18; // lw
word = 0x00004010; // mfhi
RabbitizerInstruction_init(&instr, word);
RabbitizerInstruction_init(&instr, word, 0x80000000);
RabbitizerInstruction_processUniqueId(&instr);
@ -31,5 +32,11 @@ int main() {
free(buffer);
RabbitizerInstruction_destroy(&instr);
char someMagicBuffer[0x1000];
RabbitizerUtils_escapeString(someMagicBuffer, ARRAY_COUNT(someMagicBuffer), "\tsomeExample\n", strlen("\tsomeExample\n"));
printf("%s\n", someMagicBuffer);
return 0;
}