summaryrefslogtreecommitdiffstats
path: root/lld/Common/Reproduce.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-10-02 21:00:41 +0000
committerRui Ueyama <ruiu@google.com>2017-10-02 21:00:41 +0000
commit3f851704c154b8ab045b5cd58d31ce854b9c6599 (patch)
treec0ec0a73ce767fcafa800c49494935ef986be7e7 /lld/Common/Reproduce.cpp
parente2ff2ba57d64a740095737866f0787e6f2c1e410 (diff)
downloadbcm5719-llvm-3f851704c154b8ab045b5cd58d31ce854b9c6599.tar.gz
bcm5719-llvm-3f851704c154b8ab045b5cd58d31ce854b9c6599.zip
Move new lld's code to Common subdirectory.
New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
Diffstat (limited to 'lld/Common/Reproduce.cpp')
-rw-r--r--lld/Common/Reproduce.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/lld/Common/Reproduce.cpp b/lld/Common/Reproduce.cpp
new file mode 100644
index 00000000000..1e3dabaea0c
--- /dev/null
+++ b/lld/Common/Reproduce.cpp
@@ -0,0 +1,66 @@
+//===- Reproduce.cpp - Utilities for creating reproducers -----------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Common/Reproduce.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+using namespace lld;
+using namespace llvm;
+using namespace llvm::sys;
+
+// Makes a given pathname an absolute path first, and then remove
+// beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
+// assuming that the current directory is "/home/john/bar".
+// Returned string is a forward slash separated path even on Windows to avoid
+// a mess with backslash-as-escape and backslash-as-path-separator.
+std::string lld::relativeToRoot(StringRef Path) {
+ SmallString<128> Abs = Path;
+ if (fs::make_absolute(Abs))
+ return Path;
+ path::remove_dots(Abs, /*remove_dot_dot=*/true);
+
+ // This is Windows specific. root_name() returns a drive letter
+ // (e.g. "c:") or a UNC name (//net). We want to keep it as part
+ // of the result.
+ SmallString<128> Res;
+ StringRef Root = path::root_name(Abs);
+ if (Root.endswith(":"))
+ Res = Root.drop_back();
+ else if (Root.startswith("//"))
+ Res = Root.substr(2);
+
+ path::append(Res, path::relative_path(Abs));
+ return path::convert_to_slash(Res);
+}
+
+// Quote a given string if it contains a space character.
+std::string lld::quote(StringRef S) {
+ if (S.contains(' '))
+ return ("\"" + S + "\"").str();
+ return S;
+}
+
+std::string lld::rewritePath(StringRef S) {
+ if (fs::exists(S))
+ return relativeToRoot(S);
+ return S;
+}
+
+std::string lld::toString(opt::Arg *Arg) {
+ std::string K = Arg->getSpelling();
+ if (Arg->getNumValues() == 0)
+ return K;
+ std::string V = quote(Arg->getValue());
+ if (Arg->getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
+ return K + V;
+ return K + " " + V;
+}
OpenPOWER on IntegriCloud