Clang Project

clang_source_code/include/clang/Driver/Multilib.h
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
23namespace clang {
24namespace driver {
25
26/// This corresponds to a single GCC Multilib, or a segment of one controlled
27/// by a command line flag
28class Multilib {
29public:
30  using flags_list = std::vector<std::string>;
31
32private:
33  std::string GCCSuffix;
34  std::string OSSuffix;
35  std::string IncludeSuffix;
36  flags_list Flags;
37
38public:
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  const std::string &gccSuffix() const {
45     1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 46, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(GCCSuffix.empty() ||
46 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 46, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
47    return GCCSuffix;
48  }
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  const std::string &osSuffix() const {
56     1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 57, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(OSSuffix.empty() ||
57 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 57, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
58    return OSSuffix;
59  }
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  const std::string &includeSuffix() const {
67     1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 68, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(IncludeSuffix.empty() ||
68 1)", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Multilib.h", 68, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1));
69    return IncludeSuffix;
70  }
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  const flags_list &flags() const { return Flags; }
78  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  Multilib &flag(StringRef F) {
88    assert(F.front() == '+' || F.front() == '-');
89    Flags.push_back(F);
90    return *this;
91  }
92
93  LLVM_DUMP_METHOD void dump() const;
94  /// print summary of the Multilib
95  void print(raw_ostream &OSconst;
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  { return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); }
103
104  bool operator==(const Multilib &Otherconst;
105};
106
107raw_ostream &operator<<(raw_ostream &OSconst Multilib &M);
108
109class MultilibSet {
110public:
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
118private:
119  multilib_list Multilibs;
120  IncludeDirsFunc IncludeCallback;
121  IncludeDirsFunc FilePathsCallback;
122
123public:
124  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 &M1const Multilib &M2);
131  MultilibSet &Either(const Multilib &M1const Multilib &M2,
132                      const Multilib &M3);
133  MultilibSet &Either(const Multilib &M1const Multilib &M2,
134                      const Multilib &M3const Multilib &M4);
135  MultilibSet &Either(const Multilib &M1const Multilib &M2,
136                      const Multilib &M3const Multilib &M4,
137                      const Multilib &M5);
138  MultilibSet &Either(ArrayRef<MultilibMs);
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  iterator begin() { return Multilibs.begin(); }
156  const_iterator begin() const { return Multilibs.begin(); }
157
158  iterator end() { return Multilibs.end(); }
159  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 &FlagsMultilib &Mconst;
163
164  unsigned size() const { return Multilibs.size(); }
165
166  LLVM_DUMP_METHOD void dump() const;
167  void print(raw_ostream &OSconst;
168
169  MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
170    IncludeCallback = std::move(F);
171    return *this;
172  }
173
174  const IncludeDirsFunc &includeDirsCallback() const { return IncludeCallback; }
175
176  MultilibSet &setFilePathsCallback(IncludeDirsFunc F) {
177    FilePathsCallback = std::move(F);
178    return *this;
179  }
180
181  const IncludeDirsFunc &filePathsCallback() const { return FilePathsCallback; }
182
183private:
184  /// Apply the filter to Multilibs and return the subset that remains
185  static multilib_list filterCopy(FilterCallback Fconst multilib_list &Ms);
186
187  /// Apply the filter to the multilib_list, removing those that don't match
188  static void filterInPlace(FilterCallback Fmultilib_list &Ms);
189};
190
191raw_ostream &operator<<(raw_ostream &OSconst MultilibSet &MS);
192
193// namespace driver
194// namespace clang
195
196#endif // LLVM_CLANG_DRIVER_MULTILIB_H
197
clang::driver::Multilib::GCCSuffix
clang::driver::Multilib::OSSuffix
clang::driver::Multilib::IncludeSuffix
clang::driver::Multilib::Flags
clang::driver::Multilib::gccSuffix
clang::driver::Multilib::gccSuffix
clang::driver::Multilib::osSuffix
clang::driver::Multilib::osSuffix
clang::driver::Multilib::includeSuffix
clang::driver::Multilib::includeSuffix
clang::driver::Multilib::flags
clang::driver::Multilib::flags
clang::driver::Multilib::flag
clang::driver::Multilib::dump
clang::driver::Multilib::print
clang::driver::Multilib::isValid
clang::driver::Multilib::isDefault
clang::driver::MultilibSet::Multilibs
clang::driver::MultilibSet::IncludeCallback
clang::driver::MultilibSet::FilePathsCallback
clang::driver::MultilibSet::Maybe
clang::driver::MultilibSet::Either
clang::driver::MultilibSet::Either
clang::driver::MultilibSet::Either
clang::driver::MultilibSet::Either
clang::driver::MultilibSet::Either
clang::driver::MultilibSet::FilterOut
clang::driver::MultilibSet::FilterOut
clang::driver::MultilibSet::push_back
clang::driver::MultilibSet::combineWith
clang::driver::MultilibSet::clear
clang::driver::MultilibSet::begin
clang::driver::MultilibSet::begin
clang::driver::MultilibSet::end
clang::driver::MultilibSet::end
clang::driver::MultilibSet::select
clang::driver::MultilibSet::size
clang::driver::MultilibSet::dump
clang::driver::MultilibSet::print
clang::driver::MultilibSet::setIncludeDirsCallback
clang::driver::MultilibSet::includeDirsCallback
clang::driver::MultilibSet::setFilePathsCallback
clang::driver::MultilibSet::filePathsCallback
clang::driver::MultilibSet::filterCopy
clang::driver::MultilibSet::filterInPlace