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 /include | |
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 'include')
-rw-r--r-- | include/clang/Basic/LangOptions.h | 12 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 2 | ||||
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 15 | ||||
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 2 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendAction.h | 8 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendActions.h | 11 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendOptions.h | 1 | ||||
-rw-r--r-- | include/clang/Parse/ParseAST.h | 8 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 14 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 2 |
10 files changed, 46 insertions, 29 deletions
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index dc77d4c149..5cdeda3877 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -296,6 +296,18 @@ public: } }; +/// \brief Describes the kind of translation unit being processed. +enum TranslationUnitKind { + /// \brief The translation unit is a complete translation unit. + TU_Complete, + /// \brief The translation unit is a prefix to a translation unit, and is + /// not complete. + TU_Prefix, + /// \brief The translation unit is a module. + TU_Module +}; + + /// \brief } // end namespace clang #endif diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 3edd436b7e..2c3bfc07a0 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -360,6 +360,8 @@ def ast_view : Flag<"-ast-view">, HelpText<"Build ASTs and view them with GraphViz">; def print_decl_contexts : Flag<"-print-decl-contexts">, HelpText<"Print DeclContexts and their Decls">; +def emit_module : Flag<"-emit-module">, + HelpText<"Generate pre-compiled module file">; def emit_pth : Flag<"-emit-pth">, HelpText<"Generate pre-tokenized header file">; def emit_pch : Flag<"-emit-pch">, diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index db3f7ee01c..08b626facc 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -112,8 +112,8 @@ private: /// \brief Track whether the main file was loaded from an AST or not. bool MainFileIsAST; - /// \brief Whether this AST represents a complete translation unit. - bool CompleteTranslationUnit; + /// \brief What kind of translation unit this AST represents. + TranslationUnitKind TUKind; /// \brief Whether we should time each operation. bool WantTiming; @@ -548,11 +548,8 @@ public: llvm::MemoryBuffer *getBufferForFile(StringRef Filename, std::string *ErrorStr = 0); - /// \brief Whether this AST represents a complete translation unit. - /// - /// If false, this AST is only a partial translation unit, e.g., one - /// that might still be used as a precompiled header or preamble. - bool isCompleteTranslationUnit() const { return CompleteTranslationUnit; } + /// \brief Determine what kind of translation unit this AST represents. + TranslationUnitKind getTranslationUnitKind() const { return TUKind; } typedef llvm::PointerUnion<const char *, const llvm::MemoryBuffer *> FilenameOrMemBuf; @@ -624,7 +621,7 @@ public: bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, bool PrecompilePreamble = false, - bool CompleteTranslationUnit = true, + TranslationUnitKind TUKind = TU_Complete, bool CacheCodeCompletionResults = false, bool NestedMacroExpansions = true); @@ -652,7 +649,7 @@ public: unsigned NumRemappedFiles = 0, bool RemappedFilesKeepOriginalName = true, bool PrecompilePreamble = false, - bool CompleteTranslationUnit = true, + TranslationUnitKind TUKind = TU_Complete, bool CacheCodeCompletionResults = false, bool CXXPrecompilePreamble = false, bool CXXChainedPCH = false, diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 425f2e7241..3f97f1addb 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -548,7 +548,7 @@ public: raw_ostream &OS); /// \brief Create the Sema object to be used for parsing. - void createSema(bool CompleteTranslationUnit, + void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer); /// Create the frontend timer and replace any existing one with it. diff --git a/include/clang/Frontend/FrontendAction.h b/include/clang/Frontend/FrontendAction.h index 4762e093cf..f85cc7ec91 100644 --- a/include/clang/Frontend/FrontendAction.h +++ b/include/clang/Frontend/FrontendAction.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_FRONTENDACTION_H #include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/OwningPtr.h" #include <string> @@ -160,9 +161,8 @@ public: /// file inputs. virtual bool usesPreprocessorOnly() const = 0; - /// usesCompleteTranslationUnit - For AST based actions, should the - /// translation unit be completed? - virtual bool usesCompleteTranslationUnit() { return true; } + /// \brief For AST-based actions, the kind of translation unit we're handling. + virtual TranslationUnitKind getTranslationUnitKind() { return TU_Complete; } /// hasPCHSupport - Does this action support use with PCH? virtual bool hasPCHSupport() const { return !usesPreprocessorOnly(); } @@ -282,7 +282,7 @@ public: WrapperFrontendAction(FrontendAction *WrappedAction); virtual bool usesPreprocessorOnly() const; - virtual bool usesCompleteTranslationUnit(); + virtual TranslationUnitKind getTranslationUnitKind(); virtual bool hasPCHSupport() const; virtual bool hasASTFileSupport() const; virtual bool hasIRSupport() const; diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index 646ee2552a..ef204312c4 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -67,15 +67,22 @@ protected: }; class GeneratePCHAction : public ASTFrontendAction { + bool MakeModule; + protected: virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef InFile); - virtual bool usesCompleteTranslationUnit() { return false; } + virtual TranslationUnitKind getTranslationUnitKind() { + return MakeModule? TU_Module : TU_Prefix; + } virtual bool hasASTFileSupport() const { return false; } public: + /// \brief Create a new action + explicit GeneratePCHAction(bool MakeModule) : MakeModule(MakeModule) { } + /// \brief Compute the AST consumer arguments that will be used to /// create the PCHGenerator instance returned by CreateASTConsumer. /// @@ -128,7 +135,7 @@ public: virtual ~ASTMergeAction(); virtual bool usesPreprocessorOnly() const; - virtual bool usesCompleteTranslationUnit(); + virtual TranslationUnitKind getTranslationUnitKind(); virtual bool hasPCHSupport() const; virtual bool hasASTFileSupport() const; virtual bool hasCodeCompletionSupport() const; diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index e7c2ac4002..75e3eba80c 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -35,6 +35,7 @@ namespace frontend { EmitCodeGenOnly, ///< Generate machine code, but don't emit anything. EmitObj, ///< Emit a .o file. FixIt, ///< Parse and apply any fixits to the source. + GenerateModule, ///< Generate pre-compiled module. GeneratePCH, ///< Generate pre-compiled header. GeneratePTH, ///< Generate pre-tokenized header. InitOnly, ///< Only execute frontend initialization. diff --git a/include/clang/Parse/ParseAST.h b/include/clang/Parse/ParseAST.h index 0d37e21bec..725387024e 100644 --- a/include/clang/Parse/ParseAST.h +++ b/include/clang/Parse/ParseAST.h @@ -14,6 +14,8 @@ #ifndef LLVM_CLANG_PARSE_PARSEAST_H #define LLVM_CLANG_PARSE_PARSEAST_H +#include "clang/Basic/LangOptions.h" + namespace clang { class Preprocessor; class ASTConsumer; @@ -27,15 +29,13 @@ namespace clang { /// This operation inserts the parsed decls into the translation /// unit held by Ctx. /// - /// \param CompleteTranslationUnit When true, the parsed file is - /// considered to be a complete translation unit, and any - /// end-of-translation-unit wrapup will be performed. + /// \param TUKind The kind of translation unit being parsed. /// /// \param CompletionConsumer If given, an object to consume code completion /// results. void ParseAST(Preprocessor &pp, ASTConsumer *C, ASTContext &Ctx, bool PrintStats = false, - bool CompleteTranslationUnit = true, + TranslationUnitKind TUKind = TU_Complete, CodeCompleteConsumer *CompletionConsumer = 0); /// \brief Parse the main file known to the preprocessor, producing an diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 07bbd18bee..adf2702cce 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -630,16 +630,14 @@ public: /// for C++ records. llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache; - /// \brief Whether the code handled by Sema should be considered a - /// complete translation unit or not. + /// \brief The kind of translation unit we are processing. /// - /// When true (which is generally the case), Sema will perform + /// When we're processing a complete translation unit, Sema will perform /// end-of-translation-unit semantic tasks (such as creating /// initializers for tentative definitions in C) once parsing has - /// completed. This flag will be false when building PCH files, - /// since a PCH file is by definition not a complete translation - /// unit. - bool CompleteTranslationUnit; + /// completed. Modules and precompiled headers perform different kinds of + /// checks. + TranslationUnitKind TUKind; llvm::BumpPtrAllocator BumpAlloc; @@ -685,7 +683,7 @@ public: bool isSelfExpr(Expr *RExpr); public: Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, - bool CompleteTranslationUnit = true, + TranslationUnitKind TUKind = TU_Complete, CodeCompleteConsumer *CompletionConsumer = 0); ~Sema(); diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 0bc8e29f8e..1bb8edb073 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -641,7 +641,7 @@ protected: const ASTWriter &getWriter() const { return Writer; } public: - PCHGenerator(const Preprocessor &PP, const std::string &OutputFile, + PCHGenerator(const Preprocessor &PP, StringRef OutputFile, bool Chaining, StringRef isysroot, raw_ostream *Out); ~PCHGenerator(); virtual void InitializeSema(Sema &S) { SemaPtr = &S; } |