[cfe-commits] r67913 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/TranslationUnit.h lib/AST/ASTConsumer.cpp lib/AST/ASTContext.cpp lib/AST/TranslationUnit.cpp lib/Sema/ParseAST.cpp tools/clang-cc/ASTConsumers.cpp tools/clang-cc/Backend.cpp tools/clang-cc/SerializationTest.cpp tools/clang-cc/clang.cpp
Chris Lattner
sabre at nondot.org
Fri Mar 27 21:27:18 PDT 2009
Author: lattner
Date: Fri Mar 27 23:27:18 2009
New Revision: 67913
URL: http://llvm.org/viewvc/llvm-project?rev=67913&view=rev
Log:
push more ASTContext goodness out through interfaces that use
TranslationUnit
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/TranslationUnit.h
cfe/trunk/lib/AST/ASTConsumer.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/TranslationUnit.cpp
cfe/trunk/lib/Sema/ParseAST.cpp
cfe/trunk/tools/clang-cc/ASTConsumers.cpp
cfe/trunk/tools/clang-cc/Backend.cpp
cfe/trunk/tools/clang-cc/SerializationTest.cpp
cfe/trunk/tools/clang-cc/clang.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Mar 27 23:27:18 2009
@@ -676,12 +676,12 @@
// Serialization
//===--------------------------------------------------------------------===//
- void EmitAll(llvm::Serializer& S) const;
- static ASTContext* CreateAll(llvm::Deserializer &D,
- FileManager &FMgr);
+ void EmitASTBitcodeBuffer(std::vector<unsigned char> &Buffer) const;
+ static ASTContext *ReadASTBitcodeBuffer(llvm::MemoryBuffer &MBuffer,
+ FileManager &FMgr);
void Emit(llvm::Serializer& S) const;
- static ASTContext* Create(llvm::Deserializer& D);
+ static ASTContext *Create(llvm::Deserializer& D);
//===--------------------------------------------------------------------===//
// Integer Values
Modified: cfe/trunk/include/clang/AST/TranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TranslationUnit.h?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TranslationUnit.h (original)
+++ cfe/trunk/include/clang/AST/TranslationUnit.h Fri Mar 27 23:27:18 2009
@@ -45,7 +45,7 @@
const std::string& getSourceFile() const;
/// Create - Reconsititute a translation unit from a bitcode stream.
- static TranslationUnit* Create(llvm::Deserializer& D, FileManager& FMgr);
+ //static TranslationUnit* Create(llvm::Deserializer& D, FileManager& FMgr);
// Accessors
const LangOptions& getLangOptions() const { return Context->getLangOptions();}
@@ -60,15 +60,6 @@
iterator end() const { return Context->getTranslationUnitDecl()->decls_end(); }
};
-/// EmitASTBitcodeBuffer - Emit a translation unit to a buffer.
-bool EmitASTBitcodeBuffer(const ASTContext &Ctx,
- std::vector<unsigned char>& Buffer);
-
-/// ReadASTBitcodeBuffer - Reconsitute a translation unit from a buffer.
-TranslationUnit* ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer,
- FileManager& FMgr);
-
-
} // end namespace clang
#endif
Modified: cfe/trunk/lib/AST/ASTConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTConsumer.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTConsumer.cpp (original)
+++ cfe/trunk/lib/AST/ASTConsumer.cpp Fri Mar 27 23:27:18 2009
@@ -13,7 +13,6 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Decl.h"
-#include "clang/AST/TranslationUnit.h"
using namespace clang;
ASTConsumer::~ASTConsumer() {}
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Mar 27 23:27:18 2009
@@ -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 @@
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 @@
// 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.
// ===---------------------------------------------------===/
Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Fri Mar 27 23:27:18 2009
@@ -29,68 +29,3 @@
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;
-}
Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Fri Mar 27 23:27:18 2009
@@ -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;
Modified: cfe/trunk/tools/clang-cc/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/ASTConsumers.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/ASTConsumers.cpp (original)
+++ cfe/trunk/tools/clang-cc/ASTConsumers.cpp Fri Mar 27 23:27:18 2009
@@ -13,18 +13,18 @@
#include "ASTConsumers.h"
#include "clang/Frontend/PathDiagnosticClients.h"
-#include "clang/AST/TranslationUnit.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "llvm/Module.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
-
+#include "llvm/System/Path.h"
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -981,7 +981,7 @@
std::vector<unsigned char> Buffer;
Buffer.reserve(256*1024);
- EmitASTBitcodeBuffer(Ctx, Buffer);
+ Ctx.EmitASTBitcodeBuffer(Buffer);
// Write the bits to disk.
if (FILE* fp = fopen(FName.c_str(),"wb")) {
@@ -1032,7 +1032,7 @@
std::vector<unsigned char> Buffer;
Buffer.reserve(256*1024);
- EmitASTBitcodeBuffer(Ctx, Buffer);
+ Ctx.EmitASTBitcodeBuffer(Buffer);
// Write the bits to disk.
if (FILE* fp = fopen(FName.c_str(),"wb")) {
Modified: cfe/trunk/tools/clang-cc/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Backend.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/Backend.cpp (original)
+++ cfe/trunk/tools/clang-cc/Backend.cpp Fri Mar 27 23:27:18 2009
@@ -10,7 +10,6 @@
#include "ASTConsumers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/TranslationUnit.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "clang/Frontend/CompileOptions.h"
Modified: cfe/trunk/tools/clang-cc/SerializationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/SerializationTest.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/SerializationTest.cpp (original)
+++ cfe/trunk/tools/clang-cc/SerializationTest.cpp Fri Mar 27 23:27:18 2009
@@ -81,7 +81,7 @@
std::vector<unsigned char> Buffer;
Buffer.reserve(256*1024);
- EmitASTBitcodeBuffer(Ctx, Buffer);
+ Ctx.EmitASTBitcodeBuffer(Buffer);
// Write the bits to disk.
if (FILE* fp = fopen(Filename.c_str(),"wb")) {
@@ -97,7 +97,7 @@
llvm::sys::Path& FNameDeclPrint) {
// Deserialize the translation unit.
- TranslationUnit* NewTU;
+ ASTContext *NewCtx;
{
// Create the memory buffer that contains the contents of the file.
@@ -107,10 +107,10 @@
if (!MBuffer)
return false;
- NewTU = ReadASTBitcodeBuffer(*MBuffer, FMgr);
+ NewCtx = ASTContext::ReadASTBitcodeBuffer(*MBuffer, FMgr);
}
- if (!NewTU)
+ if (!NewCtx)
return false;
{
@@ -120,11 +120,13 @@
assert (Err.empty() && "Could not open file for printing out decls.");
llvm::OwningPtr<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP));
- for (TranslationUnit::iterator I=NewTU->begin(), E=NewTU->end(); I!=E; ++I)
+ TranslationUnitDecl *TUD = NewCtx->getTranslationUnitDecl();
+ for (DeclContext::decl_iterator I = TUD->decls_begin(), E = TUD->decls_end();
+ I != E; ++I)
FilePrinter->HandleTopLevelDecl(*I);
}
- delete NewTU;
+ delete NewCtx;
return true;
}
Modified: cfe/trunk/tools/clang-cc/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang.cpp?rev=67913&r1=67912&r2=67913&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang.cpp Fri Mar 27 23:27:18 2009
@@ -1531,16 +1531,16 @@
exit (1);
}
- llvm::OwningPtr<TranslationUnit> TU;
+ llvm::OwningPtr<ASTContext> Ctx;
// Create the memory buffer that contains the contents of the file.
llvm::OwningPtr<llvm::MemoryBuffer>
MBuffer(llvm::MemoryBuffer::getFile(Filename.c_str()));
if (MBuffer)
- TU.reset(ReadASTBitcodeBuffer(*MBuffer, FileMgr));
+ Ctx.reset(ASTContext::ReadASTBitcodeBuffer(*MBuffer, FileMgr));
- if (!TU) {
+ if (!Ctx) {
fprintf(stderr, "error: file '%s' could not be deserialized\n",
InFile.c_str());
exit (1);
@@ -1549,7 +1549,7 @@
// Observe that we use the source file name stored in the deserialized
// translation unit, rather than InFile.
llvm::OwningPtr<ASTConsumer>
- Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOptions(),
+ Consumer(CreateASTConsumer(InFile, Diag, FileMgr, Ctx->getLangOptions(),
0, 0));
if (!Consumer) {
@@ -1557,10 +1557,12 @@
exit (1);
}
- Consumer->Initialize(TU->getContext());
+ Consumer->Initialize(*Ctx);
// FIXME: We need to inform Consumer about completed TagDecls as well.
- for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
+ TranslationUnitDecl *TUD = Ctx->getTranslationUnitDecl();
+ for (DeclContext::decl_iterator I = TUD->decls_begin(), E = TUD->decls_end();
+ I != E; ++I)
Consumer->HandleTopLevelDecl(*I);
}
More information about the cfe-commits
mailing list