Coverage Report

Created: 2019-02-20 07:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Driver/Multilib.h
Line
Count
Source
1
//===- Multilib.h -----------------------------------------------*- C++ -*-===//
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
#ifndef LLVM_CLANG_DRIVER_MULTILIB_H
10
#define LLVM_CLANG_DRIVER_MULTILIB_H
11
12
#include "clang/Basic/LLVM.h"
13
#include "llvm/ADT/ArrayRef.h"
14
#include "llvm/ADT/STLExtras.h"
15
#include "llvm/ADT/StringRef.h"
16
#include "llvm/Support/Compiler.h"
17
#include <cassert>
18
#include <functional>
19
#include <string>
20
#include <utility>
21
#include <vector>
22
23
namespace clang {
24
namespace driver {
25
26
/// This corresponds to a single GCC Multilib, or a segment of one controlled
27
/// by a command line flag
28
class Multilib {
29
public:
30
  using flags_list = std::vector<std::string>;
31
32
private:
33
  std::string GCCSuffix;
34
  std::string OSSuffix;
35
  std::string IncludeSuffix;
36
  flags_list Flags;
37
38
public:
39
  Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
40
           StringRef IncludeSuffix = {});
41
42
  /// Get the detected GCC installation path suffix for the multi-arch
43
  /// target variant. Always starts with a '/', unless empty
44
172k
  const std::string &gccSuffix() const {
45
172k
    assert(GCCSuffix.empty() ||
46
172k
           (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
47
172k
    return GCCSuffix;
48
172k
  }
49
50
  /// Set the GCC installation path suffix.
51
  Multilib &gccSuffix(StringRef S);
52
53
  /// Get the detected os path suffix for the multi-arch
54
  /// target variant. Always starts with a '/', unless empty
55
107k
  const std::string &osSuffix() const {
56
107k
    assert(OSSuffix.empty() ||
57
107k
           (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
58
107k
    return OSSuffix;
59
107k
  }
60
61
  /// Set the os path suffix.
62
  Multilib &osSuffix(StringRef S);
63
64
  /// Get the include directory suffix. Always starts with a '/', unless
65
  /// empty
66
106k
  const std::string &includeSuffix() const {
67
106k
    assert(IncludeSuffix.empty() ||
68
106k
           (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1));
69
106k
    return IncludeSuffix;
70
106k
  }
71
72
  /// Set the include directory suffix
73
  Multilib &includeSuffix(StringRef S);
74
75
  /// Get the flags that indicate or contraindicate this multilib's use
76
  /// All elements begin with either '+' or '-'
77
219k
  const flags_list &flags() const { return Flags; }
78
53.4k
  flags_list &flags() { return Flags; }
79
80
  /// Add a flag to the flags list
81
  /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
82
  ///     and replaced with either:
83
  ///       '-' which contraindicates using this multilib with that flag
84
  ///     or:
85
  ///       '+' which promotes using this multilib in the presence of that flag
86
  ///     otherwise '-print-multi-lib' will not emit them correctly.
87
14.5k
  Multilib &flag(StringRef F) {
88
14.5k
    assert(F.front() == '+' || F.front() == '-');
89
14.5k
    Flags.push_back(F);
90
14.5k
    return *this;
91
14.5k
  }
92
93
  LLVM_DUMP_METHOD void dump() const;
94
  /// print summary of the Multilib
95
  void print(raw_ostream &OS) const;
96
97
  /// Check whether any of the 'against' flags contradict the 'for' flags.
98
  bool isValid() const;
99
100
  /// Check whether the default is selected
101
  bool isDefault() const
102
79
  { return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); }
103
104
  bool operator==(const Multilib &Other) const;
105
};
106
107
raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
108
109
class MultilibSet {
110
public:
111
  using multilib_list = std::vector<Multilib>;
112
  using iterator = multilib_list::iterator;
113
  using const_iterator = multilib_list::const_iterator;
114
  using IncludeDirsFunc =
115
      std::function<std::vector<std::string>(const Multilib &M)>;
116
  using FilterCallback = llvm::function_ref<bool(const Multilib &)>;
117
118
private:
119
  multilib_list Multilibs;
120
  IncludeDirsFunc IncludeCallback;
121
  IncludeDirsFunc FilePathsCallback;
122
123
public:
124
38.4k
  MultilibSet() = default;
125
126
  /// Add an optional Multilib segment
127
  MultilibSet &Maybe(const Multilib &M);
128
129
  /// Add a set of mutually incompatible Multilib segments
130
  MultilibSet &Either(const Multilib &M1, const Multilib &M2);
131
  MultilibSet &Either(const Multilib &M1, const Multilib &M2,
132
                      const Multilib &M3);
133
  MultilibSet &Either(const Multilib &M1, const Multilib &M2,
134
                      const Multilib &M3, const Multilib &M4);
135
  MultilibSet &Either(const Multilib &M1, const Multilib &M2,
136
                      const Multilib &M3, const Multilib &M4,
137
                      const Multilib &M5);
138
  MultilibSet &Either(ArrayRef<Multilib> Ms);
139
140
  /// Filter out some subset of the Multilibs using a user defined callback
141
  MultilibSet &FilterOut(FilterCallback F);
142
143
  /// Filter out those Multilibs whose gccSuffix matches the given expression
144
  MultilibSet &FilterOut(const char *Regex);
145
146
  /// Add a completed Multilib to the set
147
  void push_back(const Multilib &M);
148
149
  /// Union this set of multilibs with another
150
  void combineWith(const MultilibSet &MS);
151
152
  /// Remove all of the multilibs from the set
153
  void clear() { Multilibs.clear(); }
154
155
2.30k
  iterator begin() { return Multilibs.begin(); }
156
88
  const_iterator begin() const { return Multilibs.begin(); }
157
158
2.30k
  iterator end() { return Multilibs.end(); }
159
88
  const_iterator end() const { return Multilibs.end(); }
160
161
  /// Pick the best multilib in the set, \returns false if none are compatible
162
  bool select(const Multilib::flags_list &Flags, Multilib &M) const;
163
164
175
  unsigned size() const { return Multilibs.size(); }
165
166
  LLVM_DUMP_METHOD void dump() const;
167
  void print(raw_ostream &OS) const;
168
169
317
  MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
170
317
    IncludeCallback = std::move(F);
171
317
    return *this;
172
317
  }
173
174
404
  const IncludeDirsFunc &includeDirsCallback() const { return IncludeCallback; }
175
176
138
  MultilibSet &setFilePathsCallback(IncludeDirsFunc F) {
177
138
    FilePathsCallback = std::move(F);
178
138
    return *this;
179
138
  }
180
181
398
  const IncludeDirsFunc &filePathsCallback() const { return FilePathsCallback; }
182
183
private:
184
  /// Apply the filter to Multilibs and return the subset that remains
185
  static multilib_list filterCopy(FilterCallback F, const multilib_list &Ms);
186
187
  /// Apply the filter to the multilib_list, removing those that don't match
188
  static void filterInPlace(FilterCallback F, multilib_list &Ms);
189
};
190
191
raw_ostream &operator<<(raw_ostream &OS, const MultilibSet &MS);
192
193
} // namespace driver
194
} // namespace clang
195
196
#endif // LLVM_CLANG_DRIVER_MULTILIB_H