From ccb6cb6fd9e48697564d536b07397b95dfc28d5b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 14 Nov 2009 07:53:04 +0000 Subject: Add CompilerInstance::InitializeSourceManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88764 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInstance.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lib/Frontend/CompilerInstance.cpp') diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 2877c63a4e..b5277acdff 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -25,6 +25,7 @@ #include "clang/Frontend/Utils.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "llvm/LLVMContext.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" using namespace clang; @@ -361,3 +362,40 @@ CompilerInstance::createOutputFile(llvm::StringRef OutputPath, return OS; } + +// Initialization Utilities + +bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) { + return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(), + getSourceManager(), getFrontendOpts()); +} + +bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile, + Diagnostic &Diags, + FileManager &FileMgr, + SourceManager &SourceMgr, + const FrontendOptions &Opts) { + // Figure out where to get and map in the main file. + if (Opts.EmptyInputOnly) { + const char *EmptyStr = ""; + llvm::MemoryBuffer *SB = + llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, ""); + SourceMgr.createMainFileIDForMemBuffer(SB); + } else if (InputFile != "-") { + const FileEntry *File = FileMgr.getFile(InputFile); + if (File) SourceMgr.createMainFileID(File, SourceLocation()); + if (SourceMgr.getMainFileID().isInvalid()) { + Diags.Report(diag::err_fe_error_reading) << InputFile; + return false; + } + } else { + llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(); + SourceMgr.createMainFileIDForMemBuffer(SB); + if (SourceMgr.getMainFileID().isInvalid()) { + Diags.Report(diag::err_fe_error_reading_stdin); + return false; + } + } + + return true; +} -- cgit v1.2.3-18-g5258