aboutsummaryrefslogtreecommitdiff
path: root/tools/llvmc/driver/Tool.cpp
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-12-07 16:41:11 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-12-07 16:41:11 +0000
commitf915253dfcfbe772ee04872544a4f012c6f851be (patch)
tree37804c93f492340cbffe03d4f709e34d9e1d99e2 /tools/llvmc/driver/Tool.cpp
parent6290f5cac23399201f8785e5ca8b305e42a1342c (diff)
Use (actions) instead of option properties, support external options.
Also includes a major refactoring. See documentation for more information. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvmc/driver/Tool.cpp')
-rw-r--r--tools/llvmc/driver/Tool.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/llvmc/driver/Tool.cpp b/tools/llvmc/driver/Tool.cpp
new file mode 100644
index 0000000000..886b26b5d7
--- /dev/null
+++ b/tools/llvmc/driver/Tool.cpp
@@ -0,0 +1,74 @@
+//===--- Tool.cpp - The LLVM Compiler Driver --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Tool base class - implementation details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CompilerDriver/Tool.h"
+
+#include "llvm/System/Path.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace llvmc;
+
+extern cl::opt<std::string> OutputFilename;
+
+namespace {
+ sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
+ const std::string& Suffix) {
+ sys::Path Out;
+
+ // Make sure we don't end up with path names like '/file.o' if the
+ // TempDir is empty.
+ if (TempDir.empty()) {
+ Out.set(BaseName);
+ }
+ else {
+ Out = TempDir;
+ Out.appendComponent(BaseName);
+ }
+ Out.appendSuffix(Suffix);
+ // NOTE: makeUnique always *creates* a unique temporary file,
+ // which is good, since there will be no races. However, some
+ // tools do not like it when the output file already exists, so
+ // they have to be placated with -f or something like that.
+ Out.makeUnique(true, NULL);
+ return Out;
+ }
+}
+
+sys::Path Tool::OutFilename(const sys::Path& In,
+ const sys::Path& TempDir,
+ bool StopCompilation,
+ const char* OutputSuffix) const {
+ sys::Path Out;
+
+ if (StopCompilation) {
+ if (!OutputFilename.empty()) {
+ Out.set(OutputFilename);
+ }
+ else if (IsJoin()) {
+ Out.set("a");
+ Out.appendSuffix(OutputSuffix);
+ }
+ else {
+ Out.set(In.getBasename());
+ Out.appendSuffix(OutputSuffix);
+ }
+ }
+ else {
+ if (IsJoin())
+ Out = MakeTempFile(TempDir, "tmp", OutputSuffix);
+ else
+ Out = MakeTempFile(TempDir, In.getBasename(), OutputSuffix);
+ }
+ return Out;
+}