20 #include <system_error> 22 #if !defined(_MSC_VER) && !defined(__MINGW32__) 38 std::unique_ptr<fs::mapped_file_region> Buf)
41 uint8_t *getBufferStart()
const override {
return (uint8_t *)Buffer->data(); }
43 uint8_t *getBufferEnd()
const override {
44 return (uint8_t *)Buffer->data() + Buffer->size();
47 size_t getBufferSize()
const override {
return Buffer->size(); }
49 Error commit()
override {
54 return Temp.keep(FinalPath);
57 ~OnDiskBuffer()
override {
64 void discard()
override {
71 std::unique_ptr<fs::mapped_file_region> Buffer;
82 uint8_t *getBufferStart()
const override {
return (uint8_t *)Buffer.base(); }
84 uint8_t *getBufferEnd()
const override {
85 return (uint8_t *)Buffer.base() + Buffer.size();
88 size_t getBufferSize()
const override {
return Buffer.size(); }
90 Error commit()
override {
91 using namespace sys::fs;
98 OS <<
StringRef((
const char *)Buffer.base(), Buffer.size());
115 return llvm::make_unique<InMemoryBuffer>(Path, MB,
Mode);
146 auto MappedFile = llvm::make_unique<fs::mapped_file_region>(
152 return llvm::make_unique<OnDiskBuffer>(Path, std::move(File),
153 std::move(MappedFile));
160 if (Flags & F_executable)
166 if ((Flags & F_modify) && Size ==
size_t(-1)) {
183 switch (Stat.
type()) {
static Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
This class represents lattice values for constants.
Error takeError()
Take ownership of the stored error.
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Represents the result of a call to sys::fs::status().
static MemoryBlock allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC)
This method allocates a block of memory that is suitable for loading dynamically generated code (e...
Represents a temporary file.
FileOutputBuffer - This interface provides simple way to create an in-memory buffer which will be wri...
Tagged union holding either a T or a Error.
May access map via data and modify it. Written to path.
static Expected< std::unique_ptr< OnDiskBuffer > > createOnDiskBuffer(StringRef Path, size_t Size, bool InitExisting, unsigned Mode)
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
static Expected< std::unique_ptr< InMemoryBuffer > > createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode)
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...
void consumeError(Error Err)
Consume a Error without doing anything.
static ErrorSuccess success()
Create a success value.
This class encapsulates the notion of a memory block which has an address and a size.
Owning version of MemoryBlock.
A raw_ostream that writes to a file descriptor.
CD_CreateAlways - When opening a file:
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.