mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-20 14:53:14 +01:00
Replace llvm::sys::Path with std::string.
In many cases this is straightforward. It makes the source LLVM 3.4 compatible without using #idef's.
This commit is contained in:
@@ -36,14 +36,14 @@ static bool endsWith(const std::string &str, const std::string &end)
|
||||
|
||||
static void CreateDirectoryOnDisk(llvm::StringRef fileName)
|
||||
{
|
||||
llvm::sys::Path dir(llvm::sys::path::parent_path(fileName));
|
||||
if (!dir.empty() && !llvm::sys::fs::exists(dir.str()))
|
||||
llvm::StringRef dir(llvm::sys::path::parent_path(fileName));
|
||||
if (!dir.empty() && !llvm::sys::fs::exists(dir))
|
||||
{
|
||||
std::string errstr;
|
||||
dir.createDirectoryOnDisk(true, &errstr);
|
||||
if (!errstr.empty())
|
||||
bool Existed;
|
||||
llvm::error_code ec = llvm::sys::fs::create_directory(dir, Existed);
|
||||
if (ec)
|
||||
{
|
||||
error("failed to create path to file: %s\n%s", dir.c_str(), errstr.c_str());
|
||||
error("failed to create path to file: %s\n%s", dir.data(), ec.message().c_str());
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
@@ -95,14 +95,14 @@ static std::string getOutputName(bool const sharedLib)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static llvm::sys::Path gExePath;
|
||||
static std::string gExePath;
|
||||
|
||||
static int linkObjToBinaryGcc(bool sharedLib)
|
||||
{
|
||||
Logger::println("*** Linking executable ***");
|
||||
|
||||
// find gcc for linking
|
||||
llvm::sys::Path gcc(getGcc());
|
||||
std::string gcc(getGcc());
|
||||
|
||||
// build arguments
|
||||
std::vector<std::string> args;
|
||||
@@ -131,11 +131,11 @@ static int linkObjToBinaryGcc(bool sharedLib)
|
||||
args.push_back(output);
|
||||
|
||||
// set the global gExePath
|
||||
gExePath.set(output);
|
||||
assert(gExePath.isValid());
|
||||
gExePath = output;
|
||||
//assert(gExePath.isValid());
|
||||
|
||||
// create path to exe
|
||||
CreateDirectoryOnDisk(gExePath.str());
|
||||
CreateDirectoryOnDisk(gExePath);
|
||||
|
||||
// additional linker switches
|
||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
|
||||
@@ -222,7 +222,7 @@ static int linkObjToBinaryWin(bool sharedLib)
|
||||
Logger::println("*** Linking executable ***");
|
||||
|
||||
// find link.exe for linking
|
||||
llvm::sys::Path tool(getLink());
|
||||
std::string tool(getLink());
|
||||
|
||||
// build arguments
|
||||
std::vector<std::string> args;
|
||||
@@ -276,11 +276,11 @@ static int linkObjToBinaryWin(bool sharedLib)
|
||||
}
|
||||
|
||||
// set the global gExePath
|
||||
gExePath.set(output);
|
||||
assert(gExePath.isValid());
|
||||
gExePath = output;
|
||||
//assert(gExePath.isValid());
|
||||
|
||||
// create path to exe
|
||||
CreateDirectoryOnDisk(gExePath.str());
|
||||
CreateDirectoryOnDisk(gExePath);
|
||||
|
||||
// additional linker switches
|
||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
|
||||
@@ -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());
|
||||
std::string tool(isTargetWindows ? getLib() : getArchiver());
|
||||
|
||||
// build arguments
|
||||
std::vector<std::string> args;
|
||||
@@ -406,12 +406,13 @@ void createStaticLibrary()
|
||||
|
||||
void deleteExecutable()
|
||||
{
|
||||
if (!gExePath.isEmpty())
|
||||
if (!gExePath.empty())
|
||||
{
|
||||
assert(gExePath.isValid());
|
||||
//assert(gExePath.isValid());
|
||||
bool is_directory;
|
||||
assert(!(!llvm::sys::fs::is_directory(gExePath.str(), is_directory) && is_directory));
|
||||
gExePath.eraseFromDisk(false);
|
||||
assert(!(!llvm::sys::fs::is_directory(gExePath, is_directory) && is_directory));
|
||||
bool Existed;
|
||||
llvm::sys::fs::remove(gExePath, Existed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,8 +420,8 @@ void deleteExecutable()
|
||||
|
||||
int runExecutable()
|
||||
{
|
||||
assert(!gExePath.isEmpty());
|
||||
assert(gExePath.isValid());
|
||||
assert(!gExePath.empty());
|
||||
//assert(gExePath.isValid());
|
||||
|
||||
// Run executable
|
||||
int status = executeToolAndWait(gExePath, opts::runargs, global.params.verbose);
|
||||
|
||||
@@ -83,7 +83,7 @@ static void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objp
|
||||
args.push_back("-m32");
|
||||
|
||||
// Run the compiler to assembly the program.
|
||||
llvm::sys::Path gcc(getGcc());
|
||||
std::string gcc(getGcc());
|
||||
int R = executeToolAndWait(gcc, args, global.params.verbose);
|
||||
if (R)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "mars.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
|
||||
int executeToolAndWait(llvm::sys::Path tool, std::vector<std::string> const & args, bool verbose)
|
||||
int executeToolAndWait(const std::string &tool, std::vector<std::string> const &args, bool verbose)
|
||||
{
|
||||
// Construct real argument list.
|
||||
// First entry is the tool itself, last entry must be NULL.
|
||||
@@ -37,9 +37,10 @@ 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))
|
||||
if (int status = llvm::sys::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr))
|
||||
#else
|
||||
if (int status = llvm::sys::Program::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr))
|
||||
llvm::sys::Path toolpath(tool);
|
||||
if (int status = llvm::sys::Program::ExecuteAndWait(toolpath, &realargs[0], NULL, NULL, 0, 0, &errstr))
|
||||
#endif
|
||||
{
|
||||
error("%s failed with status: %d", tool.c_str(), status);
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
#ifndef LDC_DRIVER_TOOL_H
|
||||
#define LDC_DRIVER_TOOL_H
|
||||
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
int executeToolAndWait(llvm::sys::Path tool, std::vector<std::string> const & args, bool verbose = false);
|
||||
int executeToolAndWait(const std::string &tool, std::vector<std::string> const &args, bool verbose = false);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,24 +35,20 @@ static cl::opt<std::string> mslib("ms-lib",
|
||||
cl::Hidden,
|
||||
cl::ZeroOrMore);
|
||||
|
||||
#if LDC_LLVM_VER >= 304
|
||||
typedef std::string RetType;
|
||||
#else
|
||||
typedef sys::Path RetType;
|
||||
|
||||
#if LDC_LLVM_VER < 304
|
||||
namespace llvm {
|
||||
namespace sys {
|
||||
inline sys::Path FindProgramByName(const std::string& name)
|
||||
inline std::string FindProgramByName(const std::string& name)
|
||||
{
|
||||
return llvm::sys::Program::FindProgramByName(name);
|
||||
return llvm::sys::Program::FindProgramByName(name).str();
|
||||
}
|
||||
} // namespace sys
|
||||
} // namespace llvm
|
||||
#endif
|
||||
|
||||
static RetType getProgram(const char *name, const cl::opt<std::string> &opt, const char *envVar = 0)
|
||||
static std::string getProgram(const char *name, const cl::opt<std::string> &opt, const char *envVar = 0)
|
||||
{
|
||||
RetType path;
|
||||
std::string path;
|
||||
const char *prog = NULL;
|
||||
|
||||
if (opt.getNumOccurrences() > 0 && opt.length() > 0 && (prog = opt.c_str()))
|
||||
@@ -72,22 +68,22 @@ static RetType getProgram(const char *name, const cl::opt<std::string> &opt, con
|
||||
return path;
|
||||
}
|
||||
|
||||
RetType getGcc()
|
||||
std::string getGcc()
|
||||
{
|
||||
return getProgram("gcc", gcc, "CC");
|
||||
}
|
||||
|
||||
RetType getArchiver()
|
||||
std::string getArchiver()
|
||||
{
|
||||
return getProgram("ar", ar);
|
||||
}
|
||||
|
||||
RetType getLink()
|
||||
std::string getLink()
|
||||
{
|
||||
return getProgram("link.exe", mslink);
|
||||
}
|
||||
|
||||
RetType getLib()
|
||||
std::string getLib()
|
||||
{
|
||||
return getProgram("lib.exe", mslib);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
#ifndef LDC_GEN_PROGRAMS_H
|
||||
#define LDC_GEN_PROGRAMS_H
|
||||
|
||||
#if LDC_LLVM_VER >= 304
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string getGcc();
|
||||
@@ -25,17 +23,4 @@ std::string getArchiver();
|
||||
std::string getLink();
|
||||
std::string getLib();
|
||||
|
||||
#else
|
||||
|
||||
#include "llvm/Support/Path.h"
|
||||
|
||||
llvm::sys::Path getGcc();
|
||||
llvm::sys::Path getArchiver();
|
||||
|
||||
// For Windows with MS tool chain
|
||||
llvm::sys::Path getLink();
|
||||
llvm::sys::Path getLib();
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user