19 #include <system_error> 21 #if !defined(_MSC_VER) && !defined(__MINGW32__) 37 std::unique_ptr<fs::mapped_file_region> Buf)
40 uint8_t *getBufferStart()
const override {
return (uint8_t *)Buffer->data(); }
42 uint8_t *getBufferEnd()
const override {
43 return (uint8_t *)Buffer->data() + Buffer->size();
46 size_t getBufferSize()
const override {
return Buffer->size(); }
48 Error commit()
override {
53 return Temp.keep(FinalPath);
56 ~OnDiskBuffer()
override {
63 void discard()
override {
70 std::unique_ptr<fs::mapped_file_region> Buffer;
83 uint8_t *getBufferStart()
const override {
return (uint8_t *)Buffer.base(); }
85 uint8_t *getBufferEnd()
const override {
86 return (uint8_t *)Buffer.base() + BufferSize;
89 size_t getBufferSize()
const override {
return BufferSize; }
91 Error commit()
override {
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);
149 auto MappedFile = std::make_unique<fs::mapped_file_region>(
160 return std::make_unique<OnDiskBuffer>(Path, std::move(File),
161 std::move(MappedFile));
172 if (Flags & F_executable)
186 switch (Stat.
type()) {
192 if (Flags & F_no_mmap)
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...
static Expected< std::unique_ptr< FileOutputBuffer > > createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode)
file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
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.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
Instrumentation for Order File
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.