[llvm-commits] [llvm] r74190 - in /llvm/trunk: include/llvm/CompilerDriver/BuiltinOptions.h include/llvm/CompilerDriver/Main.inc lib/CompilerDriver/Action.cpp lib/CompilerDriver/CompilationGraph.cpp lib/CompilerDriver/Tool.cpp
Mikhail Glushenkov
foldr at codedgers.com
Thu Jun 25 11:20:11 PDT 2009
Author: foldr
Date: Thu Jun 25 13:20:10 2009
New Revision: 74190
URL: http://llvm.org/viewvc/llvm-project?rev=74190&view=rev
Log:
Make -save-temps behave like in GCC 4.5.
The -save-temps option now behaves like described in GCC 4.5 release notes
(you can specify output directory for temporary files with -save-temps=obj
-o $DIRNAME). I do not have GCC 4.5 installed, so if there are any
inconsistencies between llvmc and GCC in the implementation of this
feature, please let me know.
Added:
llvm/trunk/include/llvm/CompilerDriver/BuiltinOptions.h
Modified:
llvm/trunk/include/llvm/CompilerDriver/Main.inc
llvm/trunk/lib/CompilerDriver/Action.cpp
llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp
llvm/trunk/lib/CompilerDriver/Tool.cpp
Added: llvm/trunk/include/llvm/CompilerDriver/BuiltinOptions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/BuiltinOptions.h?rev=74190&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/BuiltinOptions.h (added)
+++ llvm/trunk/include/llvm/CompilerDriver/BuiltinOptions.h Thu Jun 25 13:20:10 2009
@@ -0,0 +1,33 @@
+//===--- BuiltinOptions.h - The LLVM Compiler Driver ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Declarations of all global command-line option variables.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H
+#define LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H
+
+#include "llvm/Support/CommandLine.h"
+
+#include <string>
+
+namespace SaveTempsEnum { enum Values { Cwd, Obj, Unset }; }
+
+extern llvm::cl::list<std::string> InputFilenames;
+extern llvm::cl::opt<std::string> OutputFilename;
+extern llvm::cl::list<std::string> Languages;
+extern llvm::cl::opt<bool> DryRun;
+extern llvm::cl::opt<bool> VerboseMode;
+extern llvm::cl::opt<bool> CheckGraph;
+extern llvm::cl::opt<bool> WriteGraph;
+extern llvm::cl::opt<bool> ViewGraph;
+extern llvm::cl::opt<SaveTempsEnum::Values> SaveTemps;
+
+#endif // LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H
Modified: llvm/trunk/include/llvm/CompilerDriver/Main.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Main.inc?rev=74190&r1=74189&r2=74190&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Main.inc (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Main.inc Thu Jun 25 13:20:10 2009
@@ -17,6 +17,7 @@
#ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
#define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
+#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/CompilationGraph.h"
#include "llvm/CompilerDriver/Error.h"
#include "llvm/CompilerDriver/ForceLinkage.h"
@@ -58,27 +59,56 @@
cl::opt<bool> ViewGraph("view-graph",
cl::desc("Show compilation graph in GhostView"),
cl::Hidden);
-cl::opt<bool> SaveTemps("save-temps",
- cl::desc("Keep temporary files"),
- cl::Hidden);
+
+cl::opt<SaveTempsEnum::Values> SaveTemps
+("save-temps", cl::desc("Keep temporary files"),
+ cl::init(SaveTempsEnum::Unset),
+ cl::values(clEnumValN(SaveTempsEnum::Obj, "obj",
+ "Save files in the directory specified with -o"),
+ clEnumValN(SaveTempsEnum::Cwd, "cwd",
+ "Use current working directory"),
+ clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"),
+ clEnumValEnd),
+ cl::ValueOptional);
namespace {
+
+ sys::Path getTempDir() {
+ sys::Path tempDir;
+
+ // GCC 4.5-style -save-temps handling.
+ if (SaveTemps == SaveTempsEnum::Unset) {
+ tempDir = sys::Path::GetTemporaryDirectory();
+ }
+ else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
+ tempDir = OutputFilename;
+
+ if (!tempDir.exists()) {
+ std::string ErrMsg;
+ if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
+ throw std::runtime_error(ErrMsg);
+ }
+ }
+ // else if (SaveTemps == Cwd) -> use current dir (leave tempDir empty)
+
+ return tempDir;
+ }
+
/// BuildTargets - A small wrapper for CompilationGraph::Build.
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret;
- const sys::Path& tempDir = SaveTemps
- ? sys::Path("")
- : sys::Path(sys::Path::GetTemporaryDirectory());
+ const sys::Path& tempDir = getTempDir();
try {
ret = graph.Build(tempDir, langMap);
}
catch(...) {
- tempDir.eraseFromDisk(true);
+ if (SaveTemps == SaveTempsEnum::Unset)
+ tempDir.eraseFromDisk(true);
throw;
}
- if (!SaveTemps)
+ if (SaveTemps == SaveTempsEnum::Unset)
tempDir.eraseFromDisk(true);
return ret;
}
Modified: llvm/trunk/lib/CompilerDriver/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Action.cpp?rev=74190&r1=74189&r2=74190&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/Action.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/Action.cpp Thu Jun 25 13:20:10 2009
@@ -12,8 +12,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/CompilerDriver/Action.h"
+#include "llvm/CompilerDriver/BuiltinOptions.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/System/Program.h"
#include <iostream>
@@ -22,9 +22,6 @@
using namespace llvm;
using namespace llvmc;
-extern cl::opt<bool> DryRun;
-extern cl::opt<bool> VerboseMode;
-
namespace {
int ExecuteProgram(const std::string& name,
const StrVector& args) {
Modified: llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp?rev=74190&r1=74189&r2=74190&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp Thu Jun 25 13:20:10 2009
@@ -11,11 +11,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/CompilationGraph.h"
#include "llvm/CompilerDriver/Error.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/GraphWriter.h"
@@ -30,9 +30,6 @@
using namespace llvm;
using namespace llvmc;
-extern cl::list<std::string> InputFilenames;
-extern cl::list<std::string> Languages;
-
namespace llvmc {
const std::string& LanguageMap::GetLanguage(const sys::Path& File) const {
@@ -477,7 +474,7 @@
{
template<typename GraphType>
- static std::string getNodeLabel(const Node* N, const GraphType&,
+ static std::string getNodeLabel(const Node* N, const GraphType&,
bool ShortNames)
{
if (N->ToolPtr)
Modified: llvm/trunk/lib/CompilerDriver/Tool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Tool.cpp?rev=74190&r1=74189&r2=74190&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/Tool.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/Tool.cpp Thu Jun 25 13:20:10 2009
@@ -11,16 +11,14 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/Tool.h"
#include "llvm/System/Path.h"
-#include "llvm/Support/CommandLine.h"
using namespace llvm;
using namespace llvmc;
-extern cl::opt<std::string> OutputFilename;
-
namespace {
sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
const std::string& Suffix) {
@@ -39,7 +37,7 @@
// NOTE: makeUnique always *creates* a unique temporary file,
// which is good, since there will be no races. However, some
// tools do not like it when the output file already exists, so
- // they have to be placated with -f or something like that.
+ // they need to be placated with -f or something like that.
Out.makeUnique(true, NULL);
return Out;
}
@@ -52,7 +50,7 @@
sys::Path Out;
if (StopCompilation) {
- if (!OutputFilename.empty()) {
+ if (!OutputFilename.empty() && SaveTemps != SaveTempsEnum::Obj ) {
Out.set(OutputFilename);
}
else if (IsJoin()) {
More information about the llvm-commits
mailing list