From 9ecaeea75a84147fc1b379557ace0a68aa9e4ed6 Mon Sep 17 00:00:00 2001 From: Catena cyber <35799796+catenacyber@users.noreply.github.com> Date: Sun, 17 Jun 2018 00:09:25 +0200 Subject: [PATCH] SystemZ MIN_INT right print (#1182) --- arch/SystemZ/SystemZInstPrinter.c | 70 ++++--------------------------- 1 file changed, 7 insertions(+), 63 deletions(-) diff --git a/arch/SystemZ/SystemZInstPrinter.c b/arch/SystemZ/SystemZInstPrinter.c index 5a8f0196..51ede357 100644 --- a/arch/SystemZ/SystemZInstPrinter.c +++ b/arch/SystemZ/SystemZInstPrinter.c @@ -41,17 +41,7 @@ void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) static void printAddress(MCInst *MI, unsigned Base, int64_t Disp, unsigned Index, SStream *O) { - if (Disp >= 0) { - if (Disp > HEX_THRESHOLD) - SStream_concat(O, "0x%"PRIx64, Disp); - else - SStream_concat(O, "%"PRIu64, Disp); - } else { - if (Disp < -HEX_THRESHOLD) - SStream_concat(O, "-0x%"PRIx64, -Disp); - else - SStream_concat(O, "-%"PRIu64, -Disp); - } + printInt64(O, Disp); if (Base) { SStream_concat0(O, "("); @@ -92,17 +82,7 @@ static void _printOperand(MCInst *MI, MCOperand *MO, SStream *O) } else if (MCOperand_isImm(MO)) { int64_t Imm = MCOperand_getImm(MO); - if (Imm >= 0) { - if (Imm > HEX_THRESHOLD) - SStream_concat(O, "0x%"PRIx64, Imm); - else - SStream_concat(O, "%"PRIu64, Imm); - } else { - if (Imm < -HEX_THRESHOLD) - SStream_concat(O, "-0x%"PRIx64, -Imm); - else - SStream_concat(O, "-%"PRIu64, -Imm); - } + printInt64(O, Imm); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM; @@ -116,17 +96,7 @@ static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O) { int64_t Value = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); // assert(isUInt<4>(Value) && "Invalid u4imm argument"); - if (Value >= 0) { - if (Value > HEX_THRESHOLD) - SStream_concat(O, "0x%"PRIx64, Value); - else - SStream_concat(O, "%"PRIu64, Value); - } else { - if (Value < -HEX_THRESHOLD) - SStream_concat(O, "-0x%"PRIx64, -Value); - else - SStream_concat(O, "-%"PRIu64, -Value); - } + printInt64(O, Value); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM; @@ -140,10 +110,7 @@ static void printU6ImmOperand(MCInst *MI, int OpNum, SStream *O) uint32_t Value = (uint32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); // assert(isUInt<6>(Value) && "Invalid u6imm argument"); - if (Value > HEX_THRESHOLD) - SStream_concat(O, "0x%x", Value); - else - SStream_concat(O, "%u", Value); + printUInt32(O, Value); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM; @@ -239,17 +206,7 @@ static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O) int32_t Value = (int32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); // assert(isInt<32>(Value) && "Invalid s32imm argument"); - if (Value >= 0) { - if (Value > HEX_THRESHOLD) - SStream_concat(O, "0x%x", Value); - else - SStream_concat(O, "%u", Value); - } else { - if (Value < -HEX_THRESHOLD) - SStream_concat(O, "-0x%x", -Value); - else - SStream_concat(O, "-%u", -Value); - } + printInt32(O, Value); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM; @@ -263,10 +220,7 @@ static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O) uint32_t Value = (uint32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); // assert(isUInt<32>(Value) && "Invalid u32imm argument"); - if (Value > HEX_THRESHOLD) - SStream_concat(O, "0x%x", Value); - else - SStream_concat(O, "%u", Value); + printUInt32(O, Value); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM; @@ -295,17 +249,7 @@ static void printPCRelOperand(MCInst *MI, int OpNum, SStream *O) if (MCOperand_isImm(MO)) { imm = (int32_t)MCOperand_getImm(MO); - if (imm >= 0) { - if (imm > HEX_THRESHOLD) - SStream_concat(O, "0x%x", imm); - else - SStream_concat(O, "%u", imm); - } else { - if (imm < -HEX_THRESHOLD) - SStream_concat(O, "-0x%x", -imm); - else - SStream_concat(O, "-%u", -imm); - } + printInt32(O, imm); if (MI->csh->detail) { MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;