diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-02 08:08:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-02 08:08:39 +0000 |
commit | d062bff7ee5bec21b16338ecb44152901110a094 (patch) | |
tree | 40b96f47c0ad71a17b9c0cb9e2f296b28fde3ced /clang/lib/Frontend/CompilerInstance.cpp | |
parent | d28ae27d8d2e20672e182710160f27cf821b55fd (diff) | |
download | llvm-d062bff7ee5bec21b16338ecb44152901110a094.zip llvm-d062bff7ee5bec21b16338ecb44152901110a094.tar.gz llvm-d062bff7ee5bec21b16338ecb44152901110a094.tar.bz2 |
Introduce a new clang-cc option
-remap-file=from;to
which takes the file "from" and transparently replaces its contents
with the contents of the file "to" from the source manager's
perspective. This is the moral equivalent of
cp from saved
cp to from
<call clang>
cp saved from
rm saved
without all of the pesky file copying.
llvm-svn: 90307
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 2d58bee..02b24b49 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -190,6 +190,45 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags, PP->setPTHManager(PTHMgr); } + // Remap files in the source manager. + for (PreprocessorOptions::remapped_file_iterator + Remap = PPOpts.remapped_file_begin(), + RemapEnd = PPOpts.remapped_file_end(); + Remap != RemapEnd; + ++Remap) { + // Find the file that we're mapping to. + const FileEntry *ToFile = FileMgr.getFile(Remap->second); + if (!ToFile) { + Diags.Report(diag::err_fe_remap_missing_to_file) + << Remap->first << Remap->second; + continue; + } + + // Find the file that we're mapping from. + const FileEntry *FromFile = FileMgr.getFile(Remap->first); + if (!FromFile) { + // FIXME: We could actually recover from this, by faking a + // FileEntry based on the "ToFile". + Diags.Report(diag::err_fe_remap_missing_from_file) + << Remap->first; + continue; + } + + // Load the contents of the file we're mapping to. + std::string ErrorStr; + const llvm::MemoryBuffer *Buffer + = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr); + if (!Buffer) { + Diags.Report(diag::err_fe_error_opening) + << Remap->second << ErrorStr; + continue; + } + + // Override the contents of the "from" file with the contents of + // the "to" file. + SourceMgr.overrideFileContents(FromFile, Buffer); + } + InitializePreprocessor(*PP, PPOpts, HSOpts); // Handle generating dependencies, if requested. |