mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-11-30 12:53:51 +01:00
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:
@@ -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;
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+2
-1
@@ -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.");
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user