13 #include "llvm/ADT/StringMap.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/ADT/StringSet.h" 16 #include "llvm/Option/Arg.h" 17 #include "llvm/Option/ArgList.h" 18 #include "llvm/Option/OptTable.h" 19 #include "llvm/Option/Option.h" 20 #include "llvm/Support/Path.h" 21 #include "llvm/Support/Regex.h" 22 #include "llvm/Support/YAMLParser.h" 23 #include "llvm/Support/YAMLTraits.h" 24 #include "llvm/Support/raw_ostream.h" 28 using namespace clang;
34 StringRef seg = Segment;
38 StringRef last = path::filename(seg);
41 seg = path::parent_path(seg);
44 if (seg.empty() || seg ==
"/") {
50 if (seg.front() !=
'/') {
51 Segment =
"/" + seg.str();
58 StringRef IncludeSuffix)
59 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {
88 assert(GCCSuffix.empty() || (StringRef(GCCSuffix).front() ==
'/'));
89 if (GCCSuffix.empty())
92 OS << StringRef(GCCSuffix).drop_front();
95 for (StringRef Flag : Flags) {
96 if (Flag.front() ==
'+')
97 OS <<
"@" << Flag.substr(1);
102 llvm::StringMap<int> FlagSet;
103 for (
unsigned I = 0, N = Flags.size(); I != N; ++I) {
104 StringRef Flag(Flags[I]);
105 llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
107 assert(StringRef(Flag).front() ==
'+' || StringRef(Flag).front() ==
'-');
109 if (SI == FlagSet.end())
110 FlagSet[Flag.substr(1)] = I;
111 else if (Flags[I] != Flags[SI->getValue()])
120 llvm::StringSet<> MyFlags;
121 for (
const auto &Flag : Flags)
122 MyFlags.insert(Flag);
124 for (
const auto &Flag : Other.Flags)
125 if (MyFlags.find(Flag) == MyFlags.end())
148 for (StringRef Flag : M.
flags()) {
149 if (Flag.front() ==
'+')
150 Opposite.
flags().push_back((
"-" + Flag.substr(1)).str());
152 return Either(M, Opposite);
156 return Either({M1, M2});
161 return Either({M1, M2, M3});
166 return Either({M1, M2, M3, M4});
172 return Either({M1, M2, M3, M4, M5});
181 llvm::sys::path::append(IncludeSuffix,
"/", Base.
includeSuffix(),
184 Multilib Composed(GCCSuffix, OSSuffix, IncludeSuffix);
188 Flags.insert(Flags.end(), Base.
flags().begin(), Base.
flags().end());
189 Flags.insert(Flags.end(), New.
flags().begin(), New.
flags().end());
197 if (Multilibs.empty())
198 Multilibs.insert(Multilibs.end(), MultilibSegments.begin(),
199 MultilibSegments.end());
201 for (
const Multilib &New : MultilibSegments) {
205 Composed.push_back(MO);
209 Multilibs = Composed;
216 filterInPlace(F, Multilibs);
221 llvm::Regex R(Regex);
224 if (!R.isValid(Error)) {
225 llvm::errs() << Error;
226 llvm_unreachable(
"Invalid regex!");
238 Multilibs.insert(Multilibs.end(), Other.
begin(), Other.
end());
242 char Indicator = Flag.front();
243 assert(Indicator ==
'+' || Indicator ==
'-');
244 return Indicator ==
'+';
248 llvm::StringMap<bool> FlagSet;
252 for (StringRef Flag : Flags)
256 for (StringRef Flag : M.
flags()) {
257 llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
258 if (SI != FlagSet.end())
265 if (Filtered.size() == 0)
267 if (Filtered.size() == 1) {
289 filterInPlace(F, Copy);
294 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)
llvm::function_ref< bool(const Multilib &)> FilterCallback
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.
std::vector< Multilib > multilib_list
static void normalizePathSegment(std::string &Segment)
normalize Segment to "/foo/bar" or "".
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
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...
bool isValid() const
Check whether any of the 'against' flags contradict the 'for' flags.
Multilib(StringRef GCCSuffix="", StringRef OSSuffix="", StringRef IncludeSuffix="")
void print(raw_ostream &OS) const
print summary of the Multilib
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
std::vector< std::string > flags_list