diff --git a/clang/Driver/ASTConsumers.cpp b/clang/Driver/ASTConsumers.cpp index 49bf59b8832d..184f29a6061f 100644 --- a/clang/Driver/ASTConsumers.cpp +++ b/clang/Driver/ASTConsumers.cpp @@ -637,8 +637,20 @@ namespace { } // end anonymous namespace -ASTConsumer *clang::CreateASTSerializer(const llvm::sys::Path& FName, +ASTConsumer* clang::CreateASTSerializer(const std::string& InFile, Diagnostic &Diags, const LangOptions &Features) { + + // FIXME: This is a hack: "/" separator not portable. + std::string::size_type idx = InFile.rfind("/"); + + 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 new ASTSerializer(FName, Diags, Features); } diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 027370f708d8..05473b155852 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -37,7 +37,7 @@ ASTConsumer *CreateCodeRewriterTest(Diagnostic &Diags); ASTConsumer *CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr, const LangOptions &LOpts); -ASTConsumer *CreateASTSerializer(const llvm::sys::Path& FName, +ASTConsumer *CreateASTSerializer(const std::string& InFile, Diagnostic &Diags, const LangOptions &LOpts); } // end clang namespace diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index d440aad6a271..8afd71833fd3 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -922,21 +922,9 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, case EmitLLVM: return CreateLLVMEmitter(Diag, LangOpts); - case SerializeAST: { + case SerializeAST: // FIXME: Allow user to tailor where the file is written. - // FIXME: This is a hack: "/" separator not portable. - std::string::size_type idx = InFile.rfind("/"); - - 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); - } + return CreateASTSerializer(InFile, Diag, LangOpts); case RewriteTest: return CreateCodeRewriterTest(Diag);