18#include <system_error>
20#if !defined(_MSC_VER) && !defined(__MINGW32__)
41 return (
uint8_t *)Buffer.data() + Buffer.size();
44 size_t getBufferSize()
const override {
return Buffer.size(); }
53 return Temp.keep(FinalPath);
56 ~OnDiskBuffer()
override {
86 return (
uint8_t *)Buffer.base() + BufferSize;
92 if (FinalPath ==
"-") {
98 using namespace sys::fs;
105 OS <<
StringRef((
const char *)Buffer.base(), BufferSize);
124 return std::make_unique<InMemoryBuffer>(Path, MB,
Size, Mode);
153 return std::make_unique<OnDiskBuffer>(Path, std::move(File),
154 std::move(MappedFile));
183 switch (Stat.type()) {
184 case fs::file_type::directory_file:
186 case fs::file_type::regular_file:
187 case fs::file_type::file_not_found:
188 case fs::file_type::status_error:
static Expected< std::unique_ptr< FileOutputBuffer > > createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode)
static Expected< std::unique_ptr< InMemoryBuffer > > createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
FileOutputBuffer - This interface provides simple way to create an in-memory buffer which will be wri...
virtual uint8_t * getBufferStart() const =0
Returns a pointer to the start of the buffer.
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...
virtual uint8_t * getBufferEnd() const =0
Returns a pointer to the end of the buffer.
virtual Error commit()=0
Flushes the content of the buffer to its file and deallocates the buffer.
virtual size_t getBufferSize() const =0
Returns size of the buffer.
virtual void discard()
This removes the temporary file (unless it already was committed) but keeps the memory mapping alive.
@ F_no_mmap
Don't use mmap and instead write an in-memory buffer to a file when this buffer is closed.
@ F_executable
Set the 'x' bit on the resulting file.
StringRef - Represent a constant reference to a string, i.e.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
A raw_ostream that writes to a file descriptor.
This class encapsulates the notion of a memory block which has an address and a size.
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....
Owning version of MemoryBlock.
Represents a temporary file.
static 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 sys::fs::status().
This class represents a memory mapped file.
@ readwrite
May access map via data and modify it. Written to path.
std::error_code resize_file_before_mapping_readwrite(int FD, uint64_t Size)
Resize FD to Size before mapping mapped_file_region::readwrite.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
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...
file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.