diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-05-28 14:58:37 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-05-28 14:58:37 +0000 |
commit | 97c2c108fd23a377ca21f89d25dc021ffa884b19 (patch) | |
tree | bba70d79cf628687cf784a8239e4034117f78314 /llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp | |
parent | a3dc1ba142c5c1f8e4b53e501597904c23e5c61f (diff) | |
download | bcm5719-llvm-97c2c108fd23a377ca21f89d25dc021ffa884b19.tar.gz bcm5719-llvm-97c2c108fd23a377ca21f89d25dc021ffa884b19.zip |
[x86] avoid printing unnecessary sign bits of hex immediates in asm comments (PR20347)
It would be better to check the valid/expected size of the immediate operand, but this is
generally better than what we print right now.
Differential Revision: http://reviews.llvm.org/D20385
llvm-svn: 271114
Diffstat (limited to 'llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp')
-rw-r--r-- | llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp b/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp index 855e108a2bc..3a5d056888a 100644 --- a/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp +++ b/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp @@ -165,16 +165,25 @@ void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, if (Op.isReg()) { printRegName(O, Op.getReg()); } else if (Op.isImm()) { - // Print X86 immediates as signed values. + // Print immediates as signed values. int64_t Imm = Op.getImm(); O << markup("<imm:") << '$' << formatImm(Imm) << markup(">"); + // TODO: This should be in a helper function in the base class, so it can + // be used by other printers. + // If there are no instruction-specific comments, add a comment clarifying // the hex value of the immediate operand when it isn't in the range // [-256,255]. - if (CommentStream && !HasCustomInstComment && (Imm > 255 || Imm < -256)) - *CommentStream << format("imm = 0x%" PRIX64 "\n", (uint64_t)Imm); - + if (CommentStream && !HasCustomInstComment && (Imm > 255 || Imm < -256)) { + // Don't print unnecessary hex sign bits. + if (Imm == (int16_t)(Imm)) + *CommentStream << format("imm = 0x%" PRIX16 "\n", (uint16_t)Imm); + else if (Imm == (int32_t)(Imm)) + *CommentStream << format("imm = 0x%" PRIX32 "\n", (uint32_t)Imm); + else + *CommentStream << format("imm = 0x%" PRIX64 "\n", (uint64_t)Imm); + } } else { assert(Op.isExpr() && "unknown operand kind in printOperand"); O << markup("<imm:") << '$'; |