[modules] Support use of -E on modules built from the command line.

llvm-svn: 342306
This commit is contained in:
Richard Smith 2018-09-15 01:21:18 +00:00
parent cd35eff395
commit 8b464f299f
4 changed files with 14 additions and 10 deletions

View File

@ -587,12 +587,12 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
assert(ASTModule && "module file does not define its own module");
Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind);
} else {
auto &SM = CI.getSourceManager();
FileID ID = SM.getMainFileID();
if (auto *File = SM.getFileEntryForID(ID))
auto &OldSM = AST->getSourceManager();
FileID ID = OldSM.getMainFileID();
if (auto *File = OldSM.getFileEntryForID(ID))
Input = FrontendInputFile(File->getName(), Kind);
else
Input = FrontendInputFile(SM.getBuffer(ID), Kind);
Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
}
setCurrentInput(Input, std::move(AST));
}

View File

@ -825,7 +825,7 @@ void PrintPreprocessedAction::ExecuteAction() {
}
std::unique_ptr<raw_ostream> OS =
CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
CI.createDefaultOutputFile(BinaryMode, getCurrentFileOrBufferName());
if (!OS) return;
// If we're preprocessing a module map, start by dumping the contents of the
@ -837,8 +837,6 @@ void PrintPreprocessedAction::ExecuteAction() {
OS->write_escaped(Input.getFile());
(*OS) << "\"\n";
}
// FIXME: Include additional information here so that we don't need the
// original source files to exist on disk.
getCurrentModule()->print(*OS);
(*OS) << "#pragma clang module contents\n";
}

View File

@ -181,7 +181,7 @@ RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
void RewriteMacrosAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
std::unique_ptr<raw_ostream> OS =
CI.createDefaultOutputFile(true, getCurrentFile());
CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
if (!OS) return;
RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@ -190,7 +190,7 @@ void RewriteMacrosAction::ExecuteAction() {
void RewriteTestAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
std::unique_ptr<raw_ostream> OS =
CI.createDefaultOutputFile(false, getCurrentFile());
CI.createDefaultOutputFile(false, getCurrentFileOrBufferName());
if (!OS) return;
DoRewriteTest(CI.getPreprocessor(), OS.get());
@ -265,7 +265,8 @@ public:
bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
if (!OutputStream) {
OutputStream = CI.createDefaultOutputFile(true, getCurrentFile());
OutputStream =
CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
if (!OutputStream)
return false;
}

View File

@ -4,6 +4,11 @@
// RUN: %clang_cc1 -fmodules-ts -fmodule-file=%t.pcm %s -I%S/Inputs/no-module-map -verify -DB
// RUN: %clang_cc1 -fmodules-ts -fmodule-file=%t.pcm %s -I%S/Inputs/no-module-map -verify -DA -DB
// RUN: %clang_cc1 -E %t.pcm -o - | FileCheck %s
// RUN: %clang_cc1 -frewrite-imports -E %t.pcm -o - | FileCheck %s
// CHECK: # {{.*}}a.h
// CHECK: # {{.*}}b.h
#ifdef B
// expected-no-diagnostics
#endif