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/ADT/Triple.h"
16 #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 typedef llvm::function_ref<bool(const Multilib &)> FilterCallback;
109 multilib_list Multilibs;
110 IncludeDirsFunc IncludeCallback;
115 /// Add an optional Multilib segment
116 MultilibSet &Maybe(const Multilib &M);
118 /// Add a set of mutually incompatible Multilib segments
119 MultilibSet &Either(const Multilib &M1, const Multilib &M2);
120 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
122 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
123 const Multilib &M3, const Multilib &M4);
124 MultilibSet &Either(const Multilib &M1, const Multilib &M2,
125 const Multilib &M3, const Multilib &M4,
127 MultilibSet &Either(ArrayRef<Multilib> Ms);
129 /// Filter out some subset of the Multilibs using a user defined callback
130 MultilibSet &FilterOut(FilterCallback F);
131 /// Filter out those Multilibs whose gccSuffix matches the given expression
132 MultilibSet &FilterOut(const char *Regex);
134 /// Add a completed Multilib to the set
135 void push_back(const Multilib &M);
137 /// Union this set of multilibs with another
138 void combineWith(const MultilibSet &MS);
140 /// Remove all of thie multilibs from the set
141 void clear() { Multilibs.clear(); }
143 iterator begin() { return Multilibs.begin(); }
144 const_iterator begin() const { return Multilibs.begin(); }
146 iterator end() { return Multilibs.end(); }
147 const_iterator end() const { return Multilibs.end(); }
149 /// Pick the best multilib in the set, \returns false if none are compatible
150 bool select(const Multilib::flags_list &Flags, Multilib &M) const;
152 unsigned size() const { return Multilibs.size(); }
154 void print(raw_ostream &OS) const;
156 MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
157 IncludeCallback = std::move(F);
160 const IncludeDirsFunc &includeDirsCallback() const { return IncludeCallback; }
163 /// Apply the filter to Multilibs and return the subset that remains
164 static multilib_list filterCopy(FilterCallback F, const multilib_list &Ms);
166 /// Apply the filter to the multilib_list, removing those that don't match
167 static void filterInPlace(FilterCallback F, multilib_list &Ms);
170 raw_ostream &operator<<(raw_ostream &OS, const MultilibSet &MS);