diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-28 04:27:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-28 04:27:18 +0000 |
commit | a5adead17bb94f8517cd85f28aad57de785feaa1 (patch) | |
tree | e571e82231ded04af224d354792c264ad0d89d94 /clang/lib | |
parent | 72f307a26e85109dacc68887807734a1b72ad6a7 (diff) | |
download | bcm5719-llvm-a5adead17bb94f8517cd85f28aad57de785feaa1.tar.gz bcm5719-llvm-a5adead17bb94f8517cd85f28aad57de785feaa1.zip |
push more ASTContext goodness out through interfaces that use
TranslationUnit
llvm-svn: 67913
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTConsumer.cpp | 1 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 45 | ||||
-rw-r--r-- | clang/lib/AST/TranslationUnit.cpp | 65 | ||||
-rw-r--r-- | clang/lib/Sema/ParseAST.cpp | 1 |
4 files changed, 42 insertions, 70 deletions
diff --git a/clang/lib/AST/ASTConsumer.cpp b/clang/lib/AST/ASTConsumer.cpp index b3919f17714..6c44d1ab7b0 100644 --- a/clang/lib/AST/ASTConsumer.cpp +++ b/clang/lib/AST/ASTConsumer.cpp @@ -13,7 +13,6 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/Decl.h" -#include "clang/AST/TranslationUnit.h" using namespace clang; ASTConsumer::~ASTConsumer() {} diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 9f8630f58fc..f3cf6b18eb0 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -23,6 +23,7 @@ #include "llvm/Bitcode/Serialize.h" #include "llvm/Bitcode/Deserialize.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" using namespace clang; enum FloatingRank { @@ -3086,7 +3087,21 @@ enum { DeclsBlock = 3 }; -void ASTContext::EmitAll(llvm::Serializer &S) const { +void ASTContext::EmitASTBitcodeBuffer(std::vector<unsigned char> &Buffer) const{ + // Create bitstream. + llvm::BitstreamWriter Stream(Buffer); + + // Emit the preamble. + Stream.Emit((unsigned)'B', 8); + Stream.Emit((unsigned)'C', 8); + Stream.Emit(0xC, 4); + Stream.Emit(0xF, 4); + Stream.Emit(0xE, 4); + Stream.Emit(0x0, 4); + + // Create serializer. + llvm::Serializer S(Stream); + // ===---------------------------------------------------===/ // Serialize the "Translation Unit" metadata. // ===---------------------------------------------------===/ @@ -3142,8 +3157,32 @@ void ASTContext::Emit(llvm::Serializer& S) const { // FIXME: S.EmitOwnedPtr(CFConstantStringTypeDecl); } -ASTContext* ASTContext::CreateAll(llvm::Deserializer &Dezr, - FileManager &FMgr) { + +ASTContext *ASTContext::ReadASTBitcodeBuffer(llvm::MemoryBuffer &Buffer, + FileManager &FMgr) { + // Check if the file is of the proper length. + if (Buffer.getBufferSize() & 0x3) { + // FIXME: Provide diagnostic: "Length should be a multiple of 4 bytes." + return 0; + } + + // Create the bitstream reader. + unsigned char *BufPtr = (unsigned char *)Buffer.getBufferStart(); + llvm::BitstreamReader Stream(BufPtr, BufPtr+Buffer.getBufferSize()); + + if (Stream.Read(8) != 'B' || + Stream.Read(8) != 'C' || + Stream.Read(4) != 0xC || + Stream.Read(4) != 0xF || + Stream.Read(4) != 0xE || + Stream.Read(4) != 0x0) { + // FIXME: Provide diagnostic. + return NULL; + } + + // Create the deserializer. + llvm::Deserializer Dezr(Stream); + // ===---------------------------------------------------===/ // Deserialize the "Translation Unit" metadata. // ===---------------------------------------------------===/ diff --git a/clang/lib/AST/TranslationUnit.cpp b/clang/lib/AST/TranslationUnit.cpp index 57f9f4ebc80..0c69432014d 100644 --- a/clang/lib/AST/TranslationUnit.cpp +++ b/clang/lib/AST/TranslationUnit.cpp @@ -29,68 +29,3 @@ using namespace clang; TranslationUnit::~TranslationUnit() { } - -bool clang::EmitASTBitcodeBuffer(const ASTContext &Ctx, - std::vector<unsigned char>& Buffer) { - // Create bitstream. - llvm::BitstreamWriter Stream(Buffer); - - // Emit the preamble. - Stream.Emit((unsigned)'B', 8); - Stream.Emit((unsigned)'C', 8); - Stream.Emit(0xC, 4); - Stream.Emit(0xF, 4); - Stream.Emit(0xE, 4); - Stream.Emit(0x0, 4); - - { - // Create serializer. Placing it in its own scope assures any necessary - // finalization of bits to the buffer in the serializer's dstor. - llvm::Serializer Sezr(Stream); - - // Emit the translation unit. - Ctx.EmitAll(Sezr); - } - - return true; -} - -TranslationUnit* -clang::ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer, FileManager& FMgr) { - - // Check if the file is of the proper length. - if (MBuffer.getBufferSize() & 0x3) { - // FIXME: Provide diagnostic: "Length should be a multiple of 4 bytes." - return NULL; - } - - // Create the bitstream reader. - unsigned char *BufPtr = (unsigned char *) MBuffer.getBufferStart(); - llvm::BitstreamReader Stream(BufPtr,BufPtr+MBuffer.getBufferSize()); - - if (Stream.Read(8) != 'B' || - Stream.Read(8) != 'C' || - Stream.Read(4) != 0xC || - Stream.Read(4) != 0xF || - Stream.Read(4) != 0xE || - Stream.Read(4) != 0x0) { - // FIXME: Provide diagnostic. - return NULL; - } - - // Create the deserializer. - llvm::Deserializer Dezr(Stream); - - return TranslationUnit::Create(Dezr,FMgr); -} - -TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr, - FileManager& FMgr) { - - // Create the translation unit object. - TranslationUnit* TU = new TranslationUnit(); - - TU->Context = ASTContext::CreateAll(Dezr, FMgr); - - return TU; -} diff --git a/clang/lib/Sema/ParseAST.cpp b/clang/lib/Sema/ParseAST.cpp index bcff1c8cfbc..fdc57b6e248 100644 --- a/clang/lib/Sema/ParseAST.cpp +++ b/clang/lib/Sema/ParseAST.cpp @@ -15,7 +15,6 @@ #include "clang/Sema/ParseAST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/Stmt.h" -#include "clang/AST/TranslationUnit.h" #include "Sema.h" #include "clang/Parse/Parser.h" using namespace clang; |