diff --git a/driver/linker.cpp b/driver/linker.cpp index 012a1ba0..7af669b7 100644 --- a/driver/linker.cpp +++ b/driver/linker.cpp @@ -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 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 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 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); diff --git a/driver/toobj.cpp b/driver/toobj.cpp index 0e91f688..63859fb6 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -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) { diff --git a/driver/tool.cpp b/driver/tool.cpp index 609bfbfe..9527fd05 100644 --- a/driver/tool.cpp +++ b/driver/tool.cpp @@ -11,7 +11,7 @@ #include "mars.h" #include "llvm/Support/Program.h" -int executeToolAndWait(llvm::sys::Path tool, std::vector const & args, bool verbose) +int executeToolAndWait(const std::string &tool, std::vector 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 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); diff --git a/driver/tool.h b/driver/tool.h index e3d9e78a..cdade411 100644 --- a/driver/tool.h +++ b/driver/tool.h @@ -15,10 +15,9 @@ #ifndef LDC_DRIVER_TOOL_H #define LDC_DRIVER_TOOL_H -#include "llvm/Support/PathV1.h" #include #include -int executeToolAndWait(llvm::sys::Path tool, std::vector const & args, bool verbose = false); +int executeToolAndWait(const std::string &tool, std::vector const &args, bool verbose = false); #endif diff --git a/gen/programs.cpp b/gen/programs.cpp index a68cdfcc..ce4de3d6 100644 --- a/gen/programs.cpp +++ b/gen/programs.cpp @@ -35,24 +35,20 @@ static cl::opt 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 &opt, const char *envVar = 0) +static std::string getProgram(const char *name, const cl::opt &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 &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); } diff --git a/gen/programs.h b/gen/programs.h index a62d8b6f..02829e57 100644 --- a/gen/programs.h +++ b/gen/programs.h @@ -14,8 +14,6 @@ #ifndef LDC_GEN_PROGRAMS_H #define LDC_GEN_PROGRAMS_H -#if LDC_LLVM_VER >= 304 - #include 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