Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/MSP430/MCTargetDesc/MSP430InstPrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MSP430InstPrinter.cpp - Convert MSP430 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 MSP430 MCInst to a .s file.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "MSP430InstPrinter.h"
14
#include "MSP430.h"
15
#include "llvm/MC/MCAsmInfo.h"
16
#include "llvm/MC/MCExpr.h"
17
#include "llvm/MC/MCInst.h"
18
#include "llvm/MC/MCInstrInfo.h"
19
#include "llvm/Support/ErrorHandling.h"
20
#include "llvm/Support/FormattedStream.h"
21
using namespace llvm;
22
23
#define DEBUG_TYPE "asm-printer"
24
25
// Include the auto-generated portion of the assembly writer.
26
#define PRINT_ALIAS_INSTR
27
#include "MSP430GenAsmWriter.inc"
28
29
void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
30
3.03k
                                  StringRef Annot, const MCSubtargetInfo &STI) {
31
3.03k
  if (!printAliasInstr(MI, O))
32
2.84k
    printInstruction(MI, O);
33
3.03k
  printAnnotation(O, Annot);
34
3.03k
}
35
36
void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
37
93
                                             raw_ostream &O) {
38
93
  const MCOperand &Op = MI->getOperand(OpNo);
39
93
  if (Op.isImm()) {
40
27
    int64_t Imm = Op.getImm() * 2 + 2;
41
27
    O << "$";
42
27
    if (Imm >= 0)
43
0
      O << '+';
44
27
    O << Imm;
45
66
  } else {
46
66
    assert(Op.isExpr() && "unknown pcrel immediate operand");
47
66
    Op.getExpr()->print(O, &MAI);
48
66
  }
49
93
}
50
51
void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
52
3.08k
                                     raw_ostream &O, const char *Modifier) {
53
3.08k
  assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported");
54
3.08k
  const MCOperand &Op = MI->getOperand(OpNo);
55
3.08k
  if (Op.isReg()) {
56
1.99k
    O << getRegisterName(Op.getReg());
57
1.99k
  } else 
if (1.08k
Op.isImm()1.08k
) {
58
974
    O << '#' << Op.getImm();
59
974
  } else {
60
115
    assert(Op.isExpr() && "unknown operand kind in printOperand");
61
115
    O << '#';
62
115
    Op.getExpr()->print(O, &MAI);
63
115
  }
64
3.08k
}
65
66
void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
67
                                           raw_ostream &O,
68
1.48k
                                           const char *Modifier) {
69
1.48k
  const MCOperand &Base = MI->getOperand(OpNo);
70
1.48k
  const MCOperand &Disp = MI->getOperand(OpNo+1);
71
1.48k
72
1.48k
  // Print displacement first
73
1.48k
74
1.48k
  // If the global address expression is a part of displacement field with a
75
1.48k
  // register base, we should not emit any prefix symbol here, e.g.
76
1.48k
  //   mov.w &foo, r1
77
1.48k
  // vs
78
1.48k
  //   mov.w glb(r1), r2
79
1.48k
  // Otherwise (!) msp430-as will silently miscompile the output :(
80
1.48k
  if (Base.getReg() == MSP430::SR)
81
979
    O << '&';
82
1.48k
83
1.48k
  if (Disp.isExpr())
84
1.00k
    Disp.getExpr()->print(O, &MAI);
85
481
  else {
86
481
    assert(Disp.isImm() && "Expected immediate in displacement field");
87
481
    O << Disp.getImm();
88
481
  }
89
1.48k
90
1.48k
  // Print register base field
91
1.48k
  if ((Base.getReg() != MSP430::SR) &&
92
1.48k
      
(Base.getReg() != MSP430::PC)508
)
93
488
    O << '(' << getRegisterName(Base.getReg()) << ')';
94
1.48k
}
95
96
void MSP430InstPrinter::printIndRegOperand(const MCInst *MI, unsigned OpNo,
97
17
                                           raw_ostream &O) {
98
17
  const MCOperand &Base = MI->getOperand(OpNo);
99
17
  O << "@" << getRegisterName(Base.getReg());
100
17
}
101
102
void MSP430InstPrinter::printPostIndRegOperand(const MCInst *MI, unsigned OpNo,
103
22
                                               raw_ostream &O) {
104
22
  const MCOperand &Base = MI->getOperand(OpNo);
105
22
  O << "@" << getRegisterName(Base.getReg()) << "+";
106
22
}
107
108
void MSP430InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo,
109
78
                                       raw_ostream &O) {
110
78
  unsigned CC = MI->getOperand(OpNo).getImm();
111
78
112
78
  switch (CC) {
113
78
  default:
114
0
   llvm_unreachable("Unsupported CC code");
115
78
  case MSP430CC::COND_E:
116
26
   O << "eq";
117
26
   break;
118
78
  case MSP430CC::COND_NE:
119
21
   O << "ne";
120
21
   break;
121
78
  case MSP430CC::COND_HS:
122
7
   O << "hs";
123
7
   break;
124
78
  case MSP430CC::COND_LO:
125
4
   O << "lo";
126
4
   break;
127
78
  case MSP430CC::COND_GE:
128
10
   O << "ge";
129
10
   break;
130
78
  case MSP430CC::COND_L:
131
8
   O << 'l';
132
8
   break;
133
78
  case MSP430CC::COND_N:
134
2
   O << 'n';
135
2
   break;
136
78
  }
137
78
}