Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
}

if (MO.isImm()) {
markup(O, Markup::Immediate) << formatImm(MO.getImm());
printImm(MI, OpNo, STI, O);
return;
}

Expand Down Expand Up @@ -337,6 +337,22 @@ void RISCVInstPrinter::printVMaskReg(const MCInst *MI, unsigned OpNo,
O << ".t";
}

void RISCVInstPrinter::printImm(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O) {
const MCOperand &Op = MI->getOperand(OpNo);
const unsigned Opcode = MI->getOpcode();
uint64_t Imm = Op.getImm();
if (STI.getTargetTriple().isOSBinFormatMachO() &&
(Opcode == RISCV::ANDI || Opcode == RISCV::ORI || Opcode == RISCV::XORI ||
Opcode == RISCV::C_ANDI || Opcode == RISCV::AUIPC ||
Opcode == RISCV::LUI)) {
if (!STI.hasFeature(RISCV::Feature64Bit))
Imm &= 0xffffffff;
markup(O, Markup::Immediate) << formatHex(Imm);
} else
markup(O, Markup::Immediate) << formatImm(Imm);
}

const char *RISCVInstPrinter::getRegisterName(MCRegister Reg) {
// When PrintAliases is enabled, and EmitX8AsFP is enabled, x8 will be printed
// as fp instead of s0. Note that these similar registers are not replaced:
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class RISCVInstPrinter : public MCInstPrinter {
const MCSubtargetInfo &STI, raw_ostream &O);
void printVMaskReg(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O);
void printImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
raw_ostream &O);
void printRegList(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
raw_ostream &O);
void printStackAdj(const MCInst *MI, unsigned OpNo,
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/MC/RISCV/hex-imm-macho.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: llvm-mc -triple riscv32-apple-unknown-macho -mattr=+c --riscv-no-aliases %s | FileCheck %s

// CHECK: andi a0, a0, 0x190
// CHECK: ori a0, a0, 0x400
// CHECK: xori a0, a0, 0xfffffff4
andi a0, a0, 400
ori a0, a0, 1024
xori a0, a0, -12

// CHECK: c.andi s0, 0x1f
c.andi s0, 31

// CHECK: auipc a0, 0x3e8
// CHECK: lui a0, 0x2710
auipc a0, 1000
lui a0, 10000