Skip to content

Commit 96482ee

Browse files
committed
[SystemZInstPrinter] Introduce markup tags emission
SystemZ assembly syntax emission now leverages markup tags, if enabled. Author: Antonio Frighetto Differential Revision: https://reviews.llvm.org/D129868
1 parent b179351 commit 96482ee

File tree

4 files changed

+80
-21
lines changed

4 files changed

+80
-21
lines changed

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
4949
printFormattedRegName(MAI, MO.getReg(), O);
5050
}
5151
else if (MO.isImm())
52-
O << MO.getImm();
52+
O << markup("<imm:") << MO.getImm() << markup(">");
5353
else if (MO.isExpr())
5454
MO.getExpr()->print(O, MAI);
5555
else
5656
llvm_unreachable("Invalid operand");
5757
}
5858

5959
void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
60-
unsigned RegNo, raw_ostream &O) {
60+
unsigned RegNo,
61+
raw_ostream &O) const {
6162
const char *RegName = getRegisterName(RegNo);
6263
if (MAI->getAssemblerDialect() == AD_HLASM) {
6364
// Skip register prefix so that only register number is left
6465
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
65-
O << (RegName + 1);
66+
O << markup("<reg:") << (RegName + 1) << markup(">");
6667
} else
67-
O << '%' << RegName;
68+
O << markup("<reg:") << '%' << RegName << markup(">");
6869
}
6970

7071
void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
@@ -75,17 +76,19 @@ void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
7576
}
7677

7778
template <unsigned N>
78-
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
79+
void SystemZInstPrinter::printUImmOperand(const MCInst *MI, int OpNum,
80+
raw_ostream &O) {
7981
int64_t Value = MI->getOperand(OpNum).getImm();
8082
assert(isUInt<N>(Value) && "Invalid uimm argument");
81-
O << Value;
83+
O << markup("<imm:") << Value << markup(">");
8284
}
8385

8486
template <unsigned N>
85-
static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
87+
void SystemZInstPrinter::printSImmOperand(const MCInst *MI, int OpNum,
88+
raw_ostream &O) {
8689
int64_t Value = MI->getOperand(OpNum).getImm();
8790
assert(isInt<N>(Value) && "Invalid simm argument");
88-
O << Value;
91+
O << markup("<imm:") << Value << markup(">");
8992
}
9093

9194
void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum,
@@ -157,8 +160,9 @@ void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
157160
raw_ostream &O) {
158161
const MCOperand &MO = MI->getOperand(OpNum);
159162
if (MO.isImm()) {
160-
O << "0x";
163+
O << markup("<imm:") << "0x";
161164
O.write_hex(MO.getImm());
165+
O << markup(">");
162166
} else
163167
MO.getExpr()->print(O, &MAI);
164168
}

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ class SystemZInstPrinter : public MCInstPrinter {
3333
static const char *getRegisterName(unsigned RegNo);
3434

3535
// Print an address with the given base, displacement and index.
36-
static void printAddress(const MCAsmInfo *MAI, unsigned Base,
37-
const MCOperand &DispMO, unsigned Index,
38-
raw_ostream &O);
36+
void printAddress(const MCAsmInfo *MAI, unsigned Base,
37+
const MCOperand &DispMO, unsigned Index, raw_ostream &O);
3938

4039
// Print the given operand.
41-
static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
42-
raw_ostream &O);
40+
void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O);
4341

44-
static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
45-
raw_ostream &O);
42+
void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
43+
raw_ostream &O) const;
4644

4745
// Override MCInstPrinter.
4846
inline void printRegName(raw_ostream &O, unsigned RegNo) const override {
@@ -53,6 +51,11 @@ class SystemZInstPrinter : public MCInstPrinter {
5351
const MCSubtargetInfo &STI, raw_ostream &O) override;
5452

5553
private:
54+
template <unsigned N>
55+
void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
56+
template <unsigned N>
57+
void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
58+
5659
// Print various types of operand.
5760
void printOperand(const MCInst *MI, int OpNum, raw_ostream &O);
5861
void printOperand(const MCInst *MI, uint64_t /*Address*/, unsigned OpNum,

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,49 @@ void SystemZAsmPrinter::emitMachineConstantPoolValue(
785785
OutStreamer->emitValue(Expr, Size);
786786
}
787787

788+
static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
789+
raw_ostream &OS) {
790+
const char *RegName = SystemZInstPrinter::getRegisterName(RegNo);
791+
if (MAI->getAssemblerDialect() == AD_HLASM) {
792+
// Skip register prefix so that only register number is left
793+
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
794+
OS << (RegName + 1);
795+
} else
796+
OS << '%' << RegName;
797+
}
798+
799+
static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
800+
raw_ostream &OS) {
801+
if (MCOp.isReg()) {
802+
if (!MCOp.getReg())
803+
OS << '0';
804+
else
805+
printFormattedRegName(MAI, MCOp.getReg(), OS);
806+
} else if (MCOp.isImm())
807+
OS << MCOp.getImm();
808+
else if (MCOp.isExpr())
809+
MCOp.getExpr()->print(OS, MAI);
810+
else
811+
llvm_unreachable("Invalid operand");
812+
}
813+
814+
static void printAddress(const MCAsmInfo *MAI, unsigned Base,
815+
const MCOperand &DispMO, unsigned Index,
816+
raw_ostream &OS) {
817+
printOperand(DispMO, MAI, OS);
818+
if (Base || Index) {
819+
OS << '(';
820+
if (Index) {
821+
printFormattedRegName(MAI, Index, OS);
822+
if (Base)
823+
OS << ',';
824+
}
825+
if (Base)
826+
printFormattedRegName(MAI, Base, OS);
827+
OS << ')';
828+
}
829+
}
830+
788831
bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
789832
const char *ExtraCode,
790833
raw_ostream &OS) {
@@ -802,18 +845,17 @@ bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
802845
SystemZMCInstLower Lower(MF->getContext(), *this);
803846
MCOp = Lower.lowerOperand(MO);
804847
}
805-
SystemZInstPrinter::printOperand(MCOp, MAI, OS);
848+
printOperand(MCOp, MAI, OS);
806849
return false;
807850
}
808851

809852
bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
810853
unsigned OpNo,
811854
const char *ExtraCode,
812855
raw_ostream &OS) {
813-
SystemZInstPrinter::
814-
printAddress(MAI, MI->getOperand(OpNo).getReg(),
815-
MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
816-
MI->getOperand(OpNo + 2).getReg(), OS);
856+
printAddress(MAI, MI->getOperand(OpNo).getReg(),
857+
MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
858+
MI->getOperand(OpNo + 2).getReg(), OS);
817859
return false;
818860
}
819861

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: llvm-mc --mdis %s -triple=s390x-linux-gnu -mcpu=zEC12 2>&1 | FileCheck %s
2+
3+
# CHECK: blr <reg:%r10>
4+
0x07 0x4a
5+
# CHECK: lrl <reg:%r15>, <imm:0x90>
6+
0xc4 0xfd 0x00 0x00 0x00 0x47
7+
# CHECK: stc <reg:%r0>, <imm:4095>
8+
0x42 0x00 0x0f 0xff
9+
# CHECK: trace <reg:%r0>, <reg:%r0>, <imm:0>(<reg:%r1>)
10+
0x99 0x00 0x10 0x00

0 commit comments

Comments
 (0)