[llvm] cbb2141 - [MipsInstPrinter] Introduce markup tags emission

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 20:52:19 PDT 2022


Author: Antonio Frighetto
Date: 2022-09-01T20:52:09-07:00
New Revision: cbb2141f7fd7405cc92c780377921a6733a0f3f2

URL: https://github.com/llvm/llvm-project/commit/cbb2141f7fd7405cc92c780377921a6733a0f3f2
DIFF: https://github.com/llvm/llvm-project/commit/cbb2141f7fd7405cc92c780377921a6733a0f3f2.diff

LOG: [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

Added: 
    llvm/test/MC/Disassembler/Mips/marked-up.txt

Modified: 
    llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp
index 632192103d38f..5917cd3f95a9d 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp
@@ -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,

diff  --git a/llvm/test/MC/Disassembler/Mips/marked-up.txt b/llvm/test/MC/Disassembler/Mips/marked-up.txt
new file mode 100644
index 0000000000000..ef805c0a1cde6
--- /dev/null
+++ b/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


        


More information about the llvm-commits mailing list