summaryrefslogtreecommitdiffstats
path: root/lib/CompilerDriver
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CompilerDriver')
-rw-r--r--lib/CompilerDriver/BuiltinOptions.cpp2
-rw-r--r--lib/CompilerDriver/CompilationGraph.cpp6
-rw-r--r--lib/CompilerDriver/Main.cpp28
-rw-r--r--lib/CompilerDriver/Plugin.cpp8
-rw-r--r--lib/CompilerDriver/Tool.cpp2
5 files changed, 29 insertions, 17 deletions
diff --git a/lib/CompilerDriver/BuiltinOptions.cpp b/lib/CompilerDriver/BuiltinOptions.cpp
index a3364e8..d90c50d 100644
--- a/lib/CompilerDriver/BuiltinOptions.cpp
+++ b/lib/CompilerDriver/BuiltinOptions.cpp
@@ -25,6 +25,8 @@ cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
cl::ZeroOrMore);
cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
cl::value_desc("file"), cl::Prefix);
+cl::opt<std::string> TempDirname("temp-dir", cl::desc("Temp dir name"),
+ cl::value_desc("<directory>"), cl::Prefix);
cl::list<std::string> Languages("x",
cl::desc("Specify the language of the following input files"),
cl::ZeroOrMore);
diff --git a/lib/CompilerDriver/CompilationGraph.cpp b/lib/CompilerDriver/CompilationGraph.cpp
index f303943..bb0eb7b 100644
--- a/lib/CompilerDriver/CompilationGraph.cpp
+++ b/lib/CompilerDriver/CompilationGraph.cpp
@@ -514,13 +514,13 @@ namespace llvm {
}
void CompilationGraph::writeGraph(const std::string& OutputFilename) {
- std::ofstream O(OutputFilename.c_str());
+ std::string ErrorInfo;
+ raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo);
- if (O.good()) {
+ if (ErrorInfo.empty()) {
errs() << "Writing '"<< OutputFilename << "' file...";
llvm::WriteGraph(O, this);
errs() << "done.\n";
- O.close();
}
else {
throw std::runtime_error("Error opening file '" + OutputFilename
diff --git a/lib/CompilerDriver/Main.cpp b/lib/CompilerDriver/Main.cpp
index c9c0413..3e1fc9f 100644
--- a/lib/CompilerDriver/Main.cpp
+++ b/lib/CompilerDriver/Main.cpp
@@ -31,20 +31,29 @@ namespace {
sys::Path getTempDir() {
sys::Path tempDir;
+ // The --temp-dir option.
+ if (!TempDirname.empty()) {
+ tempDir = TempDirname;
+ }
// GCC 4.5-style -save-temps handling.
- if (SaveTemps == SaveTempsEnum::Unset) {
+ else if (SaveTemps == SaveTempsEnum::Unset) {
tempDir = sys::Path::GetTemporaryDirectory();
+ return tempDir;
}
else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
tempDir = OutputFilename;
+ tempDir = tempDir.getDirname();
+ }
+ else {
+ // SaveTemps == Cwd --> use current dir (leave tempDir empty).
+ return tempDir;
+ }
- if (!tempDir.exists()) {
- std::string ErrMsg;
- if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
- throw std::runtime_error(ErrMsg);
- }
+ 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;
}
@@ -53,17 +62,18 @@ namespace {
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret;
const sys::Path& tempDir = getTempDir();
+ bool toDelete = (SaveTemps == SaveTempsEnum::Unset);
try {
ret = graph.Build(tempDir, langMap);
}
catch(...) {
- if (SaveTemps == SaveTempsEnum::Unset)
+ if (toDelete)
tempDir.eraseFromDisk(true);
throw;
}
- if (SaveTemps == SaveTempsEnum::Unset)
+ if (toDelete)
tempDir.eraseFromDisk(true);
return ret;
}
diff --git a/lib/CompilerDriver/Plugin.cpp b/lib/CompilerDriver/Plugin.cpp
index cb3c7be..7310d12 100644
--- a/lib/CompilerDriver/Plugin.cpp
+++ b/lib/CompilerDriver/Plugin.cpp
@@ -42,7 +42,7 @@ namespace {
namespace llvmc {
PluginLoader::PluginLoader() {
- llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex);
+ llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
if (!pluginListInitialized) {
for (PluginRegistry::iterator B = PluginRegistry::begin(),
E = PluginRegistry::end(); B != E; ++B)
@@ -53,7 +53,7 @@ namespace llvmc {
}
PluginLoader::~PluginLoader() {
- llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex);
+ llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
if (pluginListInitialized) {
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B)
@@ -63,14 +63,14 @@ namespace llvmc {
}
void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) {
- llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex);
+ llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B)
(*B)->PopulateLanguageMap(langMap);
}
void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
- llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex);
+ llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B)
(*B)->PopulateCompilationGraph(graph);
diff --git a/lib/CompilerDriver/Tool.cpp b/lib/CompilerDriver/Tool.cpp
index 7953dd2..5a32fd3 100644
--- a/lib/CompilerDriver/Tool.cpp
+++ b/lib/CompilerDriver/Tool.cpp
@@ -56,7 +56,7 @@ sys::Path Tool::OutFilename(const sys::Path& In,
sys::Path Out;
if (StopCompilation) {
- if (!OutputFilename.empty() && SaveTemps != SaveTempsEnum::Obj ) {
+ if (!OutputFilename.empty()) {
Out.set(OutputFilename);
}
else if (IsJoin()) {
OpenPOWER on IntegriCloud