blob: e704dd9544ffc460002702ded5273fd0dcea472c [file] [log] [blame]
Mikhail Glushenkovf9152532008-12-07 16:41:11 +00001//===--- Tool.cpp - The LLVM Compiler Driver --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open
6// Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Tool base class - implementation details.
11//
12//===----------------------------------------------------------------------===//
13
Mikhail Glushenkov7defa2d2009-06-25 18:20:10 +000014#include "llvm/CompilerDriver/BuiltinOptions.h"
Mikhail Glushenkovf9152532008-12-07 16:41:11 +000015#include "llvm/CompilerDriver/Tool.h"
16
17#include "llvm/System/Path.h"
Mikhail Glushenkovf9152532008-12-07 16:41:11 +000018
19using namespace llvm;
20using namespace llvmc;
21
Mikhail Glushenkovf9152532008-12-07 16:41:11 +000022namespace {
23 sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
24 const std::string& Suffix) {
25 sys::Path Out;
26
27 // Make sure we don't end up with path names like '/file.o' if the
28 // TempDir is empty.
29 if (TempDir.empty()) {
30 Out.set(BaseName);
31 }
32 else {
33 Out = TempDir;
34 Out.appendComponent(BaseName);
35 }
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
Mikhail Glushenkov7defa2d2009-06-25 18:20:10 +000040 // they need to be placated with -f or something like that.
Mikhail Glushenkovf9152532008-12-07 16:41:11 +000041 Out.makeUnique(true, NULL);
42 return Out;
43 }
44}
45
46sys::Path Tool::OutFilename(const sys::Path& In,
47 const sys::Path& TempDir,
48 bool StopCompilation,
49 const char* OutputSuffix) const {
50 sys::Path Out;
51
52 if (StopCompilation) {
Mikhail Glushenkov7defa2d2009-06-25 18:20:10 +000053 if (!OutputFilename.empty() && SaveTemps != SaveTempsEnum::Obj ) {
Mikhail Glushenkovf9152532008-12-07 16:41:11 +000054 Out.set(OutputFilename);
55 }
56 else if (IsJoin()) {
57 Out.set("a");
58 Out.appendSuffix(OutputSuffix);
59 }
60 else {
61 Out.set(In.getBasename());
62 Out.appendSuffix(OutputSuffix);
63 }
64 }
65 else {
66 if (IsJoin())
67 Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
68 else
69 Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);
70 }
71 return Out;
72}