Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCParser/MCAsmParser.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MCAsmParser.cpp - Abstract Asm Parser Interface -------------------===//
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/MCParser/MCAsmParser.h"
10
#include "llvm/ADT/StringRef.h"
11
#include "llvm/ADT/Twine.h"
12
#include "llvm/Config/llvm-config.h"
13
#include "llvm/MC/MCParser/MCAsmLexer.h"
14
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
15
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
16
#include "llvm/Support/Debug.h"
17
#include "llvm/Support/SMLoc.h"
18
#include "llvm/Support/raw_ostream.h"
19
#include <cassert>
20
21
using namespace llvm;
22
23
18.4k
MCAsmParser::MCAsmParser() {}
24
25
18.4k
MCAsmParser::~MCAsmParser() = default;
26
27
18.4k
void MCAsmParser::setTargetParser(MCTargetAsmParser &P) {
28
18.4k
  assert(!TargetParser && "Target parser is already initialized!");
29
18.4k
  TargetParser = &P;
30
18.4k
  TargetParser->Initialize(*this);
31
18.4k
}
32
33
66.0M
const AsmToken &MCAsmParser::getTok() const {
34
66.0M
  return getLexer().getTok();
35
66.0M
}
36
37
44.3k
bool MCAsmParser::parseTokenLoc(SMLoc &Loc) {
38
44.3k
  Loc = getTok().getLoc();
39
44.3k
  return false;
40
44.3k
}
41
42
280k
bool MCAsmParser::parseEOL(const Twine &Msg) {
43
280k
  if (getTok().getKind() != AsmToken::EndOfStatement)
44
156
    return Error(getTok().getLoc(), Msg);
45
280k
  Lex();
46
280k
  return false;
47
280k
}
48
49
693k
bool MCAsmParser::parseToken(AsmToken::TokenKind T, const Twine &Msg) {
50
693k
  if (T == AsmToken::EndOfStatement)
51
280k
    return parseEOL(Msg);
52
413k
  if (getTok().getKind() != T)
53
121
    return Error(getTok().getLoc(), Msg);
54
413k
  Lex();
55
413k
  return false;
56
413k
}
57
58
1.77k
bool MCAsmParser::parseIntToken(int64_t &V, const Twine &Msg) {
59
1.77k
  if (getTok().getKind() != AsmToken::Integer)
60
7
    return TokError(Msg);
61
1.76k
  V = getTok().getIntVal();
62
1.76k
  Lex();
63
1.76k
  return false;
64
1.76k
}
65
66
1.41M
bool MCAsmParser::parseOptionalToken(AsmToken::TokenKind T) {
67
1.41M
  bool Present = (getTok().getKind() == T);
68
1.41M
  if (Present)
69
471k
    parseToken(T);
70
1.41M
  return Present;
71
1.41M
}
72
73
19.3k
bool MCAsmParser::check(bool P, const Twine &Msg) {
74
19.3k
  return check(P, getTok().getLoc(), Msg);
75
19.3k
}
76
77
138k
bool MCAsmParser::check(bool P, SMLoc Loc, const Twine &Msg) {
78
138k
  if (P)
79
61
    return Error(Loc, Msg);
80
138k
  return false;
81
138k
}
82
83
973
bool MCAsmParser::TokError(const Twine &Msg, SMRange Range) {
84
973
  return Error(getLexer().getLoc(), Msg, Range);
85
973
}
86
87
80.2k
bool MCAsmParser::Error(SMLoc L, const Twine &Msg, SMRange Range) {
88
80.2k
89
80.2k
  MCPendingError PErr;
90
80.2k
  PErr.Loc = L;
91
80.2k
  Msg.toVector(PErr.Msg);
92
80.2k
  PErr.Range = Range;
93
80.2k
  PendingErrors.push_back(PErr);
94
80.2k
95
80.2k
  // If we threw this parsing error after a lexing error, this should
96
80.2k
  // supercede the lexing error and so we remove it from the Lexer
97
80.2k
  // before it can propagate
98
80.2k
  if (getTok().is(AsmToken::Error))
99
17
    getLexer().Lex();
100
80.2k
  return true;
101
80.2k
}
102
103
219
bool MCAsmParser::addErrorSuffix(const Twine &Suffix) {
104
219
  // Make sure lexing errors have propagated to the parser.
105
219
  if (getTok().is(AsmToken::Error))
106
2
    Lex();
107
219
  for (auto &PErr : PendingErrors)
108
221
    Suffix.toVector(PErr.Msg);
109
219
  return true;
110
219
}
111
112
153k
bool MCAsmParser::parseMany(function_ref<bool()> parseOne, bool hasComma) {
113
153k
  if (parseOptionalToken(AsmToken::EndOfStatement))
114
660
    return false;
115
153k
  
while (152k
true) {
116
153k
    if (parseOne())
117
80
      return true;
118
153k
    if (parseOptionalToken(AsmToken::EndOfStatement))
119
152k
      return false;
120
1.71k
    if (hasComma && parseToken(AsmToken::Comma))
121
104
      return true;
122
1.71k
  }
123
152k
  
return false0
;
124
152k
}
125
126
163k
bool MCAsmParser::parseExpression(const MCExpr *&Res) {
127
163k
  SMLoc L;
128
163k
  return parseExpression(Res, L);
129
163k
}
130
131
0
void MCParsedAsmOperand::dump() const {
132
0
  // Cannot completely remove virtual function even in release mode.
133
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
134
  dbgs() << "  " << *this;
135
#endif
136
}