Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:52

0001 //===- MultilibBuilder.h
0002 //-----------------------------------------------*- C++ -*-===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef LLVM_CLANG_DRIVER_MULTILIBBUILDER_H
0011 #define LLVM_CLANG_DRIVER_MULTILIBBUILDER_H
0012 
0013 #include "clang/Driver/Multilib.h"
0014 
0015 namespace clang {
0016 namespace driver {
0017 
0018 /// This corresponds to a single GCC multilib, or a segment of one controlled
0019 /// by a command line flag. This class can be used to create a Multilib, and
0020 /// contains helper functions to mutate it before creating a Multilib instance
0021 /// with makeMultilib().
0022 class MultilibBuilder {
0023 public:
0024   using flags_list = std::vector<std::string>;
0025 
0026 private:
0027   std::string GCCSuffix;
0028   std::string OSSuffix;
0029   std::string IncludeSuffix;
0030   flags_list Flags;
0031 
0032 public:
0033   MultilibBuilder(StringRef GCCSuffix, StringRef OSSuffix,
0034                   StringRef IncludeSuffix);
0035 
0036   /// Initializes GCCSuffix, OSSuffix & IncludeSuffix to the same value.
0037   MultilibBuilder(StringRef Suffix = {});
0038 
0039   /// Get the detected GCC installation path suffix for the multi-arch
0040   /// target variant. Always starts with a '/', unless empty
0041   const std::string &gccSuffix() const {
0042     assert(GCCSuffix.empty() ||
0043            (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
0044     return GCCSuffix;
0045   }
0046 
0047   /// Set the GCC installation path suffix.
0048   MultilibBuilder &gccSuffix(StringRef S);
0049 
0050   /// Get the detected os path suffix for the multi-arch
0051   /// target variant. Always starts with a '/', unless empty
0052   const std::string &osSuffix() const {
0053     assert(OSSuffix.empty() ||
0054            (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
0055     return OSSuffix;
0056   }
0057 
0058   /// Set the os path suffix.
0059   MultilibBuilder &osSuffix(StringRef S);
0060 
0061   /// Get the include directory suffix. Always starts with a '/', unless
0062   /// empty
0063   const std::string &includeSuffix() const {
0064     assert(IncludeSuffix.empty() || (StringRef(IncludeSuffix).front() == '/' &&
0065                                      IncludeSuffix.size() > 1));
0066     return IncludeSuffix;
0067   }
0068 
0069   /// Set the include directory suffix
0070   MultilibBuilder &includeSuffix(StringRef S);
0071 
0072   /// Get the flags that indicate or contraindicate this multilib's use
0073   /// All elements begin with either '-' or '!'
0074   const flags_list &flags() const { return Flags; }
0075   flags_list &flags() { return Flags; }
0076 
0077   /// Add a flag to the flags list
0078   /// \p Flag must be a flag accepted by the driver.
0079   /// \p Disallow defines whether the flag is negated and therefore disallowed.
0080   MultilibBuilder &flag(StringRef Flag, bool Disallow = false);
0081 
0082   Multilib makeMultilib() const;
0083 
0084   /// Check whether any of the 'against' flags contradict the 'for' flags.
0085   bool isValid() const;
0086 
0087   /// Check whether the default is selected
0088   bool isDefault() const {
0089     return GCCSuffix.empty() && OSSuffix.empty() && IncludeSuffix.empty();
0090   }
0091 };
0092 
0093 /// This class can be used to create a MultilibSet, and contains helper
0094 /// functions to add combinations of multilibs before creating a MultilibSet
0095 /// instance with makeMultilibSet().
0096 class MultilibSetBuilder {
0097 public:
0098   using multilib_list = std::vector<MultilibBuilder>;
0099 
0100   MultilibSetBuilder() = default;
0101 
0102   /// Add an optional Multilib segment
0103   MultilibSetBuilder &Maybe(const MultilibBuilder &M);
0104 
0105   /// Add a set of mutually incompatible Multilib segments
0106   MultilibSetBuilder &Either(const MultilibBuilder &M1,
0107                              const MultilibBuilder &M2);
0108   MultilibSetBuilder &Either(const MultilibBuilder &M1,
0109                              const MultilibBuilder &M2,
0110                              const MultilibBuilder &M3);
0111   MultilibSetBuilder &Either(const MultilibBuilder &M1,
0112                              const MultilibBuilder &M2,
0113                              const MultilibBuilder &M3,
0114                              const MultilibBuilder &M4);
0115   MultilibSetBuilder &Either(const MultilibBuilder &M1,
0116                              const MultilibBuilder &M2,
0117                              const MultilibBuilder &M3,
0118                              const MultilibBuilder &M4,
0119                              const MultilibBuilder &M5);
0120   MultilibSetBuilder &Either(ArrayRef<MultilibBuilder> Ms);
0121 
0122   /// Filter out those Multilibs whose gccSuffix matches the given expression
0123   MultilibSetBuilder &FilterOut(const char *Regex);
0124 
0125   MultilibSet makeMultilibSet() const;
0126 
0127 private:
0128   multilib_list Multilibs;
0129 };
0130 
0131 } // namespace driver
0132 } // namespace clang
0133 
0134 #endif // LLVM_CLANG_DRIVER_MULTILIBBUILDER_H