1*0a6a1f1dSLionel Sambuc //===--- Multilib.cpp - Multilib Implementation ---------------------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc
10*0a6a1f1dSLionel Sambuc #include "clang/Driver/Multilib.h"
11*0a6a1f1dSLionel Sambuc #include "Tools.h"
12*0a6a1f1dSLionel Sambuc #include "clang/Driver/Options.h"
13*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringMap.h"
14*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringRef.h"
15*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringSet.h"
16*0a6a1f1dSLionel Sambuc #include "llvm/ADT/Triple.h"
17*0a6a1f1dSLionel Sambuc #include "llvm/Option/Arg.h"
18*0a6a1f1dSLionel Sambuc #include "llvm/Option/ArgList.h"
19*0a6a1f1dSLionel Sambuc #include "llvm/Option/OptTable.h"
20*0a6a1f1dSLionel Sambuc #include "llvm/Option/Option.h"
21*0a6a1f1dSLionel Sambuc #include "llvm/Support/MemoryBuffer.h"
22*0a6a1f1dSLionel Sambuc #include "llvm/Support/Path.h"
23*0a6a1f1dSLionel Sambuc #include "llvm/Support/Regex.h"
24*0a6a1f1dSLionel Sambuc #include "llvm/Support/YAMLParser.h"
25*0a6a1f1dSLionel Sambuc #include "llvm/Support/YAMLTraits.h"
26*0a6a1f1dSLionel Sambuc #include "llvm/Support/raw_ostream.h"
27*0a6a1f1dSLionel Sambuc #include <algorithm>
28*0a6a1f1dSLionel Sambuc
29*0a6a1f1dSLionel Sambuc using namespace clang::driver;
30*0a6a1f1dSLionel Sambuc using namespace clang;
31*0a6a1f1dSLionel Sambuc using namespace llvm::opt;
32*0a6a1f1dSLionel Sambuc using namespace llvm::sys;
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc /// normalize Segment to "/foo/bar" or "".
normalizePathSegment(std::string & Segment)35*0a6a1f1dSLionel Sambuc static void normalizePathSegment(std::string &Segment) {
36*0a6a1f1dSLionel Sambuc StringRef seg = Segment;
37*0a6a1f1dSLionel Sambuc
38*0a6a1f1dSLionel Sambuc // Prune trailing "/" or "./"
39*0a6a1f1dSLionel Sambuc while (1) {
40*0a6a1f1dSLionel Sambuc StringRef last = path::filename(seg);
41*0a6a1f1dSLionel Sambuc if (last != ".")
42*0a6a1f1dSLionel Sambuc break;
43*0a6a1f1dSLionel Sambuc seg = path::parent_path(seg);
44*0a6a1f1dSLionel Sambuc }
45*0a6a1f1dSLionel Sambuc
46*0a6a1f1dSLionel Sambuc if (seg.empty() || seg == "/") {
47*0a6a1f1dSLionel Sambuc Segment = "";
48*0a6a1f1dSLionel Sambuc return;
49*0a6a1f1dSLionel Sambuc }
50*0a6a1f1dSLionel Sambuc
51*0a6a1f1dSLionel Sambuc // Add leading '/'
52*0a6a1f1dSLionel Sambuc if (seg.front() != '/') {
53*0a6a1f1dSLionel Sambuc Segment = "/" + seg.str();
54*0a6a1f1dSLionel Sambuc } else {
55*0a6a1f1dSLionel Sambuc Segment = seg;
56*0a6a1f1dSLionel Sambuc }
57*0a6a1f1dSLionel Sambuc }
58*0a6a1f1dSLionel Sambuc
Multilib(StringRef GCCSuffix,StringRef OSSuffix,StringRef IncludeSuffix)59*0a6a1f1dSLionel Sambuc Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
60*0a6a1f1dSLionel Sambuc StringRef IncludeSuffix)
61*0a6a1f1dSLionel Sambuc : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {
62*0a6a1f1dSLionel Sambuc normalizePathSegment(this->GCCSuffix);
63*0a6a1f1dSLionel Sambuc normalizePathSegment(this->OSSuffix);
64*0a6a1f1dSLionel Sambuc normalizePathSegment(this->IncludeSuffix);
65*0a6a1f1dSLionel Sambuc }
66*0a6a1f1dSLionel Sambuc
gccSuffix(StringRef S)67*0a6a1f1dSLionel Sambuc Multilib &Multilib::gccSuffix(StringRef S) {
68*0a6a1f1dSLionel Sambuc GCCSuffix = S;
69*0a6a1f1dSLionel Sambuc normalizePathSegment(GCCSuffix);
70*0a6a1f1dSLionel Sambuc return *this;
71*0a6a1f1dSLionel Sambuc }
72*0a6a1f1dSLionel Sambuc
osSuffix(StringRef S)73*0a6a1f1dSLionel Sambuc Multilib &Multilib::osSuffix(StringRef S) {
74*0a6a1f1dSLionel Sambuc OSSuffix = S;
75*0a6a1f1dSLionel Sambuc normalizePathSegment(OSSuffix);
76*0a6a1f1dSLionel Sambuc return *this;
77*0a6a1f1dSLionel Sambuc }
78*0a6a1f1dSLionel Sambuc
includeSuffix(StringRef S)79*0a6a1f1dSLionel Sambuc Multilib &Multilib::includeSuffix(StringRef S) {
80*0a6a1f1dSLionel Sambuc IncludeSuffix = S;
81*0a6a1f1dSLionel Sambuc normalizePathSegment(IncludeSuffix);
82*0a6a1f1dSLionel Sambuc return *this;
83*0a6a1f1dSLionel Sambuc }
84*0a6a1f1dSLionel Sambuc
print(raw_ostream & OS) const85*0a6a1f1dSLionel Sambuc void Multilib::print(raw_ostream &OS) const {
86*0a6a1f1dSLionel Sambuc assert(GCCSuffix.empty() || (StringRef(GCCSuffix).front() == '/'));
87*0a6a1f1dSLionel Sambuc if (GCCSuffix.empty())
88*0a6a1f1dSLionel Sambuc OS << ".";
89*0a6a1f1dSLionel Sambuc else {
90*0a6a1f1dSLionel Sambuc OS << StringRef(GCCSuffix).drop_front();
91*0a6a1f1dSLionel Sambuc }
92*0a6a1f1dSLionel Sambuc OS << ";";
93*0a6a1f1dSLionel Sambuc for (StringRef Flag : Flags) {
94*0a6a1f1dSLionel Sambuc if (Flag.front() == '+')
95*0a6a1f1dSLionel Sambuc OS << "@" << Flag.substr(1);
96*0a6a1f1dSLionel Sambuc }
97*0a6a1f1dSLionel Sambuc }
98*0a6a1f1dSLionel Sambuc
isValid() const99*0a6a1f1dSLionel Sambuc bool Multilib::isValid() const {
100*0a6a1f1dSLionel Sambuc llvm::StringMap<int> FlagSet;
101*0a6a1f1dSLionel Sambuc for (unsigned I = 0, N = Flags.size(); I != N; ++I) {
102*0a6a1f1dSLionel Sambuc StringRef Flag(Flags[I]);
103*0a6a1f1dSLionel Sambuc llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
104*0a6a1f1dSLionel Sambuc
105*0a6a1f1dSLionel Sambuc assert(StringRef(Flag).front() == '+' || StringRef(Flag).front() == '-');
106*0a6a1f1dSLionel Sambuc
107*0a6a1f1dSLionel Sambuc if (SI == FlagSet.end())
108*0a6a1f1dSLionel Sambuc FlagSet[Flag.substr(1)] = I;
109*0a6a1f1dSLionel Sambuc else if (Flags[I] != Flags[SI->getValue()])
110*0a6a1f1dSLionel Sambuc return false;
111*0a6a1f1dSLionel Sambuc }
112*0a6a1f1dSLionel Sambuc return true;
113*0a6a1f1dSLionel Sambuc }
114*0a6a1f1dSLionel Sambuc
operator ==(const Multilib & Other) const115*0a6a1f1dSLionel Sambuc bool Multilib::operator==(const Multilib &Other) const {
116*0a6a1f1dSLionel Sambuc // Check whether the flags sets match
117*0a6a1f1dSLionel Sambuc // allowing for the match to be order invariant
118*0a6a1f1dSLionel Sambuc llvm::StringSet<> MyFlags;
119*0a6a1f1dSLionel Sambuc for (const auto &Flag : Flags)
120*0a6a1f1dSLionel Sambuc MyFlags.insert(Flag);
121*0a6a1f1dSLionel Sambuc
122*0a6a1f1dSLionel Sambuc for (const auto &Flag : Other.Flags)
123*0a6a1f1dSLionel Sambuc if (MyFlags.find(Flag) == MyFlags.end())
124*0a6a1f1dSLionel Sambuc return false;
125*0a6a1f1dSLionel Sambuc
126*0a6a1f1dSLionel Sambuc if (osSuffix() != Other.osSuffix())
127*0a6a1f1dSLionel Sambuc return false;
128*0a6a1f1dSLionel Sambuc
129*0a6a1f1dSLionel Sambuc if (gccSuffix() != Other.gccSuffix())
130*0a6a1f1dSLionel Sambuc return false;
131*0a6a1f1dSLionel Sambuc
132*0a6a1f1dSLionel Sambuc if (includeSuffix() != Other.includeSuffix())
133*0a6a1f1dSLionel Sambuc return false;
134*0a6a1f1dSLionel Sambuc
135*0a6a1f1dSLionel Sambuc return true;
136*0a6a1f1dSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc
operator <<(raw_ostream & OS,const Multilib & M)138*0a6a1f1dSLionel Sambuc raw_ostream &clang::driver::operator<<(raw_ostream &OS, const Multilib &M) {
139*0a6a1f1dSLionel Sambuc M.print(OS);
140*0a6a1f1dSLionel Sambuc return OS;
141*0a6a1f1dSLionel Sambuc }
142*0a6a1f1dSLionel Sambuc
Maybe(const Multilib & M)143*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::Maybe(const Multilib &M) {
144*0a6a1f1dSLionel Sambuc Multilib Opposite;
145*0a6a1f1dSLionel Sambuc // Negate any '+' flags
146*0a6a1f1dSLionel Sambuc for (StringRef Flag : M.flags()) {
147*0a6a1f1dSLionel Sambuc if (Flag.front() == '+')
148*0a6a1f1dSLionel Sambuc Opposite.flags().push_back(("-" + Flag.substr(1)).str());
149*0a6a1f1dSLionel Sambuc }
150*0a6a1f1dSLionel Sambuc return Either(M, Opposite);
151*0a6a1f1dSLionel Sambuc }
152*0a6a1f1dSLionel Sambuc
Either(const Multilib & M1,const Multilib & M2)153*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2) {
154*0a6a1f1dSLionel Sambuc std::vector<Multilib> Ms;
155*0a6a1f1dSLionel Sambuc Ms.push_back(M1);
156*0a6a1f1dSLionel Sambuc Ms.push_back(M2);
157*0a6a1f1dSLionel Sambuc return Either(Ms);
158*0a6a1f1dSLionel Sambuc }
159*0a6a1f1dSLionel Sambuc
Either(const Multilib & M1,const Multilib & M2,const Multilib & M3)160*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2,
161*0a6a1f1dSLionel Sambuc const Multilib &M3) {
162*0a6a1f1dSLionel Sambuc std::vector<Multilib> Ms;
163*0a6a1f1dSLionel Sambuc Ms.push_back(M1);
164*0a6a1f1dSLionel Sambuc Ms.push_back(M2);
165*0a6a1f1dSLionel Sambuc Ms.push_back(M3);
166*0a6a1f1dSLionel Sambuc return Either(Ms);
167*0a6a1f1dSLionel Sambuc }
168*0a6a1f1dSLionel Sambuc
Either(const Multilib & M1,const Multilib & M2,const Multilib & M3,const Multilib & M4)169*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2,
170*0a6a1f1dSLionel Sambuc const Multilib &M3, const Multilib &M4) {
171*0a6a1f1dSLionel Sambuc std::vector<Multilib> Ms;
172*0a6a1f1dSLionel Sambuc Ms.push_back(M1);
173*0a6a1f1dSLionel Sambuc Ms.push_back(M2);
174*0a6a1f1dSLionel Sambuc Ms.push_back(M3);
175*0a6a1f1dSLionel Sambuc Ms.push_back(M4);
176*0a6a1f1dSLionel Sambuc return Either(Ms);
177*0a6a1f1dSLionel Sambuc }
178*0a6a1f1dSLionel Sambuc
Either(const Multilib & M1,const Multilib & M2,const Multilib & M3,const Multilib & M4,const Multilib & M5)179*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::Either(const Multilib &M1, const Multilib &M2,
180*0a6a1f1dSLionel Sambuc const Multilib &M3, const Multilib &M4,
181*0a6a1f1dSLionel Sambuc const Multilib &M5) {
182*0a6a1f1dSLionel Sambuc std::vector<Multilib> Ms;
183*0a6a1f1dSLionel Sambuc Ms.push_back(M1);
184*0a6a1f1dSLionel Sambuc Ms.push_back(M2);
185*0a6a1f1dSLionel Sambuc Ms.push_back(M3);
186*0a6a1f1dSLionel Sambuc Ms.push_back(M4);
187*0a6a1f1dSLionel Sambuc Ms.push_back(M5);
188*0a6a1f1dSLionel Sambuc return Either(Ms);
189*0a6a1f1dSLionel Sambuc }
190*0a6a1f1dSLionel Sambuc
compose(const Multilib & Base,const Multilib & New)191*0a6a1f1dSLionel Sambuc static Multilib compose(const Multilib &Base, const Multilib &New) {
192*0a6a1f1dSLionel Sambuc SmallString<128> GCCSuffix;
193*0a6a1f1dSLionel Sambuc llvm::sys::path::append(GCCSuffix, "/", Base.gccSuffix(), New.gccSuffix());
194*0a6a1f1dSLionel Sambuc SmallString<128> OSSuffix;
195*0a6a1f1dSLionel Sambuc llvm::sys::path::append(OSSuffix, "/", Base.osSuffix(), New.osSuffix());
196*0a6a1f1dSLionel Sambuc SmallString<128> IncludeSuffix;
197*0a6a1f1dSLionel Sambuc llvm::sys::path::append(IncludeSuffix, "/", Base.includeSuffix(),
198*0a6a1f1dSLionel Sambuc New.includeSuffix());
199*0a6a1f1dSLionel Sambuc
200*0a6a1f1dSLionel Sambuc Multilib Composed(GCCSuffix.str(), OSSuffix.str(), IncludeSuffix.str());
201*0a6a1f1dSLionel Sambuc
202*0a6a1f1dSLionel Sambuc Multilib::flags_list &Flags = Composed.flags();
203*0a6a1f1dSLionel Sambuc
204*0a6a1f1dSLionel Sambuc Flags.insert(Flags.end(), Base.flags().begin(), Base.flags().end());
205*0a6a1f1dSLionel Sambuc Flags.insert(Flags.end(), New.flags().begin(), New.flags().end());
206*0a6a1f1dSLionel Sambuc
207*0a6a1f1dSLionel Sambuc return Composed;
208*0a6a1f1dSLionel Sambuc }
209*0a6a1f1dSLionel Sambuc
210*0a6a1f1dSLionel Sambuc MultilibSet &
Either(const std::vector<Multilib> & MultilibSegments)211*0a6a1f1dSLionel Sambuc MultilibSet::Either(const std::vector<Multilib> &MultilibSegments) {
212*0a6a1f1dSLionel Sambuc multilib_list Composed;
213*0a6a1f1dSLionel Sambuc
214*0a6a1f1dSLionel Sambuc if (Multilibs.empty())
215*0a6a1f1dSLionel Sambuc Multilibs.insert(Multilibs.end(), MultilibSegments.begin(),
216*0a6a1f1dSLionel Sambuc MultilibSegments.end());
217*0a6a1f1dSLionel Sambuc else {
218*0a6a1f1dSLionel Sambuc for (const Multilib &New : MultilibSegments) {
219*0a6a1f1dSLionel Sambuc for (const Multilib &Base : *this) {
220*0a6a1f1dSLionel Sambuc Multilib MO = compose(Base, New);
221*0a6a1f1dSLionel Sambuc if (MO.isValid())
222*0a6a1f1dSLionel Sambuc Composed.push_back(MO);
223*0a6a1f1dSLionel Sambuc }
224*0a6a1f1dSLionel Sambuc }
225*0a6a1f1dSLionel Sambuc
226*0a6a1f1dSLionel Sambuc Multilibs = Composed;
227*0a6a1f1dSLionel Sambuc }
228*0a6a1f1dSLionel Sambuc
229*0a6a1f1dSLionel Sambuc return *this;
230*0a6a1f1dSLionel Sambuc }
231*0a6a1f1dSLionel Sambuc
FilterOut(const MultilibSet::FilterCallback & F)232*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::FilterOut(const MultilibSet::FilterCallback &F) {
233*0a6a1f1dSLionel Sambuc filterInPlace(F, Multilibs);
234*0a6a1f1dSLionel Sambuc return *this;
235*0a6a1f1dSLionel Sambuc }
236*0a6a1f1dSLionel Sambuc
FilterOut(std::string Regex)237*0a6a1f1dSLionel Sambuc MultilibSet &MultilibSet::FilterOut(std::string Regex) {
238*0a6a1f1dSLionel Sambuc class REFilter : public MultilibSet::FilterCallback {
239*0a6a1f1dSLionel Sambuc mutable llvm::Regex R;
240*0a6a1f1dSLionel Sambuc
241*0a6a1f1dSLionel Sambuc public:
242*0a6a1f1dSLionel Sambuc REFilter(std::string Regex) : R(Regex) {}
243*0a6a1f1dSLionel Sambuc bool operator()(const Multilib &M) const override {
244*0a6a1f1dSLionel Sambuc std::string Error;
245*0a6a1f1dSLionel Sambuc if (!R.isValid(Error)) {
246*0a6a1f1dSLionel Sambuc llvm::errs() << Error;
247*0a6a1f1dSLionel Sambuc assert(false);
248*0a6a1f1dSLionel Sambuc return false;
249*0a6a1f1dSLionel Sambuc }
250*0a6a1f1dSLionel Sambuc return R.match(M.gccSuffix());
251*0a6a1f1dSLionel Sambuc }
252*0a6a1f1dSLionel Sambuc };
253*0a6a1f1dSLionel Sambuc
254*0a6a1f1dSLionel Sambuc REFilter REF(Regex);
255*0a6a1f1dSLionel Sambuc filterInPlace(REF, Multilibs);
256*0a6a1f1dSLionel Sambuc return *this;
257*0a6a1f1dSLionel Sambuc }
258*0a6a1f1dSLionel Sambuc
push_back(const Multilib & M)259*0a6a1f1dSLionel Sambuc void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); }
260*0a6a1f1dSLionel Sambuc
combineWith(const MultilibSet & Other)261*0a6a1f1dSLionel Sambuc void MultilibSet::combineWith(const MultilibSet &Other) {
262*0a6a1f1dSLionel Sambuc Multilibs.insert(Multilibs.end(), Other.begin(), Other.end());
263*0a6a1f1dSLionel Sambuc }
264*0a6a1f1dSLionel Sambuc
select(const Multilib::flags_list & Flags,Multilib & M) const265*0a6a1f1dSLionel Sambuc bool MultilibSet::select(const Multilib::flags_list &Flags, Multilib &M) const {
266*0a6a1f1dSLionel Sambuc class FilterFlagsMismatch : public MultilibSet::FilterCallback {
267*0a6a1f1dSLionel Sambuc llvm::StringMap<bool> FlagSet;
268*0a6a1f1dSLionel Sambuc
269*0a6a1f1dSLionel Sambuc public:
270*0a6a1f1dSLionel Sambuc FilterFlagsMismatch(const std::vector<std::string> &Flags) {
271*0a6a1f1dSLionel Sambuc // Stuff all of the flags into the FlagSet such that a true mappend
272*0a6a1f1dSLionel Sambuc // indicates the flag was enabled, and a false mappend indicates the
273*0a6a1f1dSLionel Sambuc // flag was disabled
274*0a6a1f1dSLionel Sambuc for (StringRef Flag : Flags)
275*0a6a1f1dSLionel Sambuc FlagSet[Flag.substr(1)] = isFlagEnabled(Flag);
276*0a6a1f1dSLionel Sambuc }
277*0a6a1f1dSLionel Sambuc bool operator()(const Multilib &M) const override {
278*0a6a1f1dSLionel Sambuc for (StringRef Flag : M.flags()) {
279*0a6a1f1dSLionel Sambuc llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
280*0a6a1f1dSLionel Sambuc if (SI != FlagSet.end())
281*0a6a1f1dSLionel Sambuc if (SI->getValue() != isFlagEnabled(Flag))
282*0a6a1f1dSLionel Sambuc return true;
283*0a6a1f1dSLionel Sambuc }
284*0a6a1f1dSLionel Sambuc return false;
285*0a6a1f1dSLionel Sambuc }
286*0a6a1f1dSLionel Sambuc private:
287*0a6a1f1dSLionel Sambuc bool isFlagEnabled(StringRef Flag) const {
288*0a6a1f1dSLionel Sambuc char Indicator = Flag.front();
289*0a6a1f1dSLionel Sambuc assert(Indicator == '+' || Indicator == '-');
290*0a6a1f1dSLionel Sambuc return Indicator == '+';
291*0a6a1f1dSLionel Sambuc }
292*0a6a1f1dSLionel Sambuc };
293*0a6a1f1dSLionel Sambuc
294*0a6a1f1dSLionel Sambuc FilterFlagsMismatch FlagsMismatch(Flags);
295*0a6a1f1dSLionel Sambuc
296*0a6a1f1dSLionel Sambuc multilib_list Filtered = filterCopy(FlagsMismatch, Multilibs);
297*0a6a1f1dSLionel Sambuc
298*0a6a1f1dSLionel Sambuc if (Filtered.size() == 0) {
299*0a6a1f1dSLionel Sambuc return false;
300*0a6a1f1dSLionel Sambuc } else if (Filtered.size() == 1) {
301*0a6a1f1dSLionel Sambuc M = Filtered[0];
302*0a6a1f1dSLionel Sambuc return true;
303*0a6a1f1dSLionel Sambuc }
304*0a6a1f1dSLionel Sambuc
305*0a6a1f1dSLionel Sambuc // TODO: pick the "best" multlib when more than one is suitable
306*0a6a1f1dSLionel Sambuc assert(false);
307*0a6a1f1dSLionel Sambuc
308*0a6a1f1dSLionel Sambuc return false;
309*0a6a1f1dSLionel Sambuc }
310*0a6a1f1dSLionel Sambuc
print(raw_ostream & OS) const311*0a6a1f1dSLionel Sambuc void MultilibSet::print(raw_ostream &OS) const {
312*0a6a1f1dSLionel Sambuc for (const Multilib &M : *this)
313*0a6a1f1dSLionel Sambuc OS << M << "\n";
314*0a6a1f1dSLionel Sambuc }
315*0a6a1f1dSLionel Sambuc
316*0a6a1f1dSLionel Sambuc MultilibSet::multilib_list
filterCopy(const MultilibSet::FilterCallback & F,const multilib_list & Ms)317*0a6a1f1dSLionel Sambuc MultilibSet::filterCopy(const MultilibSet::FilterCallback &F,
318*0a6a1f1dSLionel Sambuc const multilib_list &Ms) {
319*0a6a1f1dSLionel Sambuc multilib_list Copy(Ms);
320*0a6a1f1dSLionel Sambuc filterInPlace(F, Copy);
321*0a6a1f1dSLionel Sambuc return Copy;
322*0a6a1f1dSLionel Sambuc }
323*0a6a1f1dSLionel Sambuc
filterInPlace(const MultilibSet::FilterCallback & F,multilib_list & Ms)324*0a6a1f1dSLionel Sambuc void MultilibSet::filterInPlace(const MultilibSet::FilterCallback &F,
325*0a6a1f1dSLionel Sambuc multilib_list &Ms) {
326*0a6a1f1dSLionel Sambuc Ms.erase(std::remove_if(Ms.begin(), Ms.end(),
327*0a6a1f1dSLionel Sambuc [&F](const Multilib &M) { return F(M); }),
328*0a6a1f1dSLionel Sambuc Ms.end());
329*0a6a1f1dSLionel Sambuc }
330*0a6a1f1dSLionel Sambuc
operator <<(raw_ostream & OS,const MultilibSet & MS)331*0a6a1f1dSLionel Sambuc raw_ostream &clang::driver::operator<<(raw_ostream &OS, const MultilibSet &MS) {
332*0a6a1f1dSLionel Sambuc MS.print(OS);
333*0a6a1f1dSLionel Sambuc return OS;
334*0a6a1f1dSLionel Sambuc }
335