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/System/Path.h"
20 using namespace llvmc;
23 sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
24 const std::string& Suffix) {
27 // Make sure we don't end up with path names like '/file.o' if the
29 if (TempDir.empty()) {
34 Out.appendComponent(BaseName);
36 Out.appendSuffix(Suffix);
37 // NOTE: makeUnique always *creates* a unique temporary file,
38 // which is good, since there will be no races. However, some
39 // tools do not like it when the output file already exists, so
40 // they need to be placated with -f or something like that.
41 Out.makeUnique(true, NULL);
46 sys::Path Tool::OutFilename(const sys::Path& In,
47 const sys::Path& TempDir,
49 const char* OutputSuffix) const {
52 if (StopCompilation) {
53 if (!OutputFilename.empty() && SaveTemps != SaveTempsEnum::Obj ) {
54 Out.set(OutputFilename);
58 Out.appendSuffix(OutputSuffix);
61 Out.set(In.getBasename());
62 Out.appendSuffix(OutputSuffix);
67 Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
69 Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);