1 | //=- SystemZHLASMInstPrinter.cpp - Convert SystemZ MCInst to HLASM assembly -=// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "SystemZHLASMInstPrinter.h" |
10 | #include "llvm/MC/MCInst.h" |
11 | #include "llvm/MC/MCRegister.h" |
12 | #include "llvm/Support/raw_ostream.h" |
13 | |
14 | using namespace llvm; |
15 | |
16 | #define DEBUG_TYPE "asm-printer" |
17 | |
18 | #include "SystemZGenHLASMAsmWriter.inc" |
19 | |
20 | void SystemZHLASMInstPrinter::printFormattedRegName(const MCAsmInfo *MAI, |
21 | MCRegister Reg, |
22 | raw_ostream &O) { |
23 | const char *RegName = getRegisterName(Reg); |
24 | // Skip register prefix so that only register number is left |
25 | assert(isalpha(RegName[0]) && isdigit(RegName[1])); |
26 | markup(OS&: O, M: Markup::Register) << (RegName + 1); |
27 | } |
28 | |
29 | void SystemZHLASMInstPrinter::printInst(const MCInst *MI, uint64_t Address, |
30 | StringRef Annot, |
31 | const MCSubtargetInfo &STI, |
32 | raw_ostream &O) { |
33 | std::string Str; |
34 | raw_string_ostream RSO(Str); |
35 | printInstruction(MI, Address, O&: RSO); |
36 | // Eat the first tab character and replace it with a space since it is |
37 | // hardcoded in AsmWriterEmitter::EmitPrintInstruction |
38 | // TODO: introduce a line prefix member to AsmWriter to avoid this problem |
39 | if (!Str.empty() && Str.front() == '\t') |
40 | O << " " << Str.substr(pos: 1, n: Str.length()); |
41 | else |
42 | O << Str; |
43 | |
44 | printAnnotation(OS&: O, Annot); |
45 | } |
46 | |