From b23379e5374de40eddb28b7f10d5141660e32f88 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 17 Mar 2016 10:43:36 +0000 Subject: [PATCH] [mips] Use `formatImm` call to print immediate value in the `MipsInstPrinter` That allows, for example, to print hex-formatted immediates using llvm-objdump --print-imm-hex command line option. Differential Revision: http://reviews.llvm.org/D18195 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263704 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp | 4 ++-- test/MC/Mips/hex-immediates.s | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/MC/Mips/hex-immediates.s diff --git a/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp b/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp index f2ef0b2ad77..768ed20f4db 100644 --- a/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp +++ b/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp @@ -195,7 +195,7 @@ void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, } if (Op.isImm()) { - O << Op.getImm(); + O << formatImm(Op.getImm()); return; } @@ -211,7 +211,7 @@ void MipsInstPrinter::printUImm(const MCInst *MI, int opNum, raw_ostream &O) { Imm -= Offset; Imm &= (1 << Bits) - 1; Imm += Offset; - O << Imm; + O << formatImm(Imm); return; } diff --git a/test/MC/Mips/hex-immediates.s b/test/MC/Mips/hex-immediates.s new file mode 100644 index 00000000000..7bf6f71266e --- /dev/null +++ b/test/MC/Mips/hex-immediates.s @@ -0,0 +1,11 @@ +# RUN: llvm-mc -filetype=obj %s -triple=mips-unknown-linux \ +# RUN: | llvm-objdump -d --print-imm-hex - | FileCheck %s + +# CHECK: jal 0x20 +# CHECK: addiu $sp, $sp, -0x20 +# CHECK: sw $2, 0x10($fp) + +jal 32 +addiu $sp, $sp, -32 +sw $2, 16($fp) +lui $2, 2