[MipsInstPrinter] Introduce markup tags emission

MIPS assembly syntax emission now leverages markup tags, if enabled.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129867
This commit is contained in:
Antonio Frighetto 2022-09-01 20:52:08 -07:00 committed by Fangrui Song
parent bb0e6b7721
commit cbb2141f7f
2 changed files with 20 additions and 7 deletions

View File

@ -72,7 +72,8 @@ const char* Mips::MipsFCCToString(Mips::CondCode CC) {
}
void MipsInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
OS << '$' << StringRef(getRegisterName(RegNo)).lower();
OS << markup("<reg:") << '$' << StringRef(getRegisterName(RegNo)).lower()
<< markup(">");
}
void MipsInstPrinter::printInst(const MCInst *MI, uint64_t Address,
@ -132,7 +133,7 @@ void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
}
if (Op.isImm()) {
O << formatImm(Op.getImm());
O << markup("<imm:") << formatImm(Op.getImm()) << markup(">");
return;
}
@ -148,9 +149,9 @@ void MipsInstPrinter::printJumpOperand(const MCInst *MI, unsigned OpNo,
return printOperand(MI, OpNo, STI, O);
if (PrintBranchImmAsAddress)
O << formatHex(Op.getImm());
O << markup("<imm:") << formatHex(Op.getImm()) << markup(">");
else
O << formatImm(Op.getImm());
O << markup("<imm:") << formatImm(Op.getImm()) << markup(">");
}
void MipsInstPrinter::printBranchOperand(const MCInst *MI, uint64_t Address,
@ -167,9 +168,9 @@ void MipsInstPrinter::printBranchOperand(const MCInst *MI, uint64_t Address,
Target &= 0xffffffff;
else if (STI.hasFeature(Mips::FeatureMips16))
Target &= 0xffff;
O << formatHex(Target);
O << markup("<imm:") << formatHex(Target) << markup(">");
} else {
O << formatImm(Op.getImm());
O << markup("<imm:") << formatImm(Op.getImm()) << markup(">");
}
}
@ -182,7 +183,7 @@ void MipsInstPrinter::printUImm(const MCInst *MI, int opNum,
Imm -= Offset;
Imm &= (1 << Bits) - 1;
Imm += Offset;
O << formatImm(Imm);
O << markup("<imm:") << formatImm(Imm) << markup(">");
return;
}
@ -211,10 +212,12 @@ void MipsInstPrinter::printMemOperand(const MCInst *MI, int opNum,
break;
}
O << markup("<mem:");
printOperand(MI, opNum + 1, STI, O);
O << "(";
printOperand(MI, opNum, STI, O);
O << ")";
O << markup(">");
}
void MipsInstPrinter::printMemOperandEA(const MCInst *MI, int opNum,

View File

@ -0,0 +1,10 @@
# RUN: llvm-mc --mdis %s -triple=mips-unknown-linux 2>&1 | FileCheck %s
# CHECK: j <imm:80478376>
0x09 0x33 0x00 0x2a
# CHECK: addi <reg:$13>, <reg:$9>, <imm:26322>
0x21 0x2d 0x66 0xd2
# CHECK: xor <reg:$18>, <reg:$4>, <reg:$fp>
0x00 0x9e 0x90 0x26
# CHECK: lwr <reg:$zero>, <mem:<imm:-19147>(<reg:$gp>)>
0x9b 0x80 0xb5 0x35