[InstCombine] Signed saturation patterns
[llvm-core.git] / lib / Target / XCore / MCTargetDesc / XCoreInstPrinter.cpp
blobd231e0981324a6343c581b13489b78dac36e2018
1 //===-- XCoreInstPrinter.cpp - Convert XCore MCInst to assembly syntax ----===//
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 // 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/MCSymbol.h"
18 #include "llvm/Support/Casting.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include <cassert>
23 using namespace llvm;
25 #define DEBUG_TYPE "asm-printer"
27 #include "XCoreGenAsmWriter.inc"
29 void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
30 OS << StringRef(getRegisterName(RegNo)).lower();
33 void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
34 StringRef Annot, const MCSubtargetInfo &STI) {
35 printInstruction(MI, O);
36 printAnnotation(O, Annot);
39 void XCoreInstPrinter::
40 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
41 report_fatal_error("can't handle InlineJT");
44 void XCoreInstPrinter::
45 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
46 report_fatal_error("can't handle InlineJT32");
49 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
50 raw_ostream &OS) {
51 int Offset = 0;
52 const MCSymbolRefExpr *SRE;
54 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
55 SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
56 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
57 assert(SRE && CE && "Binary expression must be sym+const.");
58 Offset = CE->getValue();
59 } else {
60 SRE = dyn_cast<MCSymbolRefExpr>(Expr);
61 assert(SRE && "Unexpected MCExpr type.");
63 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
65 SRE->getSymbol().print(OS, MAI);
67 if (Offset) {
68 if (Offset > 0)
69 OS << '+';
70 OS << Offset;
74 void XCoreInstPrinter::
75 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
76 const MCOperand &Op = MI->getOperand(OpNo);
77 if (Op.isReg()) {
78 printRegName(O, Op.getReg());
79 return;
82 if (Op.isImm()) {
83 O << Op.getImm();
84 return;
87 assert(Op.isExpr() && "unknown operand kind in printOperand");
88 printExpr(Op.getExpr(), &MAI, O);