Coverage Report

Created: 2018-11-12 17:33

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCAsmMacro.h
Line
Count
Source (jump to first uncovered line)
1
//===- MCAsmMacro.h - Assembly Macros ---------------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_MC_MCASMMACRO_H
11
#define LLVM_MC_MCASMMACRO_H
12
13
#include "llvm/ADT/APInt.h"
14
#include "llvm/ADT/StringRef.h"
15
#include "llvm/Support/Debug.h"
16
#include "llvm/Support/SMLoc.h"
17
#include <vector>
18
19
namespace llvm {
20
21
/// Target independent representation for an assembler token.
22
0
class AsmToken {
Unexecuted instantiation: llvm::AsmToken::operator=(llvm::AsmToken const&)
Unexecuted instantiation: llvm::AsmToken::operator=(llvm::AsmToken&&)
23
public:
24
  enum TokenKind {
25
    // Markers
26
    Eof, Error,
27
28
    // String values.
29
    Identifier,
30
    String,
31
32
    // Integer values.
33
    Integer,
34
    BigNum, // larger than 64 bits
35
36
    // Real values.
37
    Real,
38
39
    // Comments
40
    Comment,
41
    HashDirective,
42
    // No-value.
43
    EndOfStatement,
44
    Colon,
45
    Space,
46
    Plus, Minus, Tilde,
47
    Slash,     // '/'
48
    BackSlash, // '\'
49
    LParen, RParen, LBrac, RBrac, LCurly, RCurly,
50
    Star, Dot, Comma, Dollar, Equal, EqualEqual,
51
52
    Pipe, PipePipe, Caret,
53
    Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, Hash,
54
    Less, LessEqual, LessLess, LessGreater,
55
    Greater, GreaterEqual, GreaterGreater, At,
56
57
    // MIPS unary expression operators such as %neg.
58
    PercentCall16, PercentCall_Hi, PercentCall_Lo, PercentDtprel_Hi,
59
    PercentDtprel_Lo, PercentGot, PercentGot_Disp, PercentGot_Hi, PercentGot_Lo,
60
    PercentGot_Ofst, PercentGot_Page, PercentGottprel, PercentGp_Rel, PercentHi,
61
    PercentHigher, PercentHighest, PercentLo, PercentNeg, PercentPcrel_Hi,
62
    PercentPcrel_Lo, PercentTlsgd, PercentTlsldm, PercentTprel_Hi,
63
    PercentTprel_Lo
64
  };
65
66
private:
67
  TokenKind Kind;
68
69
  /// A reference to the entire token contents; this is always a pointer into
70
  /// a memory buffer owned by the source manager.
71
  StringRef Str;
72
73
  APInt IntVal;
74
75
public:
76
767k
  AsmToken() = default;
77
  AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
78
656k
      : Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
79
  AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
80
9.31M
      : Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
81
82
19.4M
  TokenKind getKind() const { return Kind; }
83
64.9M
  bool is(TokenKind K) const { return Kind == K; }
84
10.8M
  bool isNot(TokenKind K) const { return Kind != K; }
85
86
  SMLoc getLoc() const;
87
  SMLoc getEndLoc() const;
88
  SMRange getLocRange() const;
89
90
  /// Get the contents of a string token (without quotes).
91
72.3k
  StringRef getStringContents() const {
92
72.3k
    assert(Kind == String && "This token isn't a string!");
93
72.3k
    return Str.slice(1, Str.size() - 1);
94
72.3k
  }
95
96
  /// Get the identifier string for the current token, which should be an
97
  /// identifier or a string. This gets the portion of the string which should
98
  /// be used as the identifier, e.g., it does not include the quotes on
99
  /// strings.
100
2.65M
  StringRef getIdentifier() const {
101
2.65M
    if (Kind == Identifier)
102
2.65M
      return getString();
103
413
    return getStringContents();
104
413
  }
105
106
  /// Get the string for the current token, this includes all characters (for
107
  /// example, the quotes on strings) in the token.
108
  ///
109
  /// The returned StringRef points into the source manager's memory buffer, and
110
  /// is safe to store across calls to Lex().
111
19.5M
  StringRef getString() const { return Str; }
112
113
  // FIXME: Don't compute this in advance, it makes every token larger, and is
114
  // also not generally what we want (it is nicer for recovery etc. to lex 123br
115
  // as a single token, then diagnose as an invalid number).
116
578k
  int64_t getIntVal() const {
117
578k
    assert(Kind == Integer && "This token isn't an integer!");
118
578k
    return IntVal.getZExtValue();
119
578k
  }
120
121
15
  APInt getAPIntVal() const {
122
15
    assert((Kind == Integer || Kind == BigNum) &&
123
15
           "This token isn't an integer!");
124
15
    return IntVal;
125
15
  }
126
127
  void dump(raw_ostream &OS) const;
128
0
  void dump() const { dump(dbgs()); }
129
};
130
131
struct MCAsmMacroParameter {
132
  StringRef Name;
133
  std::vector<AsmToken> Value;
134
  bool Required = false;
135
  bool Vararg = false;
136
137
211k
  MCAsmMacroParameter() = default;
138
139
0
  void dump() const { dump(dbgs()); }
140
  void dump(raw_ostream &OS) const;
141
};
142
143
typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
144
struct MCAsmMacro {
145
  StringRef Name;
146
  StringRef Body;
147
  MCAsmMacroParameters Parameters;
148
149
public:
150
  MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
151
1.90k
      : Name(N), Body(B), Parameters(std::move(P)) {}
152
153
  void dump() const { dump(dbgs()); }
154
  void dump(raw_ostream &OS) const;
155
};
156
} // namespace llvm
157
158
#endif