x86: print immediate without prefix 0x if the number is under 10

_v3_old
Nguyen Anh Quynh 11 years ago
parent e5c658c407
commit f22557ba88
  1. 37
      arch/X86/X86ATTInstPrinter.c
  2. 37
      arch/X86/X86IntelInstPrinter.c

@ -133,8 +133,12 @@ static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].mem.disp = imm;
if (imm < 0)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "0x%"PRIx64, imm);
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
}
}
SStream_concat(O, "%s", markup(">"));
@ -257,8 +261,12 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
int64_t imm = MCOperand_getImm(Op) + MI->pub_insn.size + MI->pub_insn.address;
if (imm < 0)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "0x%"PRIx64, imm);
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
}
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].type = X86_OP_IMM;
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].imm = imm;
MI->pub_insn.x86.op_count++;
@ -276,7 +284,10 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
} else if (MCOperand_isImm(Op)) {
// Print X86 immediates as signed values.
int64_t imm = MCOperand_getImm(Op);
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), imm, markup(">"));
if (imm > HEX_THRESHOLD)
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), imm, markup(">"));
else
SStream_concat(O, "%s$%"PRIu64"%s", markup("<imm:"), imm, markup(">"));
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].type = X86_OP_IMM;
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].imm = imm;
MI->pub_insn.x86.op_count++;
@ -294,8 +305,12 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
int64_t imm = MCOperand_getImm(Op);
if (imm < 0)
SStream_concat(O, "%s$-0x%"PRIx64"%s", markup("<imm:"), -imm, markup(">"));
else
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), imm, markup(">"));
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), imm, markup(">"));
else
SStream_concat(O, "%s$%"PRIu64"%s", markup("<imm:"), imm, markup(">"));
}
}
}
@ -326,8 +341,12 @@ static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
if (DispVal || (!MCOperand_getReg(IndexReg) && !MCOperand_getReg(BaseReg))) {
if (DispVal < 0)
SStream_concat(O, "-0x%"PRIx64, -DispVal);
else
SStream_concat(O, "0x%"PRIx64, DispVal);
else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);
else
SStream_concat(O, "%"PRIu64, DispVal);
}
}
}

@ -130,8 +130,12 @@ static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].mem.disp = imm;
if (imm < 0)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "0x%"PRIx64, imm);
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
}
}
SStream_concat(O, "]");
@ -315,8 +319,12 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
int64_t imm = MCOperand_getImm(Op) + MI->pub_insn.size + MI->pub_insn.address;
if (imm < 0)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "0x%"PRIx64, imm);
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
}
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].type = X86_OP_IMM;
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].imm = imm;
MI->pub_insn.x86.op_count++;
@ -339,7 +347,10 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
MI->pub_insn.x86.op_count++;
} else if (MCOperand_isImm(Op)) {
int64_t imm = MCOperand_getImm(Op);
SStream_concat(O, "0x%"PRIx64, imm);
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].type = X86_OP_IMM;
MI->pub_insn.x86.operands[MI->pub_insn.x86.op_count].imm = imm;
MI->pub_insn.x86.op_count++;
@ -356,8 +367,12 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
int64_t imm = MCOperand_getImm(Op);
if (imm < 0)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "0x%"PRIx64, imm);
else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
else
SStream_concat(O, "%"PRIu64, imm);
}
}
}
@ -414,8 +429,12 @@ static void printMemReference(MCInst *MI, unsigned Op, SStream *O) // qqq
}
if (DispVal < 0)
SStream_concat(O, "-0x%"PRIx64, -DispVal);
else
SStream_concat(O, "0x%"PRIx64, DispVal);
else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);
else
SStream_concat(O, "%"PRIu64, DispVal);
}
}
}

Loading…
Cancel
Save