1 //===--- Tool.cpp - The LLVM Compiler Driver --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Tool base class - implementation details.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CompilerDriver/Tool.h"
16 #include "llvm/System/Path.h"
17 #include "llvm/Support/CommandLine.h"
20 using namespace llvmc;
22 extern cl::opt<std::string> OutputFilename;
25 sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
26 const std::string& Suffix) {
29 // Make sure we don't end up with path names like '/file.o' if the
31 if (TempDir.empty()) {
36 Out.appendComponent(BaseName);
38 Out.appendSuffix(Suffix);
39 // NOTE: makeUnique always *creates* a unique temporary file,
40 // which is good, since there will be no races. However, some
41 // tools do not like it when the output file already exists, so
42 // they have to be placated with -f or something like that.
43 Out.makeUnique(true, NULL);
48 sys::Path Tool::OutFilename(const sys::Path& In,
49 const sys::Path& TempDir,
51 const char* OutputSuffix) const {
54 if (StopCompilation) {
55 if (!OutputFilename.empty()) {
56 Out.set(OutputFilename);
60 Out.appendSuffix(OutputSuffix);
63 Out.set(In.getBasename());
64 Out.appendSuffix(OutputSuffix);
69 Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
71 Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);