Make ldc compatible with LLVM 3.4

Development of LLVM 3.4 started with a cleanup of the path class (PathV1).
The changes here let ldc compile at least with rev. 184039 of LLVM.
This commit is contained in:
kai
2013-06-14 06:50:38 +02:00
parent fe455fe1a8
commit f1c71e4bac
7 changed files with 88 additions and 10 deletions

View File

@@ -12,6 +12,9 @@
#include "libconfig.h++"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#if LDC_LLVM_VER >= 304
#include "llvm/Support/PathV1.h"
#endif
#include <cassert>
#include <cstring>
#include <iostream>
@@ -19,12 +22,38 @@
#if _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h>
// Prevent name clash with LLVM
#undef GetCurrentDirectory
#endif
namespace sys = llvm::sys;
#if LDC_LLVM_VER >= 304
#if _WIN32
sys::Path GetUserHomeDirectory() {
char buff[MAX_PATH];
HRESULT res = SHGetFolderPathA(NULL,
CSIDL_FLAG_CREATE | CSIDL_APPDATA,
NULL,
SHGFP_TYPE_CURRENT,
buff);
if (res != S_OK)
assert(0 && "Failed to get user home directory");
return sys::Path(buff);
}
#else
sys::Path GetUserHomeDirectory() {
const char* home = getenv("HOME");
Path result;
if (home && result.set(home))
return result;
result.set("/");
return result;
}
#endif
#endif
#if _WIN32
static bool ReadPathFromRegistry(sys::Path& p)
{
@@ -81,7 +110,11 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
// user configuration
// try ~/.ldc
#if LDC_LLVM_VER >= 304
p = GetUserHomeDirectory();
#else
p = sys::Path::GetUserHomeDirectory();
#endif
p.appendComponent(".ldc");
p.appendComponent(filename);
if (sys::fs::exists(p.str()))
@@ -89,7 +122,11 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
#if _WIN32
// try home dir
#if LDC_LLVM_VER >= 304
p = GetUserHomeDirectory();
#else
p = sys::Path::GetUserHomeDirectory();
#endif
p.appendComponent(filename);
if (sys::fs::exists(p.str()))
return true;

View File

@@ -102,7 +102,7 @@ static int linkObjToBinaryGcc(bool sharedLib)
Logger::println("*** Linking executable ***");
// find gcc for linking
llvm::sys::Path gcc = getGcc();
llvm::sys::Path gcc(getGcc());
// build arguments
std::vector<std::string> args;
@@ -222,7 +222,7 @@ static int linkObjToBinaryWin(bool sharedLib)
Logger::println("*** Linking executable ***");
// find link.exe for linking
llvm::sys::Path tool = getLink();
llvm::sys::Path tool(getLink());
// build arguments
std::vector<std::string> args;
@@ -346,7 +346,7 @@ void createStaticLibrary()
const bool isTargetWindows = global.params.targetTriple.getOS() == llvm::Triple::Win32;
// find archiver
llvm::sys::Path tool = isTargetWindows ? getLib() : getArchiver();
llvm::sys::Path tool(isTargetWindows ? getLib() : getArchiver());
// build arguments
std::vector<std::string> args;

View File

@@ -83,7 +83,8 @@ static void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objp
args.push_back("-m32");
// Run the compiler to assembly the program.
int R = executeToolAndWait(getGcc(), args, global.params.verbose);
llvm::sys::Path gcc(getGcc());
int R = executeToolAndWait(gcc, args, global.params.verbose);
if (R)
{
error("Error while invoking external assembler.");

View File

@@ -36,7 +36,11 @@ int executeToolAndWait(llvm::sys::Path tool, std::vector<std::string> const & ar
// Execute tool.
std::string errstr;
#if LDC_LLVM_VER >= 304
if (int status = llvm::sys::ExecuteAndWait(tool.str(), &realargs[0], NULL, NULL, 0, 0, &errstr))
#else
if (int status = llvm::sys::Program::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr))
#endif
{
error("%s failed with status: %d", tool.c_str(), status);
if (!errstr.empty())

View File

@@ -35,19 +35,37 @@ static cl::opt<std::string> mslib("ms-lib",
cl::Hidden,
cl::ZeroOrMore);
sys::Path getProgram(const char *name, const cl::opt<std::string> &opt, const char *envVar = 0)
#if LDC_LLVM_VER >= 304
typedef std::string RetType;
#else
typedef sys::Path RetType;
#endif
RetType getProgram(const char *name, const cl::opt<std::string> &opt, const char *envVar = 0)
{
sys::Path path;
RetType path;
const char *prog = NULL;
if (opt.getNumOccurrences() > 0 && opt.length() > 0 && (prog = opt.c_str()))
#if LDC_LLVM_VER >= 304
path = sys::FindProgramByName(prog);
#else
path = sys::Program::FindProgramByName(prog);
#endif
if (path.empty() && envVar && (prog = getenv(envVar)))
#if LDC_LLVM_VER >= 304
path = sys::FindProgramByName(prog);
#else
path = sys::Program::FindProgramByName(prog);
#endif
if (path.empty())
#if LDC_LLVM_VER >= 304
path = sys::FindProgramByName(name);
#else
path = sys::Program::FindProgramByName(name);
#endif
if (path.empty()) {
error("failed to locate %s", name);
@@ -57,22 +75,22 @@ sys::Path getProgram(const char *name, const cl::opt<std::string> &opt, const ch
return path;
}
sys::Path getGcc()
RetType getGcc()
{
return getProgram("gcc", gcc, "CC");
}
sys::Path getArchiver()
RetType getArchiver()
{
return getProgram("ar", ar);
}
sys::Path getLink()
RetType getLink()
{
return getProgram("link.exe", mslink);
}
sys::Path getLib()
RetType getLib()
{
return getProgram("lib.exe", mslib);
}

View File

@@ -14,6 +14,19 @@
#ifndef LDC_GEN_PROGRAMS_H
#define LDC_GEN_PROGRAMS_H
#if LDC_LLVM_VER >= 304
#include <string>
std::string getGcc();
std::string getArchiver();
// For Windows with MS tool chain
std::string getLink();
std::string getLib();
#else
#include "llvm/Support/Path.h"
llvm::sys::Path getGcc();
@@ -24,3 +37,5 @@ llvm::sys::Path getLink();
llvm::sys::Path getLib();
#endif
#endif

View File

@@ -27,6 +27,9 @@
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#if LDC_LLVM_VER >= 304
#include "llvm/Support/PathV1.h"
#endif
using namespace llvm::dwarf;