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 LLVM_CLANG_DRIVER_MULTILIB_H
11 #define LLVM_CLANG_DRIVER_MULTILIB_H
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/Option/Option.h"
23 /// This corresponds to a single GCC Multilib, or a segment of one controlled
24 /// by a command line flag
27 typedef std::vector<std::string> flags_list;
30 std::string GCCSuffix;
32 std::string IncludeSuffix;
36 Multilib(StringRef GCCSuffix = "", StringRef OSSuffix = "",
37 StringRef IncludeSuffix = "");
39 /// \brief Get the detected GCC installation path suffix for the multi-arch
40 /// target variant. Always starts with a '/', unless empty
41 const std::string &gccSuffix() const {
42 assert(GCCSuffix.empty() ||
43 (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
46 /// Set the GCC installation path suffix.
47 Multilib &gccSuffix(StringRef S);
49 /// \brief Get the detected os path suffix for the multi-arch
50 /// target variant. Always starts with a '/', unless empty
51 const std::string &osSuffix() const {
52 assert(OSSuffix.empty() ||
53 (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
56 /// Set the os path suffix.
57 Multilib &osSuffix(StringRef S);
59 /// \brief Get the include directory suffix. Always starts with a '/', unless
61 const std::string &includeSuffix() const {
62 assert(IncludeSuffix.empty() ||
63 (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1));
66 /// Set the include directory suffix
67 Multilib &includeSuffix(StringRef S);
69 /// \brief Get the flags that indicate or contraindicate this multilib's use
70 /// All elements begin with either '+' or '-'
71 const flags_list &flags() const { return Flags; }
72 flags_list &flags() { return Flags; }
74 /// Add a flag to the flags list
75 /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
76 /// and replaced with either:
77 /// '-' which contraindicates using this multilib with that flag
79 /// '+' which promotes using this multilib in the presence of that flag
80 /// otherwise '-print-multi-lib' will not emit them correctly.
81 Multilib &flag(StringRef F) {
82 assert(F.front() == '+' || F.front() == '-');
87 LLVM_DUMP_METHOD void dump() const;
88 /// \brief print summary of the Multilib
89 void print(raw_ostream &OS) const;
91 /// Check whether any of the 'against' flags contradict the 'for' flags.
94 /// Check whether the default is selected
95 bool isDefault() const
96 { return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty(); }
98 bool operator==(const Multilib &Other) const;
101 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
105 typedef std::vector<Multilib> multilib_list;
106 typedef multilib_list::iterator iterator;
107 typedef multilib_list::const_iterator const_iterator;
109 typedef std::function<std::vector<std::string>(const Multilib &M)>
112 typedef llvm::function_ref<bool(const Multilib &)> FilterCallback;
115 multilib_list Multilibs;
116 IncludeDirsFunc IncludeCallback;
117 IncludeDirsFunc FilePathsCallback;
122 /// Add an optional Multilib segment
123 MultilibSet &Maybe(const Multilib &M);
125 /// Add a set of mutually incompatible Multilib segments
126 MultilibSet &Either(const Multilib &M1, const Multilib &M2);
127 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
129 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
130 const Multilib &M3, const Multilib &M4);
131 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
132 const Multilib &M3, const Multilib &M4,
134 MultilibSet &Either(ArrayRef<Multilib> Ms);
136 /// Filter out some subset of the Multilibs using a user defined callback
137 MultilibSet &FilterOut(FilterCallback F);
138 /// Filter out those Multilibs whose gccSuffix matches the given expression
139 MultilibSet &FilterOut(const char *Regex);
141 /// Add a completed Multilib to the set
142 void push_back(const Multilib &M);
144 /// Union this set of multilibs with another
145 void combineWith(const MultilibSet &MS);
147 /// Remove all of thie multilibs from the set
148 void clear() { Multilibs.clear(); }
150 iterator begin() { return Multilibs.begin(); }
151 const_iterator begin() const { return Multilibs.begin(); }
153 iterator end() { return Multilibs.end(); }
154 const_iterator end() const { return Multilibs.end(); }
156 /// Pick the best multilib in the set, \returns false if none are compatible
157 bool select(const Multilib::flags_list &Flags, Multilib &M) const;
159 unsigned size() const { return Multilibs.size(); }
161 LLVM_DUMP_METHOD void dump() const;
162 void print(raw_ostream &OS) const;
164 MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
165 IncludeCallback = std::move(F);
168 const IncludeDirsFunc &includeDirsCallback() const { return IncludeCallback; }
170 MultilibSet &setFilePathsCallback(IncludeDirsFunc F) {
171 FilePathsCallback = std::move(F);
174 const IncludeDirsFunc &filePathsCallback() const { return FilePathsCallback; }
177 /// Apply the filter to Multilibs and return the subset that remains
178 static multilib_list filterCopy(FilterCallback F, const multilib_list &Ms);
180 /// Apply the filter to the multilib_list, removing those that don't match
181 static void filterInPlace(FilterCallback F, multilib_list &Ms);
184 raw_ostream &operator<<(raw_ostream &OS, const MultilibSet &MS);