[cfe-commits] r45241 - /cfe/trunk/Driver/ASTConsumers.cpp
Ted Kremenek
kremenek at apple.com
Wed Dec 19 16:34:58 PST 2007
Author: kremenek
Date: Wed Dec 19 18:34:58 2007
New Revision: 45241
URL: http://llvm.org/viewvc/llvm-project?rev=45241&view=rev
Log:
Created initial implementation of "BuildSerializer", and ASTConsumer
which serializes ASTs to a common output directory. This ASTConsumer
is invoked using a combination of "-o" and "-serialize" from the driver.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=45241&r1=45240&r2=45241&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Dec 19 18:34:58 2007
@@ -13,6 +13,8 @@
#include "ASTConsumers.h"
#include "clang/AST/TranslationUnit.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/FileManager.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/CFG.h"
@@ -651,7 +653,34 @@
const LangOptions &LO)
: ASTSerializer(diags,LO), EmitDir(dir) {}
- ~BuildSerializer() { assert (false && "not implemented."); }
+ ~BuildSerializer() {
+ SourceManager& SourceMgr = TU.getASTContext()->getSourceManager();
+ unsigned ID = SourceMgr.getMainFileID();
+ assert (ID && "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 ASTFile(EmitDir);
+
+ std::vector<char> buf;
+ buf.reserve(strlen(FE->getName())+100);
+
+ sprintf(&buf[0], "dev_%llx", (uint64_t) FE->getDevice());
+ ASTFile.appendComponent(&buf[0]);
+ ASTFile.createDirectoryOnDisk(true);
+ if (!ASTFile.canWrite() || !ASTFile.isDirectory()) {
+ assert (false && "Could not create 'device' serialization directory.");
+ return;
+ }
+
+ sprintf(&buf[0], "%s-%llX.ast", FE->getName(), (uint64_t) FE->getInode());
+ ASTFile.appendComponent(&buf[0]);
+
+ EmitASTBitcodeFile(TU,ASTFile);
+ }
};
@@ -664,6 +693,12 @@
const LangOptions &Features) {
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);
@@ -684,6 +719,8 @@
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, Features);
}
@@ -692,6 +729,6 @@
// as the input file with the ".ast" extension appended.
llvm::sys::Path FName(InFile.c_str());
- FName.appendComponent("ast");
+ FName.appendSuffix("ast");
return new SingleFileSerializer(FName, Diags, Features);
}
More information about the cfe-commits
mailing list