From e2951f48bfb5cbe5d5cbdefaeda43b72a8e7a117 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 5 Nov 2012 22:53:33 +0000 Subject: 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. llvm-svn: 167419 --- clang/lib/Frontend/CompilerInstance.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'clang/lib/Frontend/CompilerInstance.cpp') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index c6c5fb5..b858322 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -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 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 SB; if (llvm::MemoryBuffer::getSTDIN(SB)) { -- cgit v1.1