Coverage Report

Created: 2019-05-19 14:56

/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
// 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 "lld/Common/Args.h"
10
#include "lld/Common/ErrorHandler.h"
11
#include "llvm/ADT/SmallVector.h"
12
#include "llvm/ADT/StringExtras.h"
13
#include "llvm/ADT/StringRef.h"
14
#include "llvm/Option/ArgList.h"
15
#include "llvm/Support/Path.h"
16
17
using namespace llvm;
18
using namespace lld;
19
20
// TODO(sbc): Remove this once CGOptLevel can be set completely based on bitcode
21
// function metadata.
22
2.62k
CodeGenOpt::Level lld::args::getCGOptLevel(int OptLevelLTO) {
23
2.62k
  if (OptLevelLTO == 3)
24
0
    return CodeGenOpt::Aggressive;
25
2.62k
  assert(OptLevelLTO < 3);
26
2.62k
  return CodeGenOpt::Default;
27
2.62k
}
28
29
21.3k
int lld::args::getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
30
21.3k
  auto *A = Args.getLastArg(Key);
31
21.3k
  if (!A)
32
21.2k
    return Default;
33
72
34
72
  int V;
35
72
  if (to_integer(A->getValue(), V, 10))
36
70
    return V;
37
2
38
2
  StringRef Spelling = Args.getArgString(A->getIndex());
39
2
  error(Spelling + ": number expected, but got '" + A->getValue() + "'");
40
2
  return 0;
41
2
}
42
43
14.1k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &Args, int Id) {
44
14.1k
  std::vector<StringRef> V;
45
14.1k
  for (auto *Arg : Args.filtered(Id))
46
90
    V.push_back(Arg->getValue());
47
14.1k
  return V;
48
14.1k
}
49
50
uint64_t lld::args::getZOptionValue(opt::InputArgList &Args, int Id,
51
8.03k
                                    StringRef Key, uint64_t Default) {
52
8.03k
  for (auto *Arg : Args.filtered_reverse(Id)) {
53
333
    std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
54
333
    if (KV.first == Key) {
55
32
      uint64_t Result = Default;
56
32
      if (!to_integer(KV.second, Result))
57
1
        error("invalid " + Key + ": " + KV.second);
58
32
      return Result;
59
32
    }
60
333
  }
61
8.03k
  
return Default8.00k
;
62
8.03k
}
63
64
61
std::vector<StringRef> lld::args::getLines(MemoryBufferRef MB) {
65
61
  SmallVector<StringRef, 0> Arr;
66
61
  MB.getBuffer().split(Arr, '\n');
67
61
68
61
  std::vector<StringRef> Ret;
69
222
  for (StringRef S : Arr) {
70
222
    S = S.trim();
71
222
    if (!S.empty() && 
S[0] != '#'158
)
72
158
      Ret.push_back(S);
73
222
  }
74
61
  return Ret;
75
61
}
76
77
3.83k
StringRef lld::args::getFilenameWithoutExe(StringRef Path) {
78
3.83k
  if (Path.endswith_lower(".exe"))
79
0
    return sys::path::stem(Path);
80
3.83k
  return sys::path::filename(Path);
81
3.83k
}