13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSet.h"
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/Option/Arg.h"
18 #include "llvm/Option/ArgList.h"
19 #include "llvm/Option/OptTable.h"
20 #include "llvm/Option/Option.h"
21 #include "llvm/Support/MemoryBuffer.h"
22 #include "llvm/Support/Path.h"
23 #include "llvm/Support/Regex.h"
24 #include "llvm/Support/YAMLParser.h"
25 #include "llvm/Support/YAMLTraits.h"
26 #include "llvm/Support/raw_ostream.h"
29 using namespace clang::driver;
30 using namespace clang;
31 using namespace llvm::opt;
32 using namespace llvm::sys;
36 StringRef seg = Segment;
40 StringRef last = path::filename(seg);
43 seg = path::parent_path(seg);
46 if (seg.empty() || seg ==
"/") {
52 if (seg.front() !=
'/') {
53 Segment =
"/" + seg.str();
60 StringRef IncludeSuffix)
61 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {
86 assert(GCCSuffix.empty() || (StringRef(GCCSuffix).front() ==
'/'));
87 if (GCCSuffix.empty())
90 OS << StringRef(GCCSuffix).drop_front();
93 for (StringRef Flag : Flags) {
94 if (Flag.front() ==
'+')
95 OS <<
"@" << Flag.substr(1);
100 llvm::StringMap<int> FlagSet;
101 for (
unsigned I = 0, N = Flags.size(); I != N; ++I) {
102 StringRef Flag(Flags[I]);
103 llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
105 assert(StringRef(Flag).front() ==
'+' || StringRef(Flag).front() ==
'-');
107 if (SI == FlagSet.end())
108 FlagSet[Flag.substr(1)] = I;
109 else if (Flags[I] != Flags[SI->getValue()])
118 llvm::StringSet<> MyFlags;
119 for (
const auto &Flag : Flags)
120 MyFlags.insert(Flag);
122 for (
const auto &Flag : Other.Flags)
123 if (MyFlags.find(Flag) == MyFlags.end())
146 for (StringRef Flag : M.
flags()) {
147 if (Flag.front() ==
'+')
148 Opposite.
flags().push_back((
"-" + Flag.substr(1)).str());
150 return Either(M, Opposite);
159 return Either({M1, M2, M3});
164 return Either({M1, M2, M3, M4});
170 return Either({M1, M2, M3, M4, M5});
179 llvm::sys::path::append(IncludeSuffix,
"/", Base.
includeSuffix(),
182 Multilib Composed(GCCSuffix, OSSuffix, IncludeSuffix);
186 Flags.insert(Flags.end(), Base.
flags().begin(), Base.
flags().end());
187 Flags.insert(Flags.end(), New.
flags().begin(), New.
flags().end());
195 if (Multilibs.empty())
196 Multilibs.insert(Multilibs.end(), MultilibSegments.begin(),
197 MultilibSegments.end());
199 for (
const Multilib &New : MultilibSegments) {
203 Composed.push_back(MO);
207 Multilibs = Composed;
214 filterInPlace(F, Multilibs);
219 llvm::Regex R(Regex);
222 if (!R.isValid(Error)) {
223 llvm::errs() <<
Error;
224 llvm_unreachable(
"Invalid regex!");
236 Multilibs.insert(Multilibs.end(), Other.
begin(), Other.
end());
240 char Indicator = Flag.front();
241 assert(Indicator ==
'+' || Indicator ==
'-');
242 return Indicator ==
'+';
246 llvm::StringMap<bool> FlagSet;
250 for (StringRef Flag : Flags)
254 for (StringRef Flag : M.
flags()) {
255 llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
256 if (SI != FlagSet.end())
263 if (Filtered.size() == 0) {
265 }
else if (Filtered.size() == 1) {
282 const multilib_list &Ms) {
284 filterInPlace(F, Copy);
288 void MultilibSet::filterInPlace(FilterCallback F, multilib_list &Ms) {
289 Ms.erase(std::remove_if(Ms.begin(), Ms.end(), F), Ms.end());
MultilibSet & Either(const Multilib &M1, const Multilib &M2)
Add a set of mutually incompatible Multilib segments.
MultilibSet & Maybe(const Multilib &M)
Add an optional Multilib segment.
const std::string & includeSuffix() const
Get the include directory suffix. Always starts with a '/', unless empty.
static Multilib compose(const Multilib &Base, const Multilib &New)
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant. Always starts with a '/'...
llvm::function_ref< bool(const Multilib &)> FilterCallback
const flags_list & flags() const
Get the flags that indicate or contraindicate this multilib's use All elements begin with either '+' ...
raw_ostream & operator<<(raw_ostream &OS, const Multilib &M)
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant. Always starts with a...
void combineWith(const MultilibSet &MS)
Union this set of multilibs with another.
std::vector< Multilib > multilib_list
static void normalizePathSegment(std::string &Segment)
normalize Segment to "/foo/bar" or "".
void push_back(const Multilib &M)
Add a completed Multilib to the set.
Multilib(StringRef GCCSuffix="", StringRef OSSuffix="", StringRef IncludeSuffix="")
bool operator==(const Multilib &Other) const
void print(raw_ostream &OS) const
print summary of the Multilib
MultilibSet & FilterOut(FilterCallback F)
Filter out some subset of the Multilibs using a user defined callback.
bool isValid() const
Check whether any of the 'against' flags contradict the 'for' flags.
static bool isFlagEnabled(StringRef Flag)
std::vector< std::string > flags_list
bool select(const Multilib::flags_list &Flags, Multilib &M) const
Pick the best multilib in the set,.
void print(raw_ostream &OS) const