26#ifndef LLVM_SUPPORT_FILESYSTEM_H
27#define LLVM_SUPPORT_FILESYSTEM_H
32#include "llvm/Config/llvm-config.h"
45#include <system_error>
109 return static_cast<perms>(
static_cast<unsigned short>(l) |
110 static_cast<unsigned short>(r));
113 return static_cast<perms>(
static_cast<unsigned short>(l) &
114 static_cast<unsigned short>(r));
126 return static_cast<perms>(
127 static_cast<unsigned short>(~static_cast<unsigned short>(x)));
135 #if defined(LLVM_ON_UNIX)
143 #elif defined (_WIN32)
159 #if defined(LLVM_ON_UNIX)
162 uid_t UID, gid_t GID, off_t
Size)
172 : LastAccessedTimeHigh(LastAccessTimeHigh),
173 LastAccessedTimeLow(LastAccessTimeLow),
174 LastWriteTimeHigh(LastWriteTimeHigh),
175 LastWriteTimeLow(LastWriteTimeLow), FileSizeHigh(FileSizeHigh),
198#if defined(LLVM_ON_UNIX)
212 return (
uint64_t(FileSizeHigh) << 32) + FileSizeLow;
225#if defined(LLVM_ON_UNIX)
227 nlink_t fs_st_nlinks = 0;
240 #if defined(LLVM_ON_UNIX)
244 uid_t UID, gid_t GID, off_t
Size)
247 fs_st_dev(Dev), fs_st_nlinks(Links), fs_st_ino(Ino) {}
248 #elif defined(_WIN32)
255 LastWriteTimeHigh, LastWriteTimeLow, FileSizeHigh,
257 NumLinks(LinkCount), VolumeSerialNumber(VolumeSerialNumber),
258 PathHash(PathHash) {}
311 bool IgnoreExisting =
true,
373 bool IgnoreNonExisting =
true);
381 bool IgnoreErrors =
true);
422 return std::error_code();
527 return !
is_local(Path, Result) && Result;
534 return !
is_local(FD, Result) && Result;
696 Result =
Status.getSize();
697 return std::error_code();
873 bool RemoveOnClose =
false;
990 unsigned Mode = 0666);
1071inline std::error_code
1094 unsigned Mode = 0666) {
1116 unsigned Mode = 0666) {
1136 unsigned Mode = 0666) {
1204 std::chrono::milliseconds
Timeout = std::chrono::milliseconds(0),
1268 return std::error_code();
1298 void *Mapping =
nullptr;
1306 Mapping = Copied.Mapping;
1308 FileHandle = Copied.FileHandle;
1329 moveFromImpl(Moved);
1338 uint64_t offset, std::error_code &ec);
1343 explicit operator bool()
const {
return Mapping; }
1386 bool FollowSymlinks =
true;
1393 : Path(Path.str()),
Type(
Type), FollowSymlinks(FollowSymlinks),
1402 const std::string &
path()
const {
return Path; }
1450 std::shared_ptr<detail::DirIterState> State;
1451 bool FollowSymlinks =
true;
1455 bool follow_symlinks =
true)
1456 : FollowSymlinks(follow_symlinks) {
1457 State = std::make_shared<detail::DirIterState>();
1460 *State, path.
toStringRef(path_storage), FollowSymlinks);
1464 bool follow_symlinks =
true)
1465 : FollowSymlinks(follow_symlinks) {
1466 State = std::make_shared<detail::DirIterState>();
1468 *State, de.
path(), FollowSymlinks);
1476 ec = directory_iterator_increment(*State);
1484 if (State ==
RHS.State)
1490 return State->CurrentEntry ==
RHS.State->CurrentEntry;
1494 return !(*
this ==
RHS);
1512 std::shared_ptr<detail::RecDirIterState> State;
1518 bool follow_symlinks =
true)
1519 : State(
std::make_shared<
detail::RecDirIterState>()),
1520 Follow(follow_symlinks) {
1530 if (State->HasNoPushRequest)
1531 State->HasNoPushRequest =
false;
1542 State->Stack.push_back(
1544 if (State->Stack.back() != end_itr) {
1548 State->Stack.pop_back();
1552 while (!State->Stack.empty()
1553 && State->Stack.back().increment(ec) == end_itr) {
1554 State->Stack.pop_back();
1559 if (State->Stack.empty())
1570 int level()
const {
return State->Level; }
1578 assert(State &&
"Cannot pop an end iterator!");
1579 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
1586 State->Stack.pop_back();
1588 }
while (!State->Stack.empty()
1589 && State->Stack.back().increment(ec) == end_itr);
1592 if (State->Stack.empty())
1597 void no_push() { State->HasNoPushRequest =
true; }
1600 return State ==
RHS.State;
1604 return !(*
this ==
RHS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Provides ErrorOr<T> smart pointer.
amode Optimize addressing mode
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallString class.
Represents either an error or a value T.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
The instances of the Type class are immutable: once they are created, they are never changed.
A raw_ostream that writes to a file descriptor.
RAII class that facilitates file locking.
FileLocker & operator=(FileLocker &&L)
FileLocker(const FileLocker &L)=delete
FileLocker & operator=(const FileLocker &L)=delete
FileLocker(FileLocker &&L)
Represents a temporary file.
LLVM_ABI TempFile & operator=(TempFile &&Other)
static LLVM_ABI Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Represents the result of a call to directory_iterator::status().
basic_file_status(file_type Type, perms Perms, time_t ATime, uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec, uid_t UID, gid_t GID, off_t Size)
void permissions(perms p)
uint32_t fs_st_mtime_nsec
basic_file_status()=default
uint32_t fs_st_atime_nsec
uint32_t getGroup() const
LLVM_ABI TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
perms permissions() const
LLVM_ABI TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
basic_file_status(file_type Type)
directory_entry - A single entry in a directory.
directory_entry(const Twine &Path, bool FollowSymlinks=true, file_type Type=file_type::type_unknown, basic_file_status Status=basic_file_status())
LLVM_ABI bool operator<=(const directory_entry &RHS) const
LLVM_ABI bool operator>(const directory_entry &RHS) const
LLVM_ABI bool operator>=(const directory_entry &RHS) const
LLVM_ABI bool operator<(const directory_entry &RHS) const
LLVM_ABI ErrorOr< basic_file_status > status() const
bool operator==(const directory_entry &RHS) const
bool operator!=(const directory_entry &RHS) const
const std::string & path() const
directory_entry()=default
LLVM_ABI void replace_filename(const Twine &Filename, file_type Type, basic_file_status Status=basic_file_status())
directory_iterator - Iterates through the entries in path.
bool operator!=(const directory_iterator &RHS) const
directory_iterator(const directory_entry &de, std::error_code &ec, bool follow_symlinks=true)
directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
directory_iterator()=default
Construct end iterator.
const directory_entry & operator*() const
directory_iterator & increment(std::error_code &ec)
bool operator==(const directory_iterator &RHS) const
const directory_entry * operator->() const
Represents the result of a call to sys::fs::status().
file_status(file_type Type, perms Perms, dev_t Dev, nlink_t Links, ino_t Ino, time_t ATime, uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec, uid_t UID, gid_t GID, off_t Size)
LLVM_ABI uint32_t getLinkCount() const
LLVM_ABI friend bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
file_status(file_type Type)
LLVM_ABI UniqueID getUniqueID() const
This class represents a memory mapped file.
LLVM_ABI size_t size() const
LLVM_ABI std::error_code sync() const
Write changes to disk and synchronize.
mapped_file_region(mapped_file_region &&Moved)
mapped_file_region()=default
static LLVM_ABI int alignment()
@ priv
May modify via data, but changes are lost on destruction.
@ readonly
May only access map via const_data as read only.
@ readwrite
May access map via data and modify it. Written to path.
mapped_file_region & operator=(mapped_file_region &&Moved)
LLVM_ABI const char * const_data() const
Get a const view of the data.
mapped_file_region(const mapped_file_region &)=delete
LLVM_ABI char * data() const
mapped_file_region & operator=(const mapped_file_region &)=delete
LLVM_ABI mapped_file_region(sys::fs::file_t fd, mapmode mode, size_t length, uint64_t offset, std::error_code &ec)
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child dire...
void pop()
Goes up one level if Level > 0.
bool operator==(const recursive_directory_iterator &RHS) const
void no_push()
Does not go down into the current directory_entry.
int level() const
Gets the current level. Starting path is at level 0.
const directory_entry * operator->() const
recursive_directory_iterator()=default
recursive_directory_iterator & increment(std::error_code &ec)
recursive_directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
const directory_entry & operator*() const
bool no_push_request() const
Returns true if no_push has been called for this directory_entry.
bool operator!=(const recursive_directory_iterator &RHS) const
LLVM_ABI std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
LLVM_ABI std::error_code directory_iterator_destruct(DirIterState &)
LLVM_ABI std::error_code directory_iterator_increment(DirIterState &)
LLVM_ABI bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
LLVM_ABI bool can_execute(const Twine &Path)
Can we execute this file?
LLVM_ABI bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
perms operator&(perms l, perms r)
LLVM_ABI void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
perms operator|(perms l, perms r)
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
LLVM_ABI Error readNativeFileToEOF(file_t FileHandle, SmallVectorImpl< char > &Buffer, ssize_t ChunkSize=DefaultReadChunkSize)
Reads from FileHandle until EOF, appending to Buffer in chunks of size ChunkSize.
perms & operator&=(perms &l, perms r)
LLVM_ABI ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
bool can_write(const Twine &Path)
Can we write this file?
LLVM_ABI std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
LLVM_ABI std::error_code openFile(const Twine &Name, int &ResultFD, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a file descr...
LLVM_ABI const file_t kInvalidFile
std::error_code resize_file_before_mapping_readwrite(int FD, uint64_t Size)
Resize FD to Size before mapping mapped_file_region::readwrite.
LLVM_ABI std::error_code getPotentiallyUniqueFileName(const Twine &Model, SmallVectorImpl< char > &ResultPath)
Get a unique name, not currently exisiting in the filesystem.
LLVM_ABI std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
LLVM_ABI ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
LLVM_ABI bool is_other(const basic_file_status &status)
Does this status represent something that exists but is not a directory or regular file?
LLVM_ABI std::error_code getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
Get a unique temporary file name, not currently exisiting in the filesystem.
perms & operator|=(perms &l, perms r)
LLVM_ABI Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI unsigned getUmask()
Get file creation mode mask of the process.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
LLVM_ABI Expected< file_t > openNativeFile(const Twine &Name, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a platform-s...
@ OF_Delete
The returned handle can be used for deleting the file.
@ OF_ChildInherit
When a child process is launched, this file should remain open in the child process.
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
@ OF_CRLF
The file should use a carriage linefeed '\r '.
@ OF_UpdateAtime
Force files Atime to be updated on access.
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
@ OF_Append
The file should be opened in append mode.
LLVM_ABI file_t getStdoutHandle()
Return an open handle to standard out.
file_type
An enumeration for the file system's view of the type.
LLVM_ABI std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
Expected< file_t > openNativeFileForWrite(const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI void expand_tilde(const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
LLVM_ABI std::error_code getUniqueID(const Twine Path, UniqueID &Result)
LLVM_ABI std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
LLVM_ABI std::error_code lockFile(int FD, LockKind Kind=LockKind::Exclusive)
Lock the file.
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
LLVM_ABI std::error_code set_current_path(const Twine &path)
Set the current path.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
@ CD_OpenAlways
CD_OpenAlways - When opening a file:
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
@ CD_CreateNew
CD_CreateNew - When opening a file:
LLVM_ABI Expected< size_t > readNativeFileSlice(file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
LLVM_ABI std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
Expected< file_t > openNativeFileForReadWrite(const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::string getMainExecutable(const char *argv0, void *MainExecAddr)
Return the path to the main executable, given the value of argv[0] from program startup and the addre...
LLVM_ABI void createUniquePath(const Twine &Model, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute)
Create a potentially unique file name but does not create it.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
LLVM_ABI bool status_known(const basic_file_status &s)
Is status available?
LLVM_ABI std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
LLVM_ABI file_type get_file_type(const Twine &Path, bool Follow=true)
Does status represent a directory?
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
LLVM_ABI std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), LockKind Kind=LockKind::Exclusive)
Try to locks the file during the specified time.
LLVM_ABI std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
LockKind
An enumeration for the lock kind.
LLVM_ABI std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
LLVM_ABI std::error_code is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
LLVM_ABI std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ABI bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
LLVM_ABI file_t getStderrHandle()
Return an open handle to standard error.
LLVM_ABI std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
LLVM_ABI ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
LLVM_ABI file_t getStdinHandle()
Return an open handle to standard in.
LLVM_ABI std::error_code unlockFile(int FD)
Unlock the file.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
@ Timeout
Reached timeout while waiting for the owner to release the lock.
Implement std::hash so that hash_code can be used in STL containers.
Keeps state for the directory_iterator.
directory_entry CurrentEntry
Keeps state for the recursive_directory_iterator.
std::vector< directory_iterator > Stack
space_info - Self explanatory.