Skip to content

Commit

Permalink
[MipsInstPrinter] Introduce markup tags emission
Browse files Browse the repository at this point in the history
MIPS assembly syntax emission now leverages markup tags, if enabled.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129867
  • Loading branch information
antoniofrighetto authored and MaskRay committed Sep 2, 2022
1 parent bb0e6b7 commit cbb2141
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand All @@ -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(">");
}
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/MC/Disassembler/Mips/marked-up.txt
@@ -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

0 comments on commit cbb2141

Please sign in to comment.