11 #include "llvm/ADT/SmallString.h" 12 #include "llvm/ADT/StringMap.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/ADT/StringSet.h" 15 #include "llvm/Support/Compiler.h" 16 #include "llvm/Support/ErrorHandling.h" 17 #include "llvm/Support/Path.h" 18 #include "llvm/Support/Regex.h" 19 #include "llvm/Support/raw_ostream.h" 24 using namespace clang;
25 using namespace driver;
30 StringRef seg = Segment;
34 StringRef last = path::filename(seg);
37 seg = path::parent_path(seg);
40 if (seg.empty() || seg ==
"/") {
46 if (seg.front() !=
'/') {
47 Segment =
"/" + seg.str();
54 StringRef IncludeSuffix,
int Priority)
55 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
85 assert(GCCSuffix.empty() || (StringRef(GCCSuffix).front() ==
'/'));
86 if (GCCSuffix.empty())
89 OS << StringRef(GCCSuffix).drop_front();
92 for (StringRef Flag : Flags) {
93 if (Flag.front() ==
'+')
94 OS <<
"@" << Flag.substr(1);
99 llvm::StringMap<int> FlagSet;
100 for (
unsigned I = 0, N = Flags.size(); I != N; ++I) {
101 StringRef Flag(Flags[I]);
102 llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
104 assert(StringRef(Flag).front() ==
'+' || StringRef(Flag).front() ==
'-');
106 if (SI == FlagSet.end())
107 FlagSet[Flag.substr(1)] = I;
108 else if (Flags[I] != Flags[SI->getValue()])
117 llvm::StringSet<> MyFlags;
118 for (
const auto &Flag : Flags)
119 MyFlags.insert(Flag);
121 for (
const auto &Flag : Other.Flags)
122 if (MyFlags.find(Flag) == MyFlags.end())
145 for (StringRef Flag : M.
flags()) {
146 if (Flag.front() ==
'+')
147 Opposite.
flags().push_back((
"-" + Flag.substr(1)).str());
149 return Either(M, Opposite);
153 return Either({M1, M2});
158 return Either({M1, M2, M3});
163 return Either({M1, M2, M3, M4});
169 return Either({M1, M2, M3, M4, M5});
178 llvm::sys::path::append(IncludeSuffix,
"/", Base.
includeSuffix(),
181 Multilib Composed(GCCSuffix, OSSuffix, IncludeSuffix);
185 Flags.insert(Flags.end(), Base.
flags().begin(), Base.
flags().end());
186 Flags.insert(Flags.end(), New.
flags().begin(), New.
flags().end());
194 if (Multilibs.empty())
195 Multilibs.insert(Multilibs.end(), MultilibSegments.begin(),
196 MultilibSegments.end());
198 for (
const auto &New : MultilibSegments) {
199 for (
const auto &
Base : *
this) {
202 Composed.push_back(MO);
206 Multilibs = Composed;
213 filterInPlace(F, Multilibs);
218 llvm::Regex R(Regex);
221 if (!R.isValid(Error)) {
222 llvm::errs() << Error;
223 llvm_unreachable(
"Invalid regex!");
235 Multilibs.insert(Multilibs.end(), Other.
begin(), Other.
end());
239 char Indicator = Flag.front();
240 assert(Indicator ==
'+' || Indicator ==
'-');
241 return Indicator ==
'+';
245 llvm::StringMap<bool> FlagSet;
249 for (StringRef Flag : Flags)
253 for (StringRef Flag : M.
flags()) {
254 llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
255 if (SI != FlagSet.end())
262 if (Filtered.empty())
264 if (Filtered.size() == 1) {
270 llvm::sort(Filtered.begin(), Filtered.end(),
275 if (Filtered[0].
priority() > Filtered[1].priority()) {
281 assert(
false &&
"More than one multilib with the same priority");
290 for (
const auto &M : *
this)
297 filterInPlace(F, Copy);
302 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.
bool operator==(const Multilib &Other) const
static Multilib compose(const Multilib &Base, const Multilib &New)
std::vector< Multilib > multilib_list
bool select(const Multilib::flags_list &Flags, Multilib &M) const
Pick the best multilib in the set,.
const std::string & includeSuffix() const
Get the include directory suffix.
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.
void combineWith(const MultilibSet &MS)
Union this set of multilibs with another.
static void normalizePathSegment(std::string &Segment)
normalize Segment to "/foo/bar" or "".
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
void print(raw_ostream &OS) const
Multilib(StringRef GCCSuffix={}, StringRef OSSuffix={}, StringRef IncludeSuffix={}, int Priority=0)
LLVM_DUMP_METHOD void dump() const
std::vector< std::string > flags_list
void push_back(const Multilib &M)
Add a completed Multilib to the set.
const flags_list & flags() const
Get the flags that indicate or contraindicate this multilib's use All elements begin with either '+' ...
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag...
int priority() const
Returns the multilib priority.
bool isValid() const
Check whether any of the 'against' flags contradict the 'for' flags.
void print(raw_ostream &OS) const
print summary of the Multilib
llvm::function_ref< bool(const Multilib &)> FilterCallback
Dataflow Directional Tag Classes.
MultilibSet & FilterOut(FilterCallback F)
Filter out some subset of the Multilibs using a user defined callback.
static bool isFlagEnabled(StringRef Flag)
LLVM_DUMP_METHOD void dump() const