SystemZ assembly syntax emission now leverages markup tags, if enabled.
Author: Antonio Frighetto
Differential Revision: https://reviews.llvm.org/D129868
printFormattedRegName(MAI, MO.getReg(), O);
}
else if (MO.isImm())
- O << MO.getImm();
+ O << markup("<imm:") << MO.getImm() << markup(">");
else if (MO.isExpr())
MO.getExpr()->print(O, MAI);
else
}
void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
- unsigned RegNo, raw_ostream &O) {
+ unsigned RegNo,
+ raw_ostream &O) const {
const char *RegName = getRegisterName(RegNo);
if (MAI->getAssemblerDialect() == AD_HLASM) {
// Skip register prefix so that only register number is left
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
- O << (RegName + 1);
+ O << markup("<reg:") << (RegName + 1) << markup(">");
} else
- O << '%' << RegName;
+ O << markup("<reg:") << '%' << RegName << markup(">");
}
void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address,
}
template <unsigned N>
-static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
+void SystemZInstPrinter::printUImmOperand(const MCInst *MI, int OpNum,
+ raw_ostream &O) {
int64_t Value = MI->getOperand(OpNum).getImm();
assert(isUInt<N>(Value) && "Invalid uimm argument");
- O << Value;
+ O << markup("<imm:") << Value << markup(">");
}
template <unsigned N>
-static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
+void SystemZInstPrinter::printSImmOperand(const MCInst *MI, int OpNum,
+ raw_ostream &O) {
int64_t Value = MI->getOperand(OpNum).getImm();
assert(isInt<N>(Value) && "Invalid simm argument");
- O << Value;
+ O << markup("<imm:") << Value << markup(">");
}
void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum,
raw_ostream &O) {
const MCOperand &MO = MI->getOperand(OpNum);
if (MO.isImm()) {
- O << "0x";
+ O << markup("<imm:") << "0x";
O.write_hex(MO.getImm());
+ O << markup(">");
} else
MO.getExpr()->print(O, &MAI);
}
static const char *getRegisterName(unsigned RegNo);
// Print an address with the given base, displacement and index.
- static void printAddress(const MCAsmInfo *MAI, unsigned Base,
- const MCOperand &DispMO, unsigned Index,
- raw_ostream &O);
+ void printAddress(const MCAsmInfo *MAI, unsigned Base,
+ const MCOperand &DispMO, unsigned Index, raw_ostream &O);
// Print the given operand.
- static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
- raw_ostream &O);
+ void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O);
- static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
- raw_ostream &O);
+ void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
+ raw_ostream &O) const;
// Override MCInstPrinter.
inline void printRegName(raw_ostream &O, unsigned RegNo) const override {
const MCSubtargetInfo &STI, raw_ostream &O) override;
private:
+ template <unsigned N>
+ void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
+ template <unsigned N>
+ void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
+
// Print various types of operand.
void printOperand(const MCInst *MI, int OpNum, raw_ostream &O);
void printOperand(const MCInst *MI, uint64_t /*Address*/, unsigned OpNum,
OutStreamer->emitValue(Expr, Size);
}
+static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
+ raw_ostream &OS) {
+ const char *RegName = SystemZInstPrinter::getRegisterName(RegNo);
+ if (MAI->getAssemblerDialect() == AD_HLASM) {
+ // Skip register prefix so that only register number is left
+ assert(isalpha(RegName[0]) && isdigit(RegName[1]));
+ OS << (RegName + 1);
+ } else
+ OS << '%' << RegName;
+}
+
+static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
+ raw_ostream &OS) {
+ if (MCOp.isReg()) {
+ if (!MCOp.getReg())
+ OS << '0';
+ else
+ printFormattedRegName(MAI, MCOp.getReg(), OS);
+ } else if (MCOp.isImm())
+ OS << MCOp.getImm();
+ else if (MCOp.isExpr())
+ MCOp.getExpr()->print(OS, MAI);
+ else
+ llvm_unreachable("Invalid operand");
+}
+
+static void printAddress(const MCAsmInfo *MAI, unsigned Base,
+ const MCOperand &DispMO, unsigned Index,
+ raw_ostream &OS) {
+ printOperand(DispMO, MAI, OS);
+ if (Base || Index) {
+ OS << '(';
+ if (Index) {
+ printFormattedRegName(MAI, Index, OS);
+ if (Base)
+ OS << ',';
+ }
+ if (Base)
+ printFormattedRegName(MAI, Base, OS);
+ OS << ')';
+ }
+}
+
bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
const char *ExtraCode,
raw_ostream &OS) {
SystemZMCInstLower Lower(MF->getContext(), *this);
MCOp = Lower.lowerOperand(MO);
}
- SystemZInstPrinter::printOperand(MCOp, MAI, OS);
+ printOperand(MCOp, MAI, OS);
return false;
}
unsigned OpNo,
const char *ExtraCode,
raw_ostream &OS) {
- SystemZInstPrinter::
- printAddress(MAI, MI->getOperand(OpNo).getReg(),
- MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
- MI->getOperand(OpNo + 2).getReg(), OS);
+ printAddress(MAI, MI->getOperand(OpNo).getReg(),
+ MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
+ MI->getOperand(OpNo + 2).getReg(), OS);
return false;
}
--- /dev/null
+# RUN: llvm-mc --mdis %s -triple=s390x-linux-gnu -mcpu=zEC12 2>&1 | FileCheck %s
+
+# CHECK: blr <reg:%r10>
+0x07 0x4a
+# CHECK: lrl <reg:%r15>, <imm:0x90>
+0xc4 0xfd 0x00 0x00 0x00 0x47
+# CHECK: stc <reg:%r0>, <imm:4095>
+0x42 0x00 0x0f 0xff
+# CHECK: trace <reg:%r0>, <reg:%r0>, <imm:0>(<reg:%r1>)
+0x99 0x00 0x10 0x00