Coverage Report

Created: 2018-10-20 12:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/Common/Args.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "llvm/Support/Path.h"
17
18
using namespace llvm;
19
using namespace lld;
20
21
19.2k
int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
22
19.2k
  auto *A = Args.getLastArg(Key);
23
19.2k
  if (!A)
24
19.1k
    return Default;
25
61
26
61
  int V;
27
61
  if (to_integer(A->getValue(), V, 10))
28
60
    return V;
29
1
30
1
  StringRef Spelling = Args.getArgString(A->getIndex());
31
1
  error(Spelling + ": number expected, but got '" + A->getValue() + "'");
32
1
  return 0;
33
1
}
34
35
12.9k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
36
12.9k
  std::vector<StringRef> V;
37
12.9k
  for (auto *Arg : Args.filtered(Id))
38
84
    V.push_back(Arg->getValue());
39
12.9k
  return V;
40
12.9k
}
41
42
uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
43
5.11k
                                    StringRef Key, uint64_t Default) {
44
5.11k
  for (auto *Arg : Args.filtered_reverse(Id)) {
45
178
    std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
46
178
    if (KV.first == Key) {
47
18
      uint64_t Result = Default;
48
18
      if (!to_integer(KV.second, Result))
49
1
        error("invalid " + Key + ": " + KV.second);
50
18
      return Result;
51
18
    }
52
178
  }
53
5.11k
  
return Default5.09k
;
54
5.11k
}
55
56
54
std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
57
54
  SmallVector<StringRef, 0> Arr;
58
54
  MB.getBuffer().split(Arr, '\n');
59
54
60
54
  std::vector<StringRef> Ret;
61
199
  for (StringRef S : Arr) {
62
199
    S = S.trim();
63
199
    if (!S.empty() && 
S[0] != '#'142
)
64
142
      Ret.push_back(S);
65
199
  }
66
54
  return Ret;
67
54
}
68
69
3.45k
StringRef lld::args::getFilenameWithoutExe(StringRef Path) {
70
3.45k
  if (Path.endswith_lower(".exe"))
71
0
    return sys::path::stem(Path);
72
3.45k
  return sys::path::filename(Path);
73
3.45k
}