forked from OSchip/llvm-project
				
			emit tokens, constify the Preprocessor passed down into PCH writer.
llvm-svn: 68798
This commit is contained in:
		
							parent
							
								
									baa52f47c1
								
							
						
					
					
						commit
						2199f5b4e5
					
				| 
						 | 
					@ -77,7 +77,7 @@ class PCHWriter {
 | 
				
			||||||
  pch::TypeID NextTypeID;
 | 
					  pch::TypeID NextTypeID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void WriteSourceManagerBlock(SourceManager &SourceMgr);
 | 
					  void WriteSourceManagerBlock(SourceManager &SourceMgr);
 | 
				
			||||||
  void WritePreprocessor(Preprocessor &PP);
 | 
					  void WritePreprocessor(const Preprocessor &PP);
 | 
				
			||||||
  void WriteType(const Type *T);
 | 
					  void WriteType(const Type *T);
 | 
				
			||||||
  void WriteTypesBlock(ASTContext &Context);
 | 
					  void WriteTypesBlock(ASTContext &Context);
 | 
				
			||||||
  uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
 | 
					  uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
 | 
				
			||||||
| 
						 | 
					@ -92,7 +92,7 @@ public:
 | 
				
			||||||
  PCHWriter(llvm::BitstreamWriter &S);
 | 
					  PCHWriter(llvm::BitstreamWriter &S);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /// \brief Write a precompiled header for the given AST context.
 | 
					  /// \brief Write a precompiled header for the given AST context.
 | 
				
			||||||
  void WritePCH(ASTContext &Context, Preprocessor &PP);
 | 
					  void WritePCH(ASTContext &Context, const Preprocessor &PP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// \brief Emit a source location.
 | 
					  /// \brief Emit a source location.
 | 
				
			||||||
  void AddSourceLocation(SourceLocation Loc, RecordData &Record);
 | 
					  void AddSourceLocation(SourceLocation Loc, RecordData &Record);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -479,7 +479,7 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr) {
 | 
				
			||||||
/// \brief Writes the block containing the serialized form of the
 | 
					/// \brief Writes the block containing the serialized form of the
 | 
				
			||||||
/// preprocessor.
 | 
					/// preprocessor.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
void PCHWriter::WritePreprocessor(Preprocessor &PP) {
 | 
					void PCHWriter::WritePreprocessor(const Preprocessor &PP) {
 | 
				
			||||||
  // Enter the preprocessor block.
 | 
					  // Enter the preprocessor block.
 | 
				
			||||||
  S.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 3);
 | 
					  S.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 3);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
| 
						 | 
					@ -527,7 +527,29 @@ void PCHWriter::WritePreprocessor(Preprocessor &PP) {
 | 
				
			||||||
    S.EmitRecord(Code, Record);
 | 
					    S.EmitRecord(Code, Record);
 | 
				
			||||||
    Record.clear();
 | 
					    Record.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // FIXME: Emit the tokens array.
 | 
					    // Emit the tokens array.
 | 
				
			||||||
 | 
					    for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
 | 
				
			||||||
 | 
					      // Note that we know that the preprocessor does not have any annotation
 | 
				
			||||||
 | 
					      // tokens in it because they are created by the parser, and thus can't be
 | 
				
			||||||
 | 
					      // in a macro definition.
 | 
				
			||||||
 | 
					      const Token &Tok = MI->getReplacementToken(TokNo);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      Record.push_back(Tok.getLocation().getRawEncoding());
 | 
				
			||||||
 | 
					      Record.push_back(Tok.getLength());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // FIXME: Output the identifier Info ID #!
 | 
				
			||||||
 | 
					      // FIXME: When reading literal tokens, reconstruct the literal pointer if
 | 
				
			||||||
 | 
					      // it is needed.
 | 
				
			||||||
 | 
					      Record.push_back((intptr_t)Tok.getIdentifierInfo());
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      // FIXME: Should translate token kind to a stable encoding.
 | 
				
			||||||
 | 
					      Record.push_back(Tok.getKind());
 | 
				
			||||||
 | 
					      // FIXME: Should translate token flags to a stable encoding.
 | 
				
			||||||
 | 
					      Record.push_back(Tok.getFlags());
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      S.EmitRecord(pch::PP_TOKEN, Record);
 | 
				
			||||||
 | 
					      Record.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
| 
						 | 
					@ -719,7 +741,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
 | 
				
			||||||
PCHWriter::PCHWriter(llvm::BitstreamWriter &S) 
 | 
					PCHWriter::PCHWriter(llvm::BitstreamWriter &S) 
 | 
				
			||||||
  : S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
 | 
					  : S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PCHWriter::WritePCH(ASTContext &Context, Preprocessor &PP) {
 | 
					void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
 | 
				
			||||||
  // Emit the file header.
 | 
					  // Emit the file header.
 | 
				
			||||||
  S.Emit((unsigned)'C', 8);
 | 
					  S.Emit((unsigned)'C', 8);
 | 
				
			||||||
  S.Emit((unsigned)'P', 8);
 | 
					  S.Emit((unsigned)'P', 8);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,7 @@ ASTConsumer *CreateASTSerializer(const std::string &InFile,
 | 
				
			||||||
                                 const std::string &EmitDir,
 | 
					                                 const std::string &EmitDir,
 | 
				
			||||||
                                 Diagnostic &Diags);
 | 
					                                 Diagnostic &Diags);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
ASTConsumer *CreatePCHGenerator(Preprocessor &PP,
 | 
					ASTConsumer *CreatePCHGenerator(const Preprocessor &PP,
 | 
				
			||||||
                                const std::string &OutFile);
 | 
					                                const std::string &OutFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ASTConsumer *CreateBlockRewriter(const std::string &InFile,
 | 
					ASTConsumer *CreateBlockRewriter(const std::string &InFile,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,11 +29,11 @@ using namespace llvm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
  class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
 | 
					  class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
 | 
				
			||||||
    Preprocessor &PP;
 | 
					    const Preprocessor &PP;
 | 
				
			||||||
    std::string OutFile;
 | 
					    std::string OutFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    explicit PCHGenerator(Preprocessor &PP, const std::string &OutFile)
 | 
					    explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
 | 
				
			||||||
      : PP(PP), OutFile(OutFile) { }
 | 
					      : PP(PP), OutFile(OutFile) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void HandleTranslationUnit(ASTContext &Ctx);
 | 
					    virtual void HandleTranslationUnit(ASTContext &Ctx);
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,7 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
 | 
				
			||||||
  Out.flush();
 | 
					  Out.flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ASTConsumer *clang::CreatePCHGenerator(Preprocessor &PP,
 | 
					ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP,
 | 
				
			||||||
                                       const std::string &OutFile) {
 | 
					                                       const std::string &OutFile) {
 | 
				
			||||||
  return new PCHGenerator(PP, OutFile);
 | 
					  return new PCHGenerator(PP, OutFile);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue