Coverage Report

Created: 2018-06-18 20:01

/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
14.3k
int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
21
14.3k
  auto *A = Args.getLastArg(Key);
22
14.3k
  if (!A)
23
14.3k
    return Default;
24
34
25
34
  int V;
26
34
  if (to_integer(A->getValue(), V, 10))
27
33
    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
11.7k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
35
11.7k
  std::vector<StringRef> V;
36
11.7k
  for (auto *Arg : Args.filtered(Id))
37
78
    V.push_back(Arg->getValue());
38
11.7k
  return V;
39
11.7k
}
40
41
uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
42
4.56k
                                    StringRef Key, uint64_t Default) {
43
4.56k
  for (auto *Arg : Args.filtered(Id)) {
44
152
    std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
45
152
    if (KV.first == Key) {
46
12
      uint64_t Result = Default;
47
12
      if (!to_integer(KV.second, Result))
48
2
        error("invalid " + Key + ": " + KV.second);
49
12
      return Result;
50
12
    }
51
152
  }
52
4.56k
  
return Default4.54k
;
53
4.56k
}
54
55
48
std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
56
48
  SmallVector<StringRef, 0> Arr;
57
48
  MB.getBuffer().split(Arr, '\n');
58
48
59
48
  std::vector<StringRef> Ret;
60
178
  for (StringRef S : Arr) {
61
178
    S = S.trim();
62
178
    if (!S.empty() && 
S[0] != '#'127
)
63
127
      Ret.push_back(S);
64
178
  }
65
48
  return Ret;
66
48
}