Coverage Report

Created: 2019-07-24 05:18

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