Frontend: Add support for reading named pipes as the main file.

- The whole {File,Source}Manager is built around wanting to pre-determine the
   size of files, so we can't fit this in naturally. Instead, we handle it like
   we do STDIN, where we just replace the main file contents upfront.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167419 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2012-11-05 22:53:33 +00:00
Родитель 95b66fca55
Коммит ce36ecd5a5
3 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -103,6 +103,10 @@ public:
bool operator<(const FileEntry &RHS) const {
return Device < RHS.Device || (Device == RHS.Device && Inode < RHS.Inode);
}
/// \brief Check whether the file is a named pipe (and thus can't be opened by
/// the native FileManager methods).
bool isNamedPipe() const;
};
/// \brief Implements support for file system lookup, file system caching,

Просмотреть файл

@ -57,6 +57,10 @@ FileEntry::~FileEntry() {
if (FD != -1) ::close(FD);
}
bool FileEntry::isNamedPipe() const {
return FileMode & S_IFIFO;
}
//===----------------------------------------------------------------------===//
// Windows.
//===----------------------------------------------------------------------===//

Просмотреть файл

@ -610,6 +610,19 @@ bool CompilerInstance::InitializeSourceManager(StringRef InputFile,
return false;
}
SourceMgr.createMainFileID(File, Kind);
// The natural SourceManager infrastructure can't currently handle named
// pipes, but we would at least like to accept them for the main
// file. Detect them here, read them with the more generic MemoryBuffer
// function, and simply override their contents as we do for STDIN.
if (File->isNamedPipe()) {
OwningPtr<llvm::MemoryBuffer> MB;
if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
return false;
}
SourceMgr.overrideFileContents(File, MB.take());
}
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {