Make handling of conditional stuff much more straightforward
[llvm/msp430.git] / lib / CompilerDriver / Tool.cpp
blob886b26b5d713f0d5764e296c93b42bc0fde243de
1 //===--- 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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CompilerDriver/Tool.h"
16 #include "llvm/System/Path.h"
17 #include "llvm/Support/CommandLine.h"
19 using namespace llvm;
20 using namespace llvmc;
22 extern cl::opt<std::string> OutputFilename;
24 namespace {
25 sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
26 const std::string& Suffix) {
27 sys::Path Out;
29 // Make sure we don't end up with path names like '/file.o' if the
30 // TempDir is empty.
31 if (TempDir.empty()) {
32 Out.set(BaseName);
34 else {
35 Out = TempDir;
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);
44 return Out;
48 sys::Path Tool::OutFilename(const sys::Path& In,
49 const sys::Path& TempDir,
50 bool StopCompilation,
51 const char* OutputSuffix) const {
52 sys::Path Out;
54 if (StopCompilation) {
55 if (!OutputFilename.empty()) {
56 Out.set(OutputFilename);
58 else if (IsJoin()) {
59 Out.set("a");
60 Out.appendSuffix(OutputSuffix);
62 else {
63 Out.set(In.getBasename());
64 Out.appendSuffix(OutputSuffix);
67 else {
68 if (IsJoin())
69 Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
70 else
71 Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);
73 return Out;