diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-14 07:53:04 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-14 07:53:04 +0000 |
commit | 409e890f8d705ec7b2ee7aff8508dfe1ac835eae (patch) | |
tree | d60267c124c14574132a10e9a502497cec683e4e /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 7935bcb0fec94f243c26220b9bc4cdd393b65377 (diff) | |
download | bcm5719-llvm-409e890f8d705ec7b2ee7aff8508dfe1ac835eae.tar.gz bcm5719-llvm-409e890f8d705ec7b2ee7aff8508dfe1ac835eae.zip |
Add CompilerInstance::InitializeSourceManager.
llvm-svn: 88764
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 2877c63a4e2..b5277acdff4 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/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, "<empty input>"); + 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; +} |