From: Ted Kremenek Date: Thu, 13 Dec 2007 17:50:11 +0000 (+0000) Subject: Changed -serialize-ast to not create a temporary directory, but instead X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3821d401a3f338aef5e80a83e5b0214c4160d9ce;p=clang Changed -serialize-ast to not create a temporary directory, but instead create a .ast file in the current working directory. This mirrors the behavior of the -c option for gcc. Later we should add the ability to write the serialized file anywhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45004 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 41d73ec289..38622a4862 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -552,7 +552,6 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) { #include "llvm/Module.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" -#include namespace { class LLVMEmitter : public ASTConsumer { @@ -596,7 +595,7 @@ namespace { CodeGen::Terminate(Builder); // Print the generated code. - M->print(std::cout); + M->print(llvm::cout.stream()); delete M; } }; diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 8c08d7cadc..8a6d132684 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -856,15 +856,16 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, case SerializeAST: { // FIXME: Allow user to tailor where the file is written. - llvm::sys::Path FName = llvm::sys::Path::GetTemporaryDirectory(NULL); - FName.appendComponent((InFile + ".ast").c_str()); + // FIXME: This is a hack: "/" separator not portable. + std::string::size_type idx = InFile.rfind("/"); - if (FName.makeUnique(true,NULL)) { - fprintf (stderr, "error: cannot create serialized file: '%s'\n", - FName.c_str()); - + if (idx != std::string::npos && idx == InFile.size()-1) return NULL; - } + + std::string TargetPrefix( idx == std::string::npos ? + InFile : InFile.substr(idx+1)); + + llvm::sys::Path FName = llvm::sys::Path((TargetPrefix + ".ast").c_str()); return CreateASTSerializer(FName, Diag, LangOpts); }