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 41d73ec..38622a4 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -552,7 +552,6 @@
#include "llvm/Module.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
-#include <iostream>
namespace {
class LLVMEmitter : public ASTConsumer {
@@ -596,7 +595,7 @@
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 8c08d7c..8a6d132 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -856,15 +856,16 @@
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);
}