Rename FindExecutable to PrependMainExecutablePath.

Makes it more clear that it is just a path manipulation function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118174 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mikhail Glushenkov
2010-11-03 16:14:16 +00:00
parent 544fba1362
commit d66f2b74f2
6 changed files with 30 additions and 26 deletions

View File

@ -30,12 +30,13 @@ bool CheckBitcodeOutputToConsole(
bool print_warning = true ///< Control whether warnings are printed bool print_warning = true ///< Control whether warnings are printed
); );
/// FindExecutable - Find a named executable, given the value of argv[0] of the /// PrependMainExecutablePath - Prepend the path to the program being executed
/// program being executed and the address of main itself. This allows us to /// to \p ExeName, given the value of argv[0] and the address of main()
/// find another LLVM tool if it is built in the same directory. An empty string /// itself. This allows us to find another LLVM tool if it is built in the same
/// is returned on error. /// directory. An empty string is returned on error; note that this function
/// just mainpulates the path and doesn't check for executability.
/// @brief Find a named executable. /// @brief Find a named executable.
sys::Path FindExecutable(const std::string &ExeName, sys::Path PrependMainExecutablePath(const std::string &ExeName,
const char *Argv0, void *MainAddr); const char *Argv0, void *MainAddr);
} // End llvm namespace } // End llvm namespace

View File

@ -57,7 +57,8 @@ namespace {
sys::Path prog(name); sys::Path prog(name);
if (!prog.isAbsolute()) { if (!prog.isAbsolute()) {
prog = FindExecutable(name, ProgramName, (void *)(intptr_t)&Main); prog = PrependMainExecutablePath(name, ProgramName,
(void *)(intptr_t)&Main);
if (!prog.canExecute()) { if (!prog.canExecute()) {
prog = sys::Program::FindProgramByName(name); prog = sys::Program::FindProgramByName(name);

View File

@ -32,12 +32,13 @@ bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
return false; return false;
} }
/// FindExecutable - Find a named executable, given the value of argv[0] of the /// PrependMainExecutablePath - Prepend the path to the program being executed
/// program being executed and the address of main itself. This allows us to /// to \p ExeName, given the value of argv[0] and the address of main()
/// find another LLVM tool if it is built in the same directory. An empty string /// itself. This allows us to find another LLVM tool if it is built in the same
/// is returned on error. /// directory. An empty string is returned on error; note that this function
#undef FindExecutable // needed on windows :( /// just mainpulates the path and doesn't check for executability.
sys::Path llvm::FindExecutable(const std::string &ExeName, /// @brief Find a named executable.
sys::Path llvm::PrependMainExecutablePath(const std::string &ExeName,
const char *Argv0, void *MainAddr) { const char *Argv0, void *MainAddr) {
// Check the directory that the calling program is in. We can do // Check the directory that the calling program is in. We can do
// this if ProgramPath contains at least one / character, indicating that it // this if ProgramPath contains at least one / character, indicating that it

View File

@ -144,7 +144,8 @@ bool BugDriver::runPasses(Module *Program,
return 1; return 1;
} }
sys::Path tool = FindExecutable("opt", getToolName(), (void*)"opt"); sys::Path tool = PrependMainExecutablePath("opt", getToolName(),
(void*)"opt");
if (tool.empty()) { if (tool.empty()) {
errs() << "Cannot find `opt' in executable directory!\n"; errs() << "Cannot find `opt' in executable directory!\n";
return 1; return 1;

View File

@ -238,7 +238,7 @@ AbstractInterpreter *AbstractInterpreter::createLLI(const char *Argv0,
std::string &Message, std::string &Message,
const std::vector<std::string> *ToolArgs) { const std::vector<std::string> *ToolArgs) {
std::string LLIPath = std::string LLIPath =
FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).str(); PrependMainExecutablePath("lli", Argv0, (void *)(intptr_t)&createLLI).str();
if (!LLIPath.empty()) { if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n"; Message = "Found lli: " + LLIPath + "\n";
return new LLI(LLIPath, ToolArgs); return new LLI(LLIPath, ToolArgs);
@ -438,7 +438,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
const std::vector<std::string> *GCCArgs, const std::vector<std::string> *GCCArgs,
bool UseIntegratedAssembler) { bool UseIntegratedAssembler) {
std::string LLCPath = std::string LLCPath =
FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str(); PrependMainExecutablePath("llc", Argv0, (void *)(intptr_t)&createLLC).str();
if (LLCPath.empty()) { if (LLCPath.empty()) {
Message = "Cannot find `llc' in executable directory!\n"; Message = "Cannot find `llc' in executable directory!\n";
return 0; return 0;
@ -526,7 +526,7 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0, AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
std::string &Message, const std::vector<std::string> *Args) { std::string &Message, const std::vector<std::string> *Args) {
std::string LLIPath = std::string LLIPath =
FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).str(); PrependMainExecutablePath("lli", Argv0, (void *)(intptr_t)&createJIT).str();
if (!LLIPath.empty()) { if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n"; Message = "Found lli: " + LLIPath + "\n";
return new JIT(LLIPath, Args); return new JIT(LLIPath, Args);
@ -608,7 +608,7 @@ CBE *AbstractInterpreter::createCBE(const char *Argv0,
const std::vector<std::string> *Args, const std::vector<std::string> *Args,
const std::vector<std::string> *GCCArgs) { const std::vector<std::string> *GCCArgs) {
sys::Path LLCPath = sys::Path LLCPath =
FindExecutable("llc", Argv0, (void *)(intptr_t)&createCBE); PrependMainExecutablePath("llc", Argv0, (void *)(intptr_t)&createCBE);
if (LLCPath.isEmpty()) { if (LLCPath.isEmpty()) {
Message = Message =
"Cannot find `llc' in executable directory!\n"; "Cannot find `llc' in executable directory!\n";

View File

@ -415,7 +415,7 @@ static void EmitShellScript(char **argv, Module *M) {
// support windows systems, we copy the llvm-stub.exe executable from the // support windows systems, we copy the llvm-stub.exe executable from the
// build tree to the destination file. // build tree to the destination file.
std::string ErrMsg; std::string ErrMsg;
sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0], sys::Path llvmstub = PrependMainExecutablePath("llvm-stub", argv[0],
(void *)(intptr_t)&Optimize); (void *)(intptr_t)&Optimize);
if (llvmstub.isEmpty()) if (llvmstub.isEmpty())
PrintAndExit("Could not find llvm-stub.exe executable!", M); PrintAndExit("Could not find llvm-stub.exe executable!", M);
@ -664,7 +664,7 @@ int main(int argc, char **argv, char **envp) {
sys::RemoveFileOnSignal(AssemblyFile); sys::RemoveFileOnSignal(AssemblyFile);
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
sys::Path llc = FindExecutable("llc", argv[0], sys::Path llc = PrependMainExecutablePath("llc", argv[0],
(void *)(intptr_t)&Optimize); (void *)(intptr_t)&Optimize);
if (llc.isEmpty()) if (llc.isEmpty())
PrintAndExit("Failed to find llc", Composite.get()); PrintAndExit("Failed to find llc", Composite.get());
@ -691,7 +691,7 @@ int main(int argc, char **argv, char **envp) {
sys::RemoveFileOnSignal(CFile); sys::RemoveFileOnSignal(CFile);
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
sys::Path llc = FindExecutable("llc", argv[0], sys::Path llc = PrependMainExecutablePath("llc", argv[0],
(void *)(intptr_t)&Optimize); (void *)(intptr_t)&Optimize);
if (llc.isEmpty()) if (llc.isEmpty())
PrintAndExit("Failed to find llc", Composite.get()); PrintAndExit("Failed to find llc", Composite.get());