[pkg-d-commits] [ldc] 50/95: Integrate module gen/programs into driver/tool
Matthias Klumpp
mak at moszumanska.debian.org
Thu Jul 13 20:53:59 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.
commit 95c1d38e2e5fa1e8dba6db0ef781f2a43fae9bb5
Author: Martin <noone at nowhere.com>
Date: Mon Mar 13 23:31:32 2017 +0100
Integrate module gen/programs into driver/tool
---
driver/linker.cpp | 1 -
driver/toobj.cpp | 1 -
driver/tool.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
driver/tool.h | 3 +++
gen/modules.cpp | 1 -
gen/programs.cpp | 71 --------------------------------------------------
gen/programs.h | 24 -----------------
7 files changed, 74 insertions(+), 105 deletions(-)
diff --git a/driver/linker.cpp b/driver/linker.cpp
index f9d6db0..52fa84a 100644
--- a/driver/linker.cpp
+++ b/driver/linker.cpp
@@ -19,7 +19,6 @@
#include "gen/llvm.h"
#include "gen/logger.h"
#include "gen/optimizer.h"
-#include "gen/programs.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Linker/Linker.h"
diff --git a/driver/toobj.cpp b/driver/toobj.cpp
index 27f90da..d8f6035 100644
--- a/driver/toobj.cpp
+++ b/driver/toobj.cpp
@@ -16,7 +16,6 @@
#include "gen/irstate.h"
#include "gen/logger.h"
#include "gen/optimizer.h"
-#include "gen/programs.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/Verifier.h"
#if LDC_LLVM_VER >= 309
diff --git a/driver/tool.cpp b/driver/tool.cpp
index c409210..9d4487f 100644
--- a/driver/tool.cpp
+++ b/driver/tool.cpp
@@ -10,6 +10,7 @@
#include "driver/tool.h"
#include "mars.h"
#include "driver/exe_path.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -18,16 +19,79 @@
#include <Windows.h>
#endif
+//////////////////////////////////////////////////////////////////////////////
+
+static llvm::cl::opt<std::string>
+ gcc("gcc", llvm::cl::desc("GCC to use for assembling and linking"),
+ llvm::cl::Hidden, llvm::cl::ZeroOrMore);
+
+static llvm::cl::opt<std::string> ar("ar", llvm::cl::desc("Archiver"),
+ llvm::cl::Hidden, llvm::cl::ZeroOrMore);
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace {
+
+std::string findProgramByName(llvm::StringRef name) {
+#if LDC_LLVM_VER >= 306
+ llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name);
+ return res ? res.get() : std::string();
+#else
+ return llvm::sys::FindProgramByName(name);
+#endif
+}
+
+std::string getProgram(const char *name,
+ const llvm::cl::opt<std::string> *opt = nullptr,
+ const char *envVar = nullptr) {
+ std::string path;
+ const char *prog = nullptr;
+
+ if (opt && !opt->empty()) {
+ path = findProgramByName(opt->c_str());
+ }
+
+ if (path.empty() && envVar && (prog = getenv(envVar)) && prog[0] != '\0') {
+ path = findProgramByName(prog);
+ }
+
+ if (path.empty()) {
+ path = findProgramByName(name);
+ }
+
+ if (path.empty()) {
+ error(Loc(), "failed to locate %s", name);
+ fatal();
+ }
+
+ return path;
+}
+
+} // anonymous namespace
+
+////////////////////////////////////////////////////////////////////////////////
+
+std::string getGcc() {
+#if defined(__FreeBSD__) && __FreeBSD__ >= 10
+ // Default compiler on FreeBSD 10 is clang
+ return getProgram("clang", &gcc, "CC");
+#else
+ return getProgram("gcc", &gcc, "CC");
+#endif
+}
+
+std::string getArchiver() { return getProgram("ar", &ar); }
+
+////////////////////////////////////////////////////////////////////////////////
+
int executeToolAndWait(const std::string &tool_,
std::vector<std::string> const &args, bool verbose) {
- auto fullToolOrError = llvm::sys::findProgramByName(tool_);
- if (fullToolOrError.getError()) {
+ const auto tool = findProgramByName(tool_);
+ if (tool.empty()) {
error(Loc(), "failed to locate binary %s", tool_.c_str());
return -1;
}
- const auto tool = std::move(*fullToolOrError);
-
// Construct real argument list.
// First entry is the tool itself, last entry must be NULL.
std::vector<const char *> realargs;
@@ -61,7 +125,7 @@ int executeToolAndWait(const std::string &tool_,
return 0;
}
-//////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
@@ -139,8 +203,8 @@ int executeAndWait(const char *commandLine) {
#endif
// according to MSDN, only CreateProcessW (unicode) may modify the passed
// command line
- if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0,
- NULL, NULL, &si, &pi)) {
+ if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si,
+ &pi)) {
exitCode = -1;
} else {
if (WaitForSingleObject(pi.hProcess, INFINITE) != 0 ||
diff --git a/driver/tool.h b/driver/tool.h
index c96f851..b966e40 100644
--- a/driver/tool.h
+++ b/driver/tool.h
@@ -18,6 +18,9 @@
#include <vector>
#include <string>
+std::string getGcc();
+std::string getArchiver();
+
int executeToolAndWait(const std::string &tool,
std::vector<std::string> const &args,
bool verbose = false);
diff --git a/gen/modules.cpp b/gen/modules.cpp
index df2dd7d..d660bfb 100644
--- a/gen/modules.cpp
+++ b/gen/modules.cpp
@@ -31,7 +31,6 @@
#include "gen/logger.h"
#include "gen/moduleinfo.h"
#include "gen/optimizer.h"
-#include "gen/programs.h"
#include "gen/runtime.h"
#include "gen/structs.h"
#include "gen/tollvm.h"
diff --git a/gen/programs.cpp b/gen/programs.cpp
deleted file mode 100644
index c03d814..0000000
--- a/gen/programs.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-//===-- programs.cpp ------------------------------------------------------===//
-//
-// LDC – the LLVM D compiler
-//
-// This file is distributed under the BSD-style LDC license. See the LICENSE
-// file for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "gen/programs.h"
-#include "mars.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Program.h"
-
-using namespace llvm;
-
-static cl::opt<std::string>
- gcc("gcc", cl::desc("GCC to use for assembling and linking"), cl::Hidden,
- cl::ZeroOrMore);
-
-static cl::opt<std::string> ar("ar", cl::desc("Archiver"), cl::Hidden,
- cl::ZeroOrMore);
-
-static std::string findProgramByName(llvm::StringRef name) {
-#if LDC_LLVM_VER >= 306
- llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name);
- return res ? res.get() : std::string();
-#else
- return llvm::sys::FindProgramByName(name);
-#endif
-}
-
-static std::string getProgram(const char *name, const cl::opt<std::string> *opt,
- const char *envVar = nullptr) {
- std::string path;
- const char *prog = nullptr;
-
- if (opt && !opt->empty()) {
- path = findProgramByName(opt->c_str());
- }
-
- if (path.empty() && envVar && (prog = getenv(envVar)) && prog[0] != '\0') {
- path = findProgramByName(prog);
- }
-
- if (path.empty()) {
- path = findProgramByName(name);
- }
-
- if (path.empty()) {
- error(Loc(), "failed to locate %s", name);
- fatal();
- }
-
- return path;
-}
-
-std::string getProgram(const char *name, const char *envVar) {
- return getProgram(name, nullptr, envVar);
-}
-
-std::string getGcc() {
-#if defined(__FreeBSD__) && __FreeBSD__ >= 10
- // Default compiler on FreeBSD 10 is clang
- return getProgram("clang", &gcc, "CC");
-#else
- return getProgram("gcc", &gcc, "CC");
-#endif
-}
-
-std::string getArchiver() { return getProgram("ar", &ar); }
diff --git a/gen/programs.h b/gen/programs.h
deleted file mode 100644
index c26ac70..0000000
--- a/gen/programs.h
+++ /dev/null
@@ -1,24 +0,0 @@
-//===-- gen/programs.h - External tool discovery ----------------*- C++ -*-===//
-//
-// LDC – the LLVM D compiler
-//
-// This file is distributed under the BSD-style LDC license. See the LICENSE
-// file for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Functions for discovering the external tools used for linking, etc.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LDC_GEN_PROGRAMS_H
-#define LDC_GEN_PROGRAMS_H
-
-#include <string>
-
-std::string getProgram(const char *name, const char *envVar = nullptr);
-
-std::string getGcc();
-std::string getArchiver();
-
-#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list