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/BuiltinOptions.h"
15 #include "llvm/CompilerDriver/Tool.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/System/Path.h"
21 using namespace llvmc;
24 sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
25 const std::string& Suffix) {
28 // Make sure we don't end up with path names like '/file.o' if the
30 if (TempDir.empty()) {
35 Out.appendComponent(BaseName);
37 Out.appendSuffix(Suffix);
38 // NOTE: makeUnique always *creates* a unique temporary file,
39 // which is good, since there will be no races. However, some
40 // tools do not like it when the output file already exists, so
41 // they need to be placated with -f or something like that.
42 Out.makeUnique(true, NULL);
47 sys::Path Tool::OutFilename(const sys::Path& In,
48 const sys::Path& TempDir,
50 const char* OutputSuffix) const {
53 if (StopCompilation) {
54 if (!OutputFilename.empty()) {
55 Out.set(OutputFilename);
59 Out.appendSuffix(OutputSuffix);
62 Out.set(In.getBasename());
63 Out.appendSuffix(OutputSuffix);
68 Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
70 Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);