diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-25 22:30:56 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-25 22:30:56 +0000 |
commit | 467dc88512b4ba4bb16e274ea3771dc1415d31da (patch) | |
tree | c5ebc779742f310ab83aa597265cfd9a7e854b0b /lib | |
parent | ca4c40ab4995d195d9a4d175fa7c30dcc2d99ebf (diff) |
Introduce a -cc1 option "-emit-module", that creates a binary module
from the given source. -emit-module behaves similarly to -emit-pch,
except that Sema is somewhat more strict about the contents of
-emit-module. In the future, there are likely to be more interesting
differences.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138595 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/ASTMerge.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/ASTUnit.cpp | 19 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | lib/Frontend/FrontendAction.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/FrontendActions.cpp | 5 | ||||
-rw-r--r-- | lib/FrontendTool/ExecuteCompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | lib/Parse/ParseAST.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 19 | ||||
-rw-r--r-- | lib/Serialization/ChainedIncludesSource.cpp | 2 | ||||
-rw-r--r-- | lib/Serialization/GeneratePCH.cpp | 2 |
11 files changed, 41 insertions, 30 deletions
diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp index df4650e68f..74aa5a64a4 100644 --- a/lib/Frontend/ASTMerge.cpp +++ b/lib/Frontend/ASTMerge.cpp @@ -93,8 +93,8 @@ bool ASTMergeAction::usesPreprocessorOnly() const { return AdaptedAction->usesPreprocessorOnly(); } -bool ASTMergeAction::usesCompleteTranslationUnit() { - return AdaptedAction->usesCompleteTranslationUnit(); +TranslationUnitKind ASTMergeAction::getTranslationUnitKind() { + return AdaptedAction->getTranslationUnitKind(); } bool ASTMergeAction::hasPCHSupport() const { diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 71f9c0dada..b8d9f2f8c2 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -97,7 +97,7 @@ static llvm::sys::cas_flag ActiveASTUnitObjects; ASTUnit::ASTUnit(bool _MainFileIsAST) : OnlyLocalDecls(false), CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST), - CompleteTranslationUnit(true), WantTiming(getenv("LIBCLANG_TIMING")), + TUKind(TU_Complete), WantTiming(getenv("LIBCLANG_TIMING")), OwnsRemappedFileBuffers(true), NumStoredDiagnosticsFromDriver(0), ConcurrencyCheckValue(CheckUnlocked), @@ -759,8 +759,8 @@ public: TopLevelDeclTrackerAction(ASTUnit &_Unit) : Unit(_Unit) {} virtual bool hasCodeCompletionSupport() const { return false; } - virtual bool usesCompleteTranslationUnit() { - return Unit.isCompleteTranslationUnit(); + virtual TranslationUnitKind getTranslationUnitKind() { + return Unit.getTranslationUnitKind(); } }; @@ -844,7 +844,7 @@ public: virtual bool hasCodeCompletionSupport() const { return false; } virtual bool hasASTFileSupport() const { return false; } - virtual bool usesCompleteTranslationUnit() { return false; } + virtual TranslationUnitKind getTranslationUnitKind() { return TU_Prefix; } }; } @@ -1592,8 +1592,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI, AST->Diagnostics = Diags; AST->OnlyLocalDecls = false; AST->CaptureDiagnostics = false; - AST->CompleteTranslationUnit = Action ? Action->usesCompleteTranslationUnit() - : true; + AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete; AST->ShouldCacheCodeCompletionResults = false; AST->Invocation = CI; @@ -1727,7 +1726,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, bool OnlyLocalDecls, bool CaptureDiagnostics, bool PrecompilePreamble, - bool CompleteTranslationUnit, + TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool NestedMacroExpansions) { // Create the AST unit. @@ -1737,7 +1736,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, AST->Diagnostics = Diags; AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; - AST->CompleteTranslationUnit = CompleteTranslationUnit; + AST->TUKind = TUKind; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->Invocation = CI; AST->NestedMacroExpansions = NestedMacroExpansions; @@ -1762,7 +1761,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, unsigned NumRemappedFiles, bool RemappedFilesKeepOriginalName, bool PrecompilePreamble, - bool CompleteTranslationUnit, + TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool CXXPrecompilePreamble, bool CXXChainedPCH, @@ -1828,7 +1827,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, AST->FileMgr = new FileManager(AST->FileSystemOpts); AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; - AST->CompleteTranslationUnit = CompleteTranslationUnit; + AST->TUKind = TUKind; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size(); AST->StoredDiagnostics.swap(StoredDiagnostics); diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 026cb5a3d5..ec8b6dc910 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -382,10 +382,10 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, ShowGlobals, OS); } -void CompilerInstance::createSema(bool CompleteTranslationUnit, +void CompilerInstance::createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer) { TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(), - CompleteTranslationUnit, CompletionConsumer)); + TUKind, CompletionConsumer)); } // Output Files diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index bc6b08d686..763c8a1e8b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -372,6 +372,7 @@ static const char *getActionName(frontend::ActionKind Kind) { case frontend::EmitCodeGenOnly: return "-emit-codegen-only"; case frontend::EmitObj: return "-emit-obj"; case frontend::FixIt: return "-fixit"; + case frontend::GenerateModule: return "-emit-module"; case frontend::GeneratePCH: return "-emit-pch"; case frontend::GeneratePTH: return "-emit-pth"; case frontend::InitOnly: return "-init-only"; @@ -1205,6 +1206,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, // fall-through! case OPT_fixit: Opts.ProgramAction = frontend::FixIt; break; + case OPT_emit_module: + Opts.ProgramAction = frontend::GenerateModule; break; case OPT_emit_pch: Opts.ProgramAction = frontend::GeneratePCH; break; case OPT_emit_pth: diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 0753686a34..b92f75ba43 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -398,7 +398,7 @@ void ASTFrontendAction::ExecuteAction() { CompletionConsumer = &CI.getCodeCompletionConsumer(); if (!CI.hasSema()) - CI.createSema(usesCompleteTranslationUnit(), CompletionConsumer); + CI.createSema(getTranslationUnitKind(), CompletionConsumer); ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats); } @@ -432,8 +432,8 @@ void WrapperFrontendAction::EndSourceFileAction() { bool WrapperFrontendAction::usesPreprocessorOnly() const { return WrappedAction->usesPreprocessorOnly(); } -bool WrapperFrontendAction::usesCompleteTranslationUnit() { - return WrappedAction->usesCompleteTranslationUnit(); +TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() { + return WrappedAction->getTranslationUnitKind(); } bool WrapperFrontendAction::hasPCHSupport() const { return WrappedAction->hasPCHSupport(); diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index d6df141905..5e2b9c473f 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -79,12 +79,13 @@ ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, std::string OutputFile; raw_ostream *OS = 0; bool Chaining; - if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS, Chaining)) + if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS, + Chaining)) return 0; if (!CI.getFrontendOpts().RelocatablePCH) Sysroot.clear(); - return new PCHGenerator(CI.getPreprocessor(), OutputFile, Chaining, Sysroot, + return new PCHGenerator(CI.getPreprocessor(), OutputFile, Chaining, Sysroot, OS); } diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp index ed081923f3..a506b410c5 100644 --- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -50,7 +50,8 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { case EmitCodeGenOnly: return new EmitCodeGenOnlyAction(); case EmitObj: return new EmitObjAction(); case FixIt: return new FixItAction(); - case GeneratePCH: return new GeneratePCHAction(); + case GenerateModule: return new GeneratePCHAction(true); + case GeneratePCH: return new GeneratePCHAction(false); case GeneratePTH: return new GeneratePTHAction(); case InitOnly: return new InitOnlyAction(); case ParseSyntaxOnly: return new SyntaxOnlyAction(); diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp index 5c2c2f785f..fdd7d0f151 100644 --- a/lib/Parse/ParseAST.cpp +++ b/lib/Parse/ParseAST.cpp @@ -37,11 +37,11 @@ using namespace clang; /// void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, ASTContext &Ctx, bool PrintStats, - bool CompleteTranslationUnit, + TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer) { llvm::OwningPtr<Sema> S(new Sema(PP, Ctx, *Consumer, - CompleteTranslationUnit, + TUKind, CompletionConsumer)); // Recover resources if we crash before exiting this method. diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index f9da82dbb3..d3ace9dc69 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -74,7 +74,7 @@ void Sema::ActOnTranslationUnitScope(Scope *S) { } Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, - bool CompleteTranslationUnit, + TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter) : TheTargetAttributesSema(0), FPFeatures(pp.getLangOptions()), LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer), @@ -85,7 +85,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, IdResolver(pp.getLangOptions()), CXXTypeInfoDecl(0), MSVCGuidDecl(0), GlobalNewDeleteDeclared(false), ObjCShouldCallSuperDealloc(false), - CompleteTranslationUnit(CompleteTranslationUnit), + TUKind(TUKind), NumSFINAEErrors(0), SuppressAccessChecking(false), AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false), NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1), @@ -391,9 +391,9 @@ void Sema::LoadExternalWeakUndeclaredIdentifiers() { /// translation unit when EOF is reached and all but the top-level scope is /// popped. void Sema::ActOnEndOfTranslationUnit() { - // At PCH writing, implicit instantiations and VTable handling info are - // stored and performed when the PCH is included. - if (CompleteTranslationUnit) { + // Only complete translation units define vtables and perform implicit + // instantiations. + if (TUKind == TU_Complete) { // If any dynamic classes have their key function defined within // this translation unit, then those vtables are considered "used" and must // be emitted. @@ -435,7 +435,8 @@ void Sema::ActOnEndOfTranslationUnit() { this)), UnusedFileScopedDecls.end()); - if (!CompleteTranslationUnit) { + if (TUKind == TU_Prefix) { + // Translation unit prefixes don't need any of the checking below. TUScope = 0; return; } @@ -453,6 +454,12 @@ void Sema::ActOnEndOfTranslationUnit() { << I->first; } + if (TUKind == TU_Module) { + // Modules don't need any of the checking below. + TUScope = 0; + return; + } + // C99 6.9.2p2: // A declaration of an identifier for an object that has file // scope without an initializer, and without a storage-class diff --git a/lib/Serialization/ChainedIncludesSource.cpp b/lib/Serialization/ChainedIncludesSource.cpp index 454e4194ab..4ee1c1667f 100644 --- a/lib/Serialization/ChainedIncludesSource.cpp +++ b/lib/Serialization/ChainedIncludesSource.cpp @@ -111,7 +111,7 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { Clang->getASTContext().setASTMutationListener( consumer->GetASTMutationListener()); Clang->setASTConsumer(consumer.take()); - Clang->createSema(/*CompleteTranslationUnit=*/false, 0); + Clang->createSema(TU_Prefix, 0); if (firstInclude) { Preprocessor &PP = Clang->getPreprocessor(); diff --git a/lib/Serialization/GeneratePCH.cpp b/lib/Serialization/GeneratePCH.cpp index 3f3674e616..ac395bb2d6 100644 --- a/lib/Serialization/GeneratePCH.cpp +++ b/lib/Serialization/GeneratePCH.cpp @@ -27,7 +27,7 @@ using namespace clang; PCHGenerator::PCHGenerator(const Preprocessor &PP, - const std::string &OutputFile, + StringRef OutputFile, bool Chaining, StringRef isysroot, raw_ostream *OS) |