Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp =================================================================== --- llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp +++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp @@ -150,7 +150,8 @@ } if (AsmMnemonic) { O << '\t' << AsmMnemonic << '\t' << getRegisterName(Op0.getReg()) - << ", " << getRegisterName(Op1.getReg()) << ", #" << shift; + << ", " << getRegisterName(Op1.getReg()) << ", " << markup(""); printAnnotation(O, Annot); return; } @@ -159,8 +160,10 @@ // SBFIZ/UBFIZ aliases if (Op2.getImm() > Op3.getImm()) { O << '\t' << (IsSigned ? "sbfiz" : "ubfiz") << '\t' - << getRegisterName(Op0.getReg()) << ", " << getRegisterName(Op1.getReg()) - << ", #" << (Is64Bit ? 64 : 32) - Op2.getImm() << ", #" << Op3.getImm() + 1; + << getRegisterName(Op0.getReg()) << ", " + << getRegisterName(Op1.getReg()) << ", " << markup("") << ", " + << markup(""); printAnnotation(O, Annot); return; } @@ -168,7 +171,9 @@ // Otherwise SBFX/UBFX is the preferred form O << '\t' << (IsSigned ? "sbfx" : "ubfx") << '\t' << getRegisterName(Op0.getReg()) << ", " << getRegisterName(Op1.getReg()) - << ", #" << Op2.getImm() << ", #" << Op3.getImm() - Op2.getImm() + 1; + << ", " << markup("") << ", " + << markup(""); printAnnotation(O, Annot); return; } @@ -187,8 +192,9 @@ int LSB = (BitWidth - ImmR) % BitWidth; int Width = ImmS + 1; - O << "\tbfc\t" << getRegisterName(Op0.getReg()) - << ", #" << LSB << ", #" << Width; + O << "\tbfc\t" << getRegisterName(Op0.getReg()) << ", " << markup("") << ", " << markup(""); printAnnotation(O, Annot); return; } else if (ImmS < ImmR) { @@ -198,7 +204,9 @@ int Width = ImmS + 1; O << "\tbfi\t" << getRegisterName(Op0.getReg()) << ", " - << getRegisterName(Op2.getReg()) << ", #" << LSB << ", #" << Width; + << getRegisterName(Op2.getReg()) << ", " << markup("") << ", " << markup(""); printAnnotation(O, Annot); return; } @@ -206,9 +214,9 @@ int LSB = ImmR; int Width = ImmS - ImmR + 1; // Otherwise BFXIL the preferred form - O << "\tbfxil\t" - << getRegisterName(Op0.getReg()) << ", " << getRegisterName(Op2.getReg()) - << ", #" << LSB << ", #" << Width; + O << "\tbfxil\t" << getRegisterName(Op0.getReg()) << ", " + << getRegisterName(Op2.getReg()) << ", " << markup("") << ", " << markup(""); printAnnotation(O, Annot); return; } @@ -224,15 +232,19 @@ else O << "\tmovn\t"; - O << getRegisterName(MI->getOperand(0).getReg()) << ", #"; + O << getRegisterName(MI->getOperand(0).getReg()) << ", " << markup("getOperand(1).getExpr()->print(O, &MAI); + O << markup(">"); return; } if ((Opcode == AArch64::MOVKXi || Opcode == AArch64::MOVKWi) && MI->getOperand(2).isExpr()) { - O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #"; + O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", " + << markup("getOperand(2).getExpr()->print(O, &MAI); + O << markup(">"); return; } @@ -249,8 +261,9 @@ if (AArch64_AM::isMOVZMovAlias(Value, Shift, Opcode == AArch64::MOVZXi ? 64 : 32)) { - O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #" - << formatImm(SignExtend64(Value, RegWidth)); + O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", " + << markup(""); return; } } @@ -264,8 +277,9 @@ Value = Value & 0xffffffff; if (AArch64_AM::isMOVNMovAlias(Value, Shift, RegWidth)) { - O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #" - << formatImm(SignExtend64(Value, RegWidth)); + O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", " + << markup(""); return; } } @@ -278,8 +292,9 @@ uint64_t Value = AArch64_AM::decodeLogicalImmediate( MI->getOperand(2).getImm(), RegWidth); if (!AArch64_AM::isAnyMOVWMovAlias(Value, RegWidth)) { - O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #" - << formatImm(SignExtend64(Value, RegWidth)); + O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg()) << ", " + << markup(""); return; } } @@ -756,7 +771,8 @@ O << ", " << getRegisterName(Reg); else { assert(LdStDesc->NaturalOffset && "no offset on post-inc instruction?"); - O << ", #" << LdStDesc->NaturalOffset; + O << ", " << markup("NaturalOffset + << markup(">"); } } @@ -963,14 +979,14 @@ const MCSubtargetInfo &STI, raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); - O << "#" << formatImm(Op.getImm()); + O << markup(""); } void AArch64InstPrinter::printImmHex(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); - O << format("#%#llx", Op.getImm()); + O << markup(""); } template @@ -979,11 +995,13 @@ raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); if (Size == 8) - O << "#" << formatImm((signed char)Op.getImm()); + O << markup(""); else if (Size == 16) - O << "#" << formatImm((signed short)Op.getImm()); + O << markup(""); else - O << "#" << formatImm(Op.getImm()); + O << markup(""); } void AArch64InstPrinter::printPostIncOperand(const MCInst *MI, unsigned OpNo, @@ -992,7 +1010,7 @@ if (Op.isReg()) { unsigned Reg = Op.getReg(); if (Reg == AArch64::XZR) - O << "#" << Imm; + O << markup(""); else O << getRegisterName(Reg); } else @@ -1025,7 +1043,7 @@ assert(Val == MO.getImm() && "Add/sub immediate out of range!"); unsigned Shift = AArch64_AM::getShiftValue(MI->getOperand(OpNum + 1).getImm()); - O << '#' << formatImm(Val); + O << markup(""); if (Shift != 0) { printShifter(MI, OpNum + 1, STI, O); if (CommentStream) @@ -1043,8 +1061,9 @@ const MCSubtargetInfo &STI, raw_ostream &O) { uint64_t Val = MI->getOperand(OpNum).getImm(); - O << "#0x"; + O << markup(""); } void AArch64InstPrinter::printShifter(const MCInst *MI, unsigned OpNum, @@ -1056,7 +1075,8 @@ AArch64_AM::getShiftValue(Val) == 0) return; O << ", " << AArch64_AM::getShiftExtendName(AArch64_AM::getShiftType(Val)) - << " #" << AArch64_AM::getShiftValue(Val); + << " " << markup(""); } void AArch64InstPrinter::printShiftedRegister(const MCInst *MI, unsigned OpNum, @@ -1091,18 +1111,18 @@ ((Dest == AArch64::WSP || Src1 == AArch64::WSP) && ExtType == AArch64_AM::UXTW) ) { if (ShiftVal != 0) - O << ", lsl #" << ShiftVal; + O << ", lsl " << markup(""); return; } } O << ", " << AArch64_AM::getShiftExtendName(ExtType); if (ShiftVal != 0) - O << " #" << ShiftVal; + O << " " << markup(""); } -static void printMemExtendImpl(bool SignExtend, bool DoShift, - unsigned Width, char SrcRegKind, - raw_ostream &O) { +static void printMemExtendImpl(bool SignExtend, bool DoShift, unsigned Width, + char SrcRegKind, raw_ostream &O, + bool UseMarkup) { // sxtw, sxtx, uxtw or lsl (== uxtx) bool IsLSL = !SignExtend && SrcRegKind == 'x'; if (IsLSL) @@ -1110,8 +1130,14 @@ else O << (SignExtend ? 's' : 'u') << "xt" << SrcRegKind; - if (DoShift || IsLSL) + if (DoShift || IsLSL) { + O << " "; + if (UseMarkup) + O << ""; + } } void AArch64InstPrinter::printMemExtend(const MCInst *MI, unsigned OpNum, @@ -1119,7 +1145,7 @@ unsigned Width) { bool SignExtend = MI->getOperand(OpNum).getImm(); bool DoShift = MI->getOperand(OpNum + 1).getImm(); - printMemExtendImpl(SignExtend, DoShift, Width, SrcRegKind, O); + printMemExtendImpl(SignExtend, DoShift, Width, SrcRegKind, O, UseMarkup); } template @@ -1136,7 +1162,7 @@ bool DoShift = ExtWidth != 8; if (SignExtend || DoShift || SrcRegKind == 'w') { O << ", "; - printMemExtendImpl(SignExtend, DoShift, ExtWidth, SrcRegKind, O); + printMemExtendImpl(SignExtend, DoShift, ExtWidth, SrcRegKind, O, UseMarkup); } } @@ -1164,14 +1190,16 @@ void AArch64InstPrinter::printImmScale(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI, raw_ostream &O) { - O << '#' << formatImm(Scale * MI->getOperand(OpNum).getImm()); + O << markup("getOperand(OpNum).getImm()) << markup(">"); } void AArch64InstPrinter::printUImm12Offset(const MCInst *MI, unsigned OpNum, unsigned Scale, raw_ostream &O) { const MCOperand MO = MI->getOperand(OpNum); if (MO.isImm()) { - O << "#" << formatImm(MO.getImm() * Scale); + O << markup(""); } else { assert(MO.isExpr() && "Unexpected operand type!"); MO.getExpr()->print(O, &MAI); @@ -1183,7 +1211,8 @@ const MCOperand MO1 = MI->getOperand(OpNum + 1); O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()); if (MO1.isImm()) { - O << ", #" << formatImm(MO1.getImm() * Scale); + O << ", " << markup(""); } else { assert(MO1.isExpr() && "Unexpected operand type!"); O << ", "; @@ -1207,7 +1236,7 @@ return; } - O << '#' << formatImm(prfop); + O << markup(""); } void AArch64InstPrinter::printPSBHintOp(const MCInst *MI, unsigned OpNum, @@ -1218,7 +1247,7 @@ if (PSB) O << PSB->Name; else - O << '#' << formatImm(psbhintop); + O << markup(""); } void AArch64InstPrinter::printBTIHintOp(const MCInst *MI, unsigned OpNum, @@ -1229,7 +1258,7 @@ if (BTI) O << BTI->Name; else - O << '#' << formatImm(btihintop); + O << markup(""); } void AArch64InstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum, @@ -1240,7 +1269,7 @@ : AArch64_AM::getFPImmFloat(MO.getImm()); // 8 decimal places are enough to perfectly represent permitted floats. - O << format("#%.8f", FPImm); + O << markup(""); } static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride = 1) { @@ -1460,11 +1489,13 @@ // If the label has already been resolved to an immediate offset (say, when // we're running the disassembler), just print the immediate. if (Op.isImm()) { + O << markup(""); return; } @@ -1490,10 +1521,12 @@ // we're running the disassembler), just print the immediate. if (Op.isImm()) { const int64_t Offset = Op.getImm() * 4096; + O << markup(""); return; } @@ -1521,7 +1554,7 @@ if (!Name.empty()) O << Name; else - O << "#" << Val; + O << markup(""); } void AArch64InstPrinter::printBarriernXSOption(const MCInst *MI, unsigned OpNo, @@ -1537,7 +1570,7 @@ if (!Name.empty()) O << Name; else - O << "#" << Val; + O << markup(""); } static bool isValidSysReg(const AArch64SysReg::SysReg *Reg, bool Read, @@ -1633,7 +1666,7 @@ raw_ostream &O) { unsigned RawVal = MI->getOperand(OpNo).getImm(); uint64_t Val = AArch64_AM::decodeAdvSIMDModImmType10(RawVal); - O << format("#%#016llx", Val); + O << markup(""); } template @@ -1641,7 +1674,7 @@ const MCSubtargetInfo &STI, raw_ostream &O) { unsigned Val = MI->getOperand(OpNo).getImm(); - O << "#" << (Val * Angle) + Remainder; + O << markup(""); } void AArch64InstPrinter::printSVEPattern(const MCInst *MI, unsigned OpNum, @@ -1651,7 +1684,7 @@ if (auto Pat = AArch64SVEPredPattern::lookupSVEPREDPATByEncoding(Val)) O << Pat->Name; else - O << '#' << formatImm(Val); + O << markup(""); } template @@ -1680,9 +1713,9 @@ std::make_unsigned_t HexValue = Value; if (getPrintImmHex()) - O << '#' << formatHex((uint64_t)HexValue); + O << markup(""); else - O << '#' << formatDec(Value); + O << markup(""); if (CommentStream) { // Do the opposite to that used for instruction operands. @@ -1704,7 +1737,7 @@ // #0 lsl #8 is never pretty printed if ((UnscaledVal == 0) && (AArch64_AM::getShiftValue(Shift) != 0)) { - O << '#' << formatImm(UnscaledVal); + O << markup(""); printShifter(MI, OpNum + 1, STI, O); return; } @@ -1734,7 +1767,7 @@ else if ((uint16_t)PrintVal == PrintVal) printImmSVE(PrintVal, O); else - O << '#' << formatHex((uint64_t)PrintVal); + O << markup(""); } template @@ -1762,7 +1795,8 @@ auto *Imm0Desc = AArch64ExactFPImm::lookupExactFPImmByEnum(ImmIs0); auto *Imm1Desc = AArch64ExactFPImm::lookupExactFPImmByEnum(ImmIs1); unsigned Val = MI->getOperand(OpNum).getImm(); - O << "#" << (Val ? Imm1Desc->Repr : Imm0Desc->Repr); + O << markup("Repr : Imm0Desc->Repr) + << markup(">"); } void AArch64InstPrinter::printGPR64as32(const MCInst *MI, unsigned OpNum, Index: llvm/test/MC/Disassembler/AArch64/arm64-marked-up.txt =================================================================== --- /dev/null +++ llvm/test/MC/Disassembler/AArch64/arm64-marked-up.txt @@ -0,0 +1,11 @@ +# RUN: llvm-mc --mdis %s -triple=arm64-apple-darwin 2>&1 | FileCheck %s --check-prefix=CHECK-APPLE + +# CHECK-APPLE: b.ne +0xa1 0x00 0x00 0x54 +# CHECK-APPLE: asr , , +0x00 0x7c 0x00 0x13 +# CHECK-APPLE: subs , , , asr +0xac 0x9d 0x8e 0xeb +# CHECK-APPLE: ldp , , [, ]! +0xe3 0x09 0xc2 0x29 +