Coverage Report

Created: 2019-01-18 03:29

/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.9k
int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
22
19.9k
  auto *A = Args.getLastArg(Key);
23
19.9k
  if (!A)
24
19.9k
    return Default;
25
66
26
66
  int V;
27
66
  if (to_integer(A->getValue(), V, 10))
28
65
    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
13.4k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
36
13.4k
  std::vector<StringRef> V;
37
13.4k
  for (auto *Arg : Args.filtered(Id))
38
84
    V.push_back(Arg->getValue());
39
13.4k
  return V;
40
13.4k
}
41
42
uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
43
5.30k
                                    StringRef Key, uint64_t Default) {
44
5.30k
  for (auto *Arg : Args.filtered_reverse(Id)) {
45
184
    std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
46
184
    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
184
  }
53
5.30k
  
return Default5.28k
;
54
5.30k
}
55
56
58
std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
57
58
  SmallVector<StringRef, 0> Arr;
58
58
  MB.getBuffer().split(Arr, '\n');
59
58
60
58
  std::vector<StringRef> Ret;
61
207
  for (StringRef S : Arr) {
62
207
    S = S.trim();
63
207
    if (!S.empty() && 
S[0] != '#'146
)
64
146
      Ret.push_back(S);
65
207
  }
66
58
  return Ret;
67
58
}
68
69
3.56k
StringRef lld::args::getFilenameWithoutExe(StringRef Path) {
70
3.56k
  if (Path.endswith_lower(".exe"))
71
0
    return sys::path::stem(Path);
72
3.56k
  return sys::path::filename(Path);
73
3.56k
}