Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:38

0001 //===- llvm/TextAPI/Utils.h - TAPI Utils -----------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Helper functionality used for Darwin specific operations.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_TEXTAPI_UTILS_H
0014 #define LLVM_TEXTAPI_UTILS_H
0015 
0016 #include "llvm/ADT/Twine.h"
0017 #include "llvm/Support/Error.h"
0018 #include "llvm/Support/FileSystem.h"
0019 #include "llvm/Support/MemoryBuffer.h"
0020 #include "llvm/Support/Path.h"
0021 #include "llvm/Support/Regex.h"
0022 #include "llvm/TextAPI/Symbol.h"
0023 #include <map>
0024 
0025 #if !defined(PATH_MAX)
0026 #define PATH_MAX 1024
0027 #endif // !defined(PATH_MAX)
0028 
0029 #define MACCATALYST_PREFIX_PATH "/System/iOSSupport"
0030 #define DRIVERKIT_PREFIX_PATH "/System/DriverKit"
0031 
0032 namespace llvm::MachO {
0033 
0034 using PathSeq = std::vector<std::string>;
0035 using PathToPlatform = std::pair<std::string, std::optional<PlatformType>>;
0036 using PathToPlatformSeq = std::vector<PathToPlatform>;
0037 
0038 // Defines simple struct for storing symbolic links.
0039 struct SymLink {
0040   std::string SrcPath;
0041   std::string LinkContent;
0042 
0043   SymLink(std::string Path, std::string Link)
0044       : SrcPath(std::move(Path)), LinkContent(std::move(Link)) {}
0045 
0046   SymLink(StringRef Path, StringRef Link)
0047       : SrcPath(std::string(Path)), LinkContent(std::string(Link)) {}
0048 };
0049 
0050 /// Replace extension considering frameworks.
0051 ///
0052 /// \param Path Location of file.
0053 /// \param Extension File extension to update with.
0054 void replace_extension(SmallVectorImpl<char> &Path, const Twine &Extension);
0055 
0056 /// Determine whether to skip over symlink due to either too many symlink levels
0057 /// or is cyclic.
0058 ///
0059 /// \param Path Location to symlink.
0060 /// \param Result Holds whether to skip over Path.
0061 std::error_code shouldSkipSymLink(const Twine &Path, bool &Result);
0062 
0063 /// Turn absolute symlink into relative.
0064 ///
0065 /// \param From The symlink.
0066 /// \param To What the symlink points to.
0067 /// \param RelativePath Path location to update what the symlink points to.
0068 std::error_code make_relative(StringRef From, StringRef To,
0069                               SmallVectorImpl<char> &RelativePath);
0070 
0071 /// Determine if library is private by parsing file path.
0072 /// It does not touch the file system.
0073 ///
0074 /// \param Path File path for library.
0075 /// \param IsSymLink Whether path points to a symlink.
0076 bool isPrivateLibrary(StringRef Path, bool IsSymLink = false);
0077 
0078 /// Create a regex rule from provided glob string.
0079 /// \param Glob String that represents glob input.
0080 /// \return The equivalent regex rule.
0081 llvm::Expected<llvm::Regex> createRegexFromGlob(llvm::StringRef Glob);
0082 
0083 using AliasEntry = std::pair<std::string, EncodeKind>;
0084 using AliasMap = std::map<AliasEntry, AliasEntry>;
0085 
0086 /// Parse input list and capture symbols and their alias.
0087 ///
0088 /// \param Buffer Data contents of file for the alias list.
0089 /// \return Lookup table of alias to their base symbol.
0090 Expected<AliasMap> parseAliasList(std::unique_ptr<llvm::MemoryBuffer> &Buffer);
0091 
0092 /// Pickup active paths for a given platform.
0093 ///
0094 /// \param Paths File or search paths to pick up.
0095 /// \param Platform Platform to collect paths for.
0096 PathSeq getPathsForPlatform(const PathToPlatformSeq &Paths,
0097                             PlatformType Platform);
0098 
0099 } // namespace llvm::MachO
0100 #endif // LLVM_TEXTAPI_UTILS_H