summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-cc/ASTConsumers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/clang-cc/ASTConsumers.cpp')
-rw-r--r--clang/tools/clang-cc/ASTConsumers.cpp141
1 files changed, 0 insertions, 141 deletions
diff --git a/clang/tools/clang-cc/ASTConsumers.cpp b/clang/tools/clang-cc/ASTConsumers.cpp
index 52aafd35c02..b0f06fad244 100644
--- a/clang/tools/clang-cc/ASTConsumers.cpp
+++ b/clang/tools/clang-cc/ASTConsumers.cpp
@@ -1000,144 +1000,3 @@ public:
ASTConsumer *clang::CreateInheritanceViewer(const std::string& clsname) {
return new InheritanceViewer(clsname);
}
-
-//===----------------------------------------------------------------------===//
-// AST Serializer
-
-namespace {
-
-class ASTSerializer : public ASTConsumer {
-protected:
- Diagnostic& Diags;
-
-public:
- ASTSerializer(Diagnostic& diags) : Diags(diags) {}
-};
-
-class SingleFileSerializer : public ASTSerializer {
- const llvm::sys::Path FName;
-public:
- SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags)
- : ASTSerializer(diags), FName(F) {}
-
- virtual void HandleTranslationUnit(ASTContext &Ctx) {
- if (Diags.hasErrorOccurred())
- return;
-
- // Reserve 256K for bitstream buffer.
- std::vector<unsigned char> Buffer;
- Buffer.reserve(256*1024);
-
- Ctx.EmitASTBitcodeBuffer(Buffer);
-
- // Write the bits to disk.
- if (FILE* fp = fopen(FName.c_str(),"wb")) {
- fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp);
- fclose(fp);
- }
- }
-};
-
-class BuildSerializer : public ASTSerializer {
- llvm::sys::Path EmitDir;
-public:
- BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags)
- : ASTSerializer(diags), EmitDir(dir) {}
-
- virtual void HandleTranslationUnit(ASTContext &Ctx);
-};
-} // end anonymous namespace
-
-
-void BuildSerializer::HandleTranslationUnit(ASTContext &Ctx) {
- if (Diags.hasErrorOccurred())
- return;
-
- SourceManager& SourceMgr = Ctx.getSourceManager();
- FileID ID = SourceMgr.getMainFileID();
- assert(!ID.isInvalid() && "MainFileID not set!");
- const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
- assert(FE && "No FileEntry for main file.");
-
- // FIXME: This is not portable to Windows.
- // FIXME: This logic should probably be moved elsewhere later.
-
- llvm::sys::Path FName(EmitDir);
-
- std::vector<char> buf;
- buf.reserve(strlen(FE->getName())+100);
-
- sprintf(&buf[0], "dev_%llx", (unsigned long long) FE->getDevice());
- FName.appendComponent(&buf[0]);
- FName.createDirectoryOnDisk(true);
- if (!FName.canWrite() || !FName.isDirectory()) {
- assert (false && "Could not create 'device' serialization directory.");
- return;
- }
-
- sprintf(&buf[0], "%s-%llX.ast", FE->getName(),
- (unsigned long long) FE->getInode());
- FName.appendComponent(&buf[0]);
-
-
- // Reserve 256K for bitstream buffer.
- std::vector<unsigned char> Buffer;
- Buffer.reserve(256*1024);
-
- Ctx.EmitASTBitcodeBuffer(Buffer);
-
- // Write the bits to disk.
- if (FILE* fp = fopen(FName.c_str(),"wb")) {
- fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp);
- fclose(fp);
- }
-
- // Now emit the sources.
-
-}
-
-
-ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
- const std::string& OutputFile,
- Diagnostic &Diags) {
-
- if (OutputFile.size()) {
- if (InFile == "-") {
- llvm::cerr <<
- "error: Cannot use --serialize with -o for source read from STDIN.\n";
- return NULL;
- }
-
- // The user specified an AST-emission directory. Determine if the path
- // is absolute.
- llvm::sys::Path EmitDir(OutputFile);
-
- if (!EmitDir.isAbsolute()) {
- llvm::cerr <<
- "error: Output directory for --serialize must be an absolute path.\n";
-
- return NULL;
- }
-
- // Create the directory if it does not exist.
- EmitDir.createDirectoryOnDisk(true);
- if (!EmitDir.canWrite() || !EmitDir.isDirectory()) {
- llvm::cerr <<
- "error: Could not create output directory for --serialize.\n";
-
- return NULL;
- }
-
- // FIXME: We should probably only allow using BuildSerializer when
- // the ASTs come from parsed source files, and not from .ast files.
- return new BuildSerializer(EmitDir, Diags);
- }
-
- // The user did not specify an output directory for serialized ASTs.
- // Serialize the translation to a single file whose name is the same
- // as the input file with the ".ast" extension appended.
-
- llvm::sys::Path FName(InFile.c_str());
- FName.appendSuffix("ast");
- return new SingleFileSerializer(FName, Diags);
-}
OpenPOWER on IntegriCloud