1 //===-- XCoreInstPrinter.cpp - Convert XCore MCInst to assembly syntax ----===//
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
7 //===----------------------------------------------------------------------===//
9 // This class prints an XCore MCInst to a .s file.
11 //===----------------------------------------------------------------------===//
13 #include "XCoreInstPrinter.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCRegister.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/Casting.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/raw_ostream.h"
26 #define DEBUG_TYPE "asm-printer"
28 #include "XCoreGenAsmWriter.inc"
30 void XCoreInstPrinter::printRegName(raw_ostream
&OS
, MCRegister Reg
) {
31 OS
<< StringRef(getRegisterName(Reg
)).lower();
34 void XCoreInstPrinter::printInst(const MCInst
*MI
, uint64_t Address
,
35 StringRef Annot
, const MCSubtargetInfo
&STI
,
37 printInstruction(MI
, Address
, O
);
38 printAnnotation(O
, Annot
);
41 void XCoreInstPrinter::
42 printInlineJT(const MCInst
*MI
, int opNum
, raw_ostream
&O
) {
43 report_fatal_error("can't handle InlineJT");
46 void XCoreInstPrinter::
47 printInlineJT32(const MCInst
*MI
, int opNum
, raw_ostream
&O
) {
48 report_fatal_error("can't handle InlineJT32");
51 static void printExpr(const MCExpr
*Expr
, const MCAsmInfo
*MAI
,
54 const MCSymbolRefExpr
*SRE
;
56 if (const MCBinaryExpr
*BE
= dyn_cast
<MCBinaryExpr
>(Expr
)) {
57 SRE
= dyn_cast
<MCSymbolRefExpr
>(BE
->getLHS());
58 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(BE
->getRHS());
59 assert(SRE
&& CE
&& "Binary expression must be sym+const.");
60 Offset
= CE
->getValue();
62 SRE
= dyn_cast
<MCSymbolRefExpr
>(Expr
);
63 assert(SRE
&& "Unexpected MCExpr type.");
65 assert(SRE
->getKind() == MCSymbolRefExpr::VK_None
);
67 SRE
->getSymbol().print(OS
, MAI
);
76 void XCoreInstPrinter::
77 printOperand(const MCInst
*MI
, unsigned OpNo
, raw_ostream
&O
) {
78 const MCOperand
&Op
= MI
->getOperand(OpNo
);
80 printRegName(O
, Op
.getReg());
89 assert(Op
.isExpr() && "unknown operand kind in printOperand");
90 printExpr(Op
.getExpr(), &MAI
, O
);