From ac1db6b2bde50e9a0f3846243f654f6c13682725 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 26 Jun 2013 05:03:40 +0000 Subject: [PATCH] Use llvm::sys::fs::getMainExecutable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184915 91177308-0d34-0410-b5e6-96231b3b80d8 --- examples/clang-interpreter/main.cpp | 9 +++++---- lib/Frontend/CompilerInvocation.cpp | 3 ++- lib/Tooling/Tooling.cpp | 2 +- tools/arcmt-test/arcmt-test.cpp | 4 ++-- tools/driver/driver.cpp | 13 ++++++------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp index ff86d2b368..028b9cc34f 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -21,6 +21,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/IR/Module.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" @@ -35,11 +36,11 @@ using namespace clang::driver; // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -llvm::sys::Path GetExecutablePath(const char *Argv0) { +std::string GetExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. void *MainAddr = (void*) (intptr_t) GetExecutablePath; - return llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); + return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } static int Execute(llvm::Module *Mod, char * const *envp) { @@ -68,14 +69,14 @@ static int Execute(llvm::Module *Mod, char * const *envp) { int main(int argc, const char **argv, char * const *envp) { void *MainAddr = (void*) (intptr_t) GetExecutablePath; - llvm::sys::Path Path = GetExecutablePath(argv[0]); + std::string Path = GetExecutablePath(argv[0]); IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); - Driver TheDriver(Path.str(), llvm::sys::getProcessTriple(), "a.out", Diags); + Driver TheDriver(Path, llvm::sys::getProcessTriple(), "a.out", Diags); TheDriver.setTitle("clang interpreter"); // FIXME: This is a hack to try to force the driver to do something we can diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 4986dac005..49ce0b7f82 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -29,6 +29,7 @@ #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" #include "llvm/Support/PathV1.h" @@ -845,7 +846,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, std::string CompilerInvocation::GetResourcesPath(const char *Argv0, void *MainAddr) { - llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); + llvm::sys::Path P(llvm::sys::fs::getMainExecutable(Argv0, MainAddr)); if (!P.isEmpty()) { P.eraseComponent(); // Remove /clang from foo/bin/clang diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index afe7fc8903..518fa50b43 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -292,7 +292,7 @@ int ClangTool::run(FrontendActionFactory *ActionFactory) { // first argument, thus allowing ClangTool and runToolOnCode to just // pass in made-up names here. Make sure this works on other platforms. std::string MainExecutable = - llvm::sys::Path::GetMainExecutable("clang_tool", &StaticSymbol).str(); + llvm::sys::fs::getMainExecutable("clang_tool", &StaticSymbol); bool ProcessingFailed = false; for (unsigned I = 0; I < CompileCommands.size(); ++I) { diff --git a/tools/arcmt-test/arcmt-test.cpp b/tools/arcmt-test/arcmt-test.cpp index 84bee81047..0a5bbe838c 100644 --- a/tools/arcmt-test/arcmt-test.cpp +++ b/tools/arcmt-test/arcmt-test.cpp @@ -62,11 +62,11 @@ static llvm::cl::extrahelp extraHelp( // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -llvm::sys::Path GetExecutablePath(const char *Argv0) { +std::string GetExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. void *MainAddr = (void*) (intptr_t) GetExecutablePath; - return llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); + return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } static void printSourceLocation(SourceLocation loc, ASTContext &Ctx, diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 8b02a35387..6059571c69 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -48,14 +48,14 @@ using namespace clang; using namespace clang::driver; using namespace llvm::opt; -llvm::sys::Path GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { +std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { if (!CanonicalPrefixes) - return llvm::sys::Path(Argv0); + return Argv0; // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. void *P = (void*) (intptr_t) GetExecutablePath; - return llvm::sys::Path::GetMainExecutable(Argv0, P); + return llvm::sys::fs::getMainExecutable(Argv0, P); } static const char *SaveStringInSet(std::set &SavedStrings, @@ -401,7 +401,7 @@ int main(int argc_, const char **argv_) { argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end()); } - llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes); + std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes); IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions; { @@ -419,14 +419,13 @@ int main(int argc_, const char **argv_) { // DiagnosticOptions instance. TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagClient->setPrefix(llvm::sys::path::filename(Path.str())); + DiagClient->setPrefix(llvm::sys::path::filename(Path)); IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false); - Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(), - "a.out", Diags); + Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), "a.out", Diags); // Attempt to find the original path used to invoke the driver, to determine // the installed path. We do this manually, because we want to support that -- 2.40.0