Allow disabling upper case for immediates

This commit is contained in:
Angie 2022-07-07 00:44:30 -04:00
parent 3d70f9d285
commit d5b4b096b4
5 changed files with 22 additions and 10 deletions

View File

@ -57,7 +57,8 @@ typedef struct RabbitizerConfig_ToolchainTweaks {
typedef struct RabbitizerConfig_Misc { typedef struct RabbitizerConfig_Misc {
int opcodeLJust; // The minimal number of characters to left-align the opcode name int opcodeLJust; // The minimal number of characters to left-align the opcode name
bool unknownInstrComment; // Generate a pseudo-disassembly comment when disassembling non implemented instructions bool unknownInstrComment; // Generate a pseudo-disassembly comment when disassembling non implemented instructions
bool omit0XOnSmallHex; bool omit0XOnSmallImm;
bool upperCaseImm;
} RabbitizerConfig_Misc; } RabbitizerConfig_Misc;
typedef struct RabbitizerConfig { typedef struct RabbitizerConfig {

View File

@ -39,6 +39,7 @@ class _RabbitizerConfig:
misc_opcodeLJust: int = 11 misc_opcodeLJust: int = 11
misc_unknownInstrComment: bool = True misc_unknownInstrComment: bool = True
misc_omit0XOnSmallHex: bool = False misc_omit0XOnSmallImm: bool = False
misc_upperCaseImm: bool = False
config: _RabbitizerConfig config: _RabbitizerConfig

View File

@ -124,7 +124,8 @@ DEF_MEMBER_GET_SET_BOOL(toolchainTweaks, sn64DivFix)
DEF_MEMBER_GET_SET_INT(misc, opcodeLJust, false, 0, 0) DEF_MEMBER_GET_SET_INT(misc, opcodeLJust, false, 0, 0)
DEF_MEMBER_GET_SET_BOOL(misc, unknownInstrComment) DEF_MEMBER_GET_SET_BOOL(misc, unknownInstrComment)
DEF_MEMBER_GET_SET_BOOL(misc, omit0XOnSmallHex) DEF_MEMBER_GET_SET_BOOL(misc, omit0XOnSmallImm)
DEF_MEMBER_GET_SET_BOOL(misc, upperCaseImm)
static PyGetSetDef rabbitizer_global_config_GetSets[] = { static PyGetSetDef rabbitizer_global_config_GetSets[] = {
@ -148,7 +149,8 @@ static PyGetSetDef rabbitizer_global_config_GetSets[] = {
MEMBER_GET_SET(misc, opcodeLJust, "", NULL), MEMBER_GET_SET(misc, opcodeLJust, "", NULL),
MEMBER_GET_SET(misc, unknownInstrComment, "", NULL), MEMBER_GET_SET(misc, unknownInstrComment, "", NULL),
MEMBER_GET_SET(misc, omit0XOnSmallHex, "", NULL), MEMBER_GET_SET(misc, omit0XOnSmallImm, "", NULL),
MEMBER_GET_SET(misc, upperCaseImm, "", NULL),
{ 0 }, { 0 },
}; };

View File

@ -45,6 +45,7 @@ RabbitizerConfig RabbitizerConfig_Cfg = {
.misc = { .misc = {
.opcodeLJust = 7+4, .opcodeLJust = 7+4,
.unknownInstrComment = true, .unknownInstrComment = true,
.omit0XOnSmallHex = false, .omit0XOnSmallImm = false,
.upperCaseImm = true,
} }
}; };

View File

@ -151,8 +151,7 @@ size_t RabbitizerOperandType_processLabel(const RabbitizerInstruction *self, cha
return immOverrideLength; return immOverrideLength;
} }
RABUTILS_BUFFER_CPY(dst, totalSize, "func_"); RABUTILS_BUFFER_SPRINTF(dst, totalSize, "func_%06X", RabbitizerInstruction_getInstrIndexAsVram(self));
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%06X", RabbitizerInstruction_getInstrIndexAsVram(self));
return totalSize; return totalSize;
} }
@ -166,16 +165,24 @@ size_t RabbitizerOperandType_processImmediate(const RabbitizerInstruction *self,
} }
number = RabbitizerInstruction_getProcessedImmediate(self); number = RabbitizerInstruction_getProcessedImmediate(self);
if (RabbitizerConfig_Cfg.misc.omit0XOnSmallHex) { if (RabbitizerConfig_Cfg.misc.omit0XOnSmallImm) {
if (number > -10 && number < 10) { if (number > -10 && number < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", number); RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", number);
return totalSize; return totalSize;
} }
} }
if (number < 0) { if (number < 0) {
if (RabbitizerConfig_Cfg.misc.upperCaseImm) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%X", -number); RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%X", -number);
} else { } else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "-0x%x", -number);
}
} else {
if (RabbitizerConfig_Cfg.misc.upperCaseImm) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%X", number); RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%X", number);
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", number);
}
} }
return totalSize; return totalSize;
} }