Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCInstPrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MCInstPrinter.cpp - Convert an MCInst to target 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
#include "llvm/MC/MCInstPrinter.h"
10
#include "llvm/ADT/ArrayRef.h"
11
#include "llvm/ADT/StringRef.h"
12
#include "llvm/MC/MCAsmInfo.h"
13
#include "llvm/MC/MCInstrInfo.h"
14
#include "llvm/Support/ErrorHandling.h"
15
#include "llvm/Support/Format.h"
16
#include "llvm/Support/raw_ostream.h"
17
#include <cinttypes>
18
#include <cstdint>
19
20
using namespace llvm;
21
22
261k
void llvm::dumpBytes(ArrayRef<uint8_t> bytes, raw_ostream &OS) {
23
261k
  static const char hex_rep[] = "0123456789abcdef";
24
261k
  bool First = true;
25
956k
  for (char i: bytes) {
26
956k
    if (First)
27
261k
      First = false;
28
694k
    else
29
694k
      OS << ' ';
30
956k
    OS << hex_rep[(i & 0xF0) >> 4];
31
956k
    OS << hex_rep[i & 0xF];
32
956k
  }
33
261k
}
34
35
29.9k
MCInstPrinter::~MCInstPrinter() = default;
36
37
/// getOpcodeName - Return the name of the specified opcode enum (e.g.
38
/// "MOV32ri") or empty if we can't resolve it.
39
8.73k
StringRef MCInstPrinter::getOpcodeName(unsigned Opcode) const {
40
8.73k
  return MII.getName(Opcode);
41
8.73k
}
42
43
0
void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
44
0
  llvm_unreachable("Target should implement this");
45
0
}
46
47
2.93M
void MCInstPrinter::printAnnotation(raw_ostream &OS, StringRef Annot) {
48
2.93M
  if (!Annot.empty()) {
49
665
    if (CommentStream) {
50
583
      (*CommentStream) << Annot;
51
583
      // By definition (see MCInstPrinter.h), CommentStream must end with
52
583
      // a newline after each comment.
53
583
      if (Annot.back() != '\n')
54
583
        (*CommentStream) << '\n';
55
583
    } else
56
82
      OS << " " << MAI.getCommentString() << " " << Annot;
57
665
  }
58
2.93M
}
59
60
/// Utility functions to make adding mark ups simpler.
61
5.88M
StringRef MCInstPrinter::markup(StringRef s) const {
62
5.88M
  if (getUseMarkup())
63
26
    return s;
64
5.88M
  else
65
5.88M
    return "";
66
5.88M
}
67
0
StringRef MCInstPrinter::markup(StringRef a, StringRef b) const {
68
0
  if (getUseMarkup())
69
0
    return a;
70
0
  else
71
0
    return b;
72
0
}
73
74
// For asm-style hex (e.g. 0ffh) the first digit always has to be a number.
75
static bool needsLeadingZero(uint64_t Value)
76
0
{
77
0
  while (Value)
78
0
  {
79
0
    uint64_t digit = (Value >> 60) & 0xf;
80
0
    if (digit != 0)
81
0
      return (digit >= 0xa);
82
0
    Value <<= 4;
83
0
  }
84
0
  return false;
85
0
}
86
87
739k
format_object<int64_t> MCInstPrinter::formatDec(int64_t Value) const {
88
739k
  return format("%" PRId64, Value);
89
739k
}
90
91
95.8k
format_object<int64_t> MCInstPrinter::formatHex(int64_t Value) const {
92
95.8k
  switch(PrintHexStyle) {
93
95.8k
  case HexStyle::C:
94
95.8k
    if (Value < 0)
95
643
      return format("-0x%" PRIx64, -Value);
96
95.1k
    else
97
95.1k
      return format("0x%" PRIx64, Value);
98
0
  case HexStyle::Asm:
99
0
    if (Value < 0) {
100
0
      if (needsLeadingZero((uint64_t)(-Value)))
101
0
        return format("-0%" PRIx64 "h", -Value);
102
0
      else
103
0
        return format("-%" PRIx64 "h", -Value);
104
0
    } else {
105
0
      if (needsLeadingZero((uint64_t)(Value)))
106
0
        return format("0%" PRIx64 "h", Value);
107
0
      else
108
0
        return format("%" PRIx64 "h", Value);
109
0
    }
110
0
  }
111
0
  llvm_unreachable("unsupported print style");
112
0
}
113
114
46.0k
format_object<uint64_t> MCInstPrinter::formatHex(uint64_t Value) const {
115
46.0k
  switch(PrintHexStyle) {
116
46.0k
  case HexStyle::C:
117
46.0k
     return format("0x%" PRIx64, Value);
118
46.0k
  case HexStyle::Asm:
119
0
    if (needsLeadingZero(Value))
120
0
      return format("0%" PRIx64 "h", Value);
121
0
    else
122
0
      return format("%" PRIx64 "h", Value);
123
0
  }
124
0
  llvm_unreachable("unsupported print style");
125
0
}