]> granicus.if.org Git - clang/commitdiff
Changed -serialize-ast to not create a temporary directory, but instead
authorTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 17:50:11 +0000 (17:50 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 17:50:11 +0000 (17:50 +0000)
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

Driver/ASTConsumers.cpp
Driver/clang.cpp

index 41d73ec289f86b4d92e958cb51b1b3d4d6f591dd..38622a4862d4e5df9d51248c4e2fe203e3b6d629 100644 (file)
@@ -552,7 +552,6 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) {
 #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 @@ namespace {
       CodeGen::Terminate(Builder);
       
       // Print the generated code.
-      M->print(std::cout);
+      M->print(llvm::cout.stream());
       delete M;
     }
   }; 
index 8c08d7cadc3aa561c5491482985f5142060f873c..8a6d1326842f2926f7c8fef92189b38591d4a394 100644 (file)
@@ -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);
     }