Coverage Report

Created: 2019-07-24 05:18

/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.86k
CodeGenOpt::Level lld::args::getCGOptLevel(int optLevelLTO) {
23
2.86k
  if (optLevelLTO == 3)
24
0
    return CodeGenOpt::Aggressive;
25
2.86k
  assert(optLevelLTO < 3);
26
2.86k
  return CodeGenOpt::Default;
27
2.86k
}
28
29
int64_t lld::args::getInteger(opt::InputArgList &args, unsigned key,
30
23.1k
                              int64_t Default) {
31
23.1k
  auto *a = args.getLastArg(key);
32
23.1k
  if (!a)
33
23.0k
    return Default;
34
85
35
85
  int64_t v;
36
85
  if (to_integer(a->getValue(), v, 10))
37
83
    return v;
38
2
39
2
  StringRef spelling = args.getArgString(a->getIndex());
40
2
  error(spelling + ": number expected, but got '" + a->getValue() + "'");
41
2
  return 0;
42
2
}
43
44
18.1k
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &args, int id) {
45
18.1k
  std::vector<StringRef> v;
46
18.1k
  for (auto *arg : args.filtered(id))
47
95
    v.push_back(arg->getValue());
48
18.1k
  return v;
49
18.1k
}
50
51
uint64_t lld::args::getZOptionValue(opt::InputArgList &args, int id,
52
8.75k
                                    StringRef key, uint64_t Default) {
53
8.75k
  for (auto *arg : args.filtered_reverse(id)) {
54
333
    std::pair<StringRef, StringRef> kv = StringRef(arg->getValue()).split('=');
55
333
    if (kv.first == key) {
56
32
      uint64_t result = Default;
57
32
      if (!to_integer(kv.second, result))
58
1
        error("invalid " + key + ": " + kv.second);
59
32
      return result;
60
32
    }
61
333
  }
62
8.75k
  
return Default8.71k
;
63
8.75k
}
64
65
65
std::vector<StringRef> lld::args::getLines(MemoryBufferRef mb) {
66
65
  SmallVector<StringRef, 0> arr;
67
65
  mb.getBuffer().split(arr, '\n');
68
65
69
65
  std::vector<StringRef> ret;
70
239
  for (StringRef s : arr) {
71
239
    s = s.trim();
72
239
    if (!s.empty() && 
s[0] != '#'171
)
73
171
      ret.push_back(s);
74
239
  }
75
65
  return ret;
76
65
}
77
78
4.14k
StringRef lld::args::getFilenameWithoutExe(StringRef path) {
79
4.14k
  if (path.endswith_lower(".exe"))
80
0
    return sys::path::stem(path);
81
4.14k
  return sys::path::filename(path);
82
4.14k
}