Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp
Line
Count
Source (jump to first uncovered line)
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.
10
//
11
//===----------------------------------------------------------------------===//
12
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>
22
23
using namespace llvm;
24
25
#define DEBUG_TYPE "asm-printer"
26
27
#include "XCoreGenAsmWriter.inc"
28
29
1.80k
void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
30
1.80k
  OS << StringRef(getRegisterName(RegNo)).lower();
31
1.80k
}
32
33
void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
34
1.70k
                                 StringRef Annot, const MCSubtargetInfo &STI) {
35
1.70k
  printInstruction(MI, O);
36
1.70k
  printAnnotation(O, Annot);
37
1.70k
}
38
39
void XCoreInstPrinter::
40
0
printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
41
0
  report_fatal_error("can't handle InlineJT");
42
0
}
43
44
void XCoreInstPrinter::
45
0
printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
46
0
  report_fatal_error("can't handle InlineJT32");
47
0
}
48
49
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
50
238
                      raw_ostream &OS) {
51
238
  int Offset = 0;
52
238
  const MCSymbolRefExpr *SRE;
53
238
54
238
  if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
55
16
    SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
56
16
    const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
57
16
    assert(SRE && CE && "Binary expression must be sym+const.");
58
16
    Offset = CE->getValue();
59
222
  } else {
60
222
    SRE = dyn_cast<MCSymbolRefExpr>(Expr);
61
222
    assert(SRE && "Unexpected MCExpr type.");
62
222
  }
63
238
  assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
64
238
65
238
  SRE->getSymbol().print(OS, MAI);
66
238
67
238
  if (Offset) {
68
16
    if (Offset > 0)
69
16
      OS << '+';
70
16
    OS << Offset;
71
16
  }
72
238
}
73
74
void XCoreInstPrinter::
75
3.08k
printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
76
3.08k
  const MCOperand &Op = MI->getOperand(OpNo);
77
3.08k
  if (Op.isReg()) {
78
1.80k
    printRegName(O, Op.getReg());
79
1.80k
    return;
80
1.80k
  }
81
1.27k
82
1.27k
  if (Op.isImm()) {
83
1.03k
    O << Op.getImm();
84
1.03k
    return;
85
1.03k
  }
86
238
87
238
  assert(Op.isExpr() && "unknown operand kind in printOperand");
88
238
  printExpr(Op.getExpr(), &MAI, O);
89
238
}