1 //===--- Multilib.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_LIB_DRIVER_MULTILIB_H_
11 #define CLANG_LIB_DRIVER_MULTILIB_H_
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/Option/Option.h"
24 /// This corresponds to a single GCC Multilib, or a segment of one controlled
25 /// by a command line flag
28 typedef std::vector<std::string> flags_list;
31 std::string GCCSuffix;
33 std::string IncludeSuffix;
37 Multilib(StringRef GCCSuffix = "", StringRef OSSuffix = "",
38 StringRef IncludeSuffix = "");
40 /// \brief Get the detected GCC installation path suffix for the multi-arch
41 /// target variant. Always starts with a '/', unless empty
42 const std::string &gccSuffix() const {
43 assert(GCCSuffix.empty() ||
44 (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
47 /// Set the GCC installation path suffix.
48 Multilib &gccSuffix(StringRef S);
50 /// \brief Get the detected os path suffix for the multi-arch
51 /// target variant. Always starts with a '/', unless empty
52 const std::string &osSuffix() const {
53 assert(OSSuffix.empty() ||
54 (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
57 /// Set the os path suffix.
58 Multilib &osSuffix(StringRef S);
60 /// \brief Get the include directory suffix. Always starts with a '/', unless
62 const std::string &includeSuffix() const {
63 assert(IncludeSuffix.empty() ||
64 (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1));
67 /// Set the include directory suffix
68 Multilib &includeSuffix(StringRef S);
70 /// \brief Get the flags that indicate or contraindicate this multilib's use
71 /// All elements begin with either '+' or '-'
72 const flags_list &flags() const { return Flags; }
73 flags_list &flags() { return Flags; }
74 /// Add a flag to the flags list
75 Multilib &flag(StringRef F) {
76 assert(F.front() == '+' || F.front() == '-');
81 /// \brief print summary of the Multilib
82 void print(raw_ostream &OS) const;
84 /// Check whether any of the 'against' flags contradict the 'for' flags.
87 /// Check whether the default is selected
88 bool isDefault() const
89 { return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); }
91 bool operator==(const Multilib &Other) const;
94 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
98 typedef std::vector<Multilib> multilib_list;
99 typedef multilib_list::iterator iterator;
100 typedef multilib_list::const_iterator const_iterator;
102 typedef std::function<std::vector<std::string>(
103 StringRef InstallDir, StringRef Triple, const Multilib &M)>
106 struct FilterCallback {
107 virtual ~FilterCallback() {};
108 /// \return true iff the filter should remove the Multilib from the set
109 virtual bool operator()(const Multilib &M) const = 0;
113 multilib_list Multilibs;
114 IncludeDirsFunc IncludeCallback;
119 /// Add an optional Multilib segment
120 MultilibSet &Maybe(const Multilib &M);
122 /// Add a set of mutually incompatible Multilib segments
123 MultilibSet &Either(const Multilib &M1, const Multilib &M2);
124 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
126 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
127 const Multilib &M3, const Multilib &M4);
128 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
129 const Multilib &M3, const Multilib &M4,
131 MultilibSet &Either(const std::vector<Multilib> &Ms);
133 /// Filter out some subset of the Multilibs using a user defined callback
134 MultilibSet &FilterOut(const FilterCallback &F);
135 /// Filter out those Multilibs whose gccSuffix matches the given expression
136 MultilibSet &FilterOut(std::string Regex);
138 /// Add a completed Multilib to the set
139 void push_back(const Multilib &M);
141 /// Union this set of multilibs with another
142 void combineWith(const MultilibSet &MS);
144 /// Remove all of thie multilibs from the set
145 void clear() { Multilibs.clear(); }
147 iterator begin() { return Multilibs.begin(); }
148 const_iterator begin() const { return Multilibs.begin(); }
150 iterator end() { return Multilibs.end(); }
151 const_iterator end() const { return Multilibs.end(); }
153 /// Pick the best multilib in the set, \returns false if none are compatible
154 bool select(const Multilib::flags_list &Flags, Multilib &M) const;
156 unsigned size() const { return Multilibs.size(); }
158 void print(raw_ostream &OS) const;
160 MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
164 IncludeDirsFunc includeDirsCallback() const { return IncludeCallback; }
167 /// Apply the filter to Multilibs and return the subset that remains
168 static multilib_list filterCopy(const FilterCallback &F,
169 const multilib_list &Ms);
171 /// Apply the filter to the multilib_list, removing those that don't match
172 static void filterInPlace(const FilterCallback &F, multilib_list &Ms);
175 raw_ostream &operator<<(raw_ostream &OS, const MultilibSet &MS);