Coverage Report

Created: 2018-08-19 14:04

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/Common/Args.cpp
Line
Count
Source
1
//===- Args.cpp -----------------------------------------------------------===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "lld/Common/Args.h"
11
#include "lld/Common/ErrorHandler.h"
12
#include "llvm/ADT/SmallVector.h"
13
#include "llvm/ADT/StringExtras.h"
14
#include "llvm/ADT/StringRef.h"
15
#include "llvm/Option/ArgList.h"
16
17
using namespace llvm;
18
using namespace lld;
19
20
15.1k
int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
21
15.1k
  auto *A = Args.getLastArg(Key);
22
15.1k
  if (!A)
23
15.0k
    return Default;
24
36
25
36
  int V;
26
36
  if (to_integer(A->getValue(), V, 10))
27
35
    return V;
28
1
29
1
  StringRef Spelling = Args.getArgString(A->getIndex());
30
1
  error(Spelling + ": number expected, but got '" + A->getValue() + "'");
31
1
  return 0;
32
1
}
33
34
12.3k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
35
12.3k
  std::vector<StringRef> V;
36
12.3k
  for (auto *Arg : Args.filtered(Id))
37
79
    V.push_back(Arg->getValue());
38
12.3k
  return V;
39
12.3k
}
40
41
uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
42
4.80k
                                    StringRef Key, uint64_t Default) {
43
4.80k
  for (auto *Arg : Args.filtered(Id)) {
44
160
    std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
45
160
    if (KV.first == Key) {
46
11
      uint64_t Result = Default;
47
11
      if (!to_integer(KV.second, Result))
48
1
        error("invalid " + Key + ": " + KV.second);
49
11
      return Result;
50
11
    }
51
160
  }
52
4.80k
  
return Default4.78k
;
53
4.80k
}
54
55
50
std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
56
50
  SmallVector<StringRef, 0> Arr;
57
50
  MB.getBuffer().split(Arr, '\n');
58
50
59
50
  std::vector<StringRef> Ret;
60
191
  for (StringRef S : Arr) {
61
191
    S = S.trim();
62
191
    if (!S.empty() && 
S[0] != '#'138
)
63
138
      Ret.push_back(S);
64
191
  }
65
50
  return Ret;
66
50
}