diff options
author | Daniel Sanders <daniel.sanders@imgtec.com> | 2016-02-29 16:06:38 +0000 |
---|---|---|
committer | Daniel Sanders <daniel.sanders@imgtec.com> | 2016-02-29 16:06:38 +0000 |
commit | 03a8d2f8ecdbfd531d712e4b0ca0b66c091405db (patch) | |
tree | 58af7d8ed67b2cf4f1cc6a2a2e2963b81f7c03b3 /llvm/lib/Target/Mips/InstPrinter | |
parent | 29620aca3e85cb16434069c86b43a4baf8accc67 (diff) | |
download | bcm5719-llvm-03a8d2f8ecdbfd531d712e4b0ca0b66c091405db.tar.gz bcm5719-llvm-03a8d2f8ecdbfd531d712e4b0ca0b66c091405db.zip |
[mips] Range check uimm20 and fixed a bug this revealed.
Summary:
The bug was that dextu's operand 3 would print 0-31 instead of 32-63 when
printing assembly. This came up when replacing
MipsInstPrinter::printUnsignedImm() with a version that could handle arbitrary
bit widths.
MipsAsmPrinter::printUnsignedImm*() don't seem to be used so they have been
removed.
Reviewers: vkalintiris
Subscribers: dsanders, llvm-commits
Differential Revision: http://reviews.llvm.org/D15521
llvm-svn: 262231
Diffstat (limited to 'llvm/lib/Target/Mips/InstPrinter')
-rw-r--r-- | llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.h | 4 |
2 files changed, 14 insertions, 17 deletions
diff --git a/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp b/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp index a7b7d2e080e..f2ef0b2ad77 100644 --- a/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp +++ b/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp @@ -203,22 +203,19 @@ void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, printExpr(Op.getExpr(), &MAI, O); } -void MipsInstPrinter::printUnsignedImm(const MCInst *MI, int opNum, - raw_ostream &O) { +template <unsigned Bits, unsigned Offset> +void MipsInstPrinter::printUImm(const MCInst *MI, int opNum, raw_ostream &O) { const MCOperand &MO = MI->getOperand(opNum); - if (MO.isImm()) - O << (unsigned short int)MO.getImm(); - else - printOperand(MI, opNum, O); -} + if (MO.isImm()) { + uint64_t Imm = MO.getImm(); + Imm -= Offset; + Imm &= (1 << Bits) - 1; + Imm += Offset; + O << Imm; + return; + } -void MipsInstPrinter::printUnsignedImm8(const MCInst *MI, int opNum, - raw_ostream &O) { - const MCOperand &MO = MI->getOperand(opNum); - if (MO.isImm()) - O << (unsigned short int)(unsigned char)MO.getImm(); - else - printOperand(MI, opNum, O); + printOperand(MI, opNum, O); } void MipsInstPrinter:: @@ -343,7 +340,7 @@ void MipsInstPrinter::printSaveRestore(const MCInst *MI, raw_ostream &O) { if (MI->getOperand(i).isReg()) printRegName(O, MI->getOperand(i).getReg()); else - printUnsignedImm(MI, i, O); + printUImm<16>(MI, i, O); } } diff --git a/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.h b/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.h index 0e61ea61899..4a76b5acac7 100644 --- a/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.h +++ b/llvm/lib/Target/Mips/InstPrinter/MipsInstPrinter.h @@ -93,8 +93,8 @@ public: private: void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); - void printUnsignedImm(const MCInst *MI, int opNum, raw_ostream &O); - void printUnsignedImm8(const MCInst *MI, int opNum, raw_ostream &O); + template <unsigned Bits, unsigned Offset = 0> + void printUImm(const MCInst *MI, int opNum, raw_ostream &O); void printMemOperand(const MCInst *MI, int opNum, raw_ostream &O); void printMemOperandEA(const MCInst *MI, int opNum, raw_ostream &O); void printFCCOperand(const MCInst *MI, int opNum, raw_ostream &O); |