Misha Brukman | ebb0faa | 2004-06-18 15:38:49 +0000 | [diff] [blame] | 1 | //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains functions used to do a variety of low-level, often |
| 11 | // system-specific, tasks. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Bill Wendling | fe6b146 | 2006-11-26 10:52:51 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Streams.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 16 | #include "llvm/Support/SystemUtils.h" |
Reid Spencer | 436f23e | 2005-01-01 23:56:20 +0000 | [diff] [blame] | 17 | #include "llvm/System/Process.h" |
Misha Brukman | dca7978 | 2005-04-22 19:13:22 +0000 | [diff] [blame] | 18 | #include "llvm/System/Program.h" |
Bill Wendling | 1a097e3 | 2006-12-07 23:41:45 +0000 | [diff] [blame] | 19 | #include <ostream> |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 20 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 22 | bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check, |
| 23 | bool print_warning) { |
Bill Wendling | bcd2498 | 2006-12-07 20:28:15 +0000 | [diff] [blame] | 24 | if (stream_to_check == cout.stream() && |
| 25 | sys::Process::StandardOutIsDisplayed()) { |
Reid Spencer | 52b50a6 | 2005-01-02 00:10:03 +0000 | [diff] [blame] | 26 | if (print_warning) { |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 27 | cerr << "WARNING: You're attempting to print out a bitcode file.\n" |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 28 | << "This is inadvisable as it may cause display problems. If\n" |
Gabor Greif | a99be51 | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 29 | << "you REALLY want to taste LLVM bitcode first-hand, you\n" |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 30 | << "can force output with the `-f' option.\n\n"; |
Reid Spencer | 52b50a6 | 2005-01-02 00:10:03 +0000 | [diff] [blame] | 31 | } |
Reid Spencer | 436f23e | 2005-01-01 23:56:20 +0000 | [diff] [blame] | 32 | return true; |
| 33 | } |
Brian Gaeke | 8507ecb | 2004-04-02 21:26:04 +0000 | [diff] [blame] | 34 | return false; |
Chris Lattner | b234d46 | 2004-04-02 05:04:03 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Misha Brukman | f7066c7 | 2003-08-07 21:34:25 +0000 | [diff] [blame] | 37 | /// FindExecutable - Find a named executable, giving the argv[0] of program |
Misha Brukman | 44f8a34 | 2003-09-29 22:40:07 +0000 | [diff] [blame] | 38 | /// being executed. This allows us to find another LLVM tool if it is built |
| 39 | /// into the same directory, but that directory is neither the current |
| 40 | /// directory, nor in the PATH. If the executable cannot be found, return an |
Daniel Dunbar | 93696a3 | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 41 | /// empty string. Return the input string if given a full path to an executable. |
Reid Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame] | 42 | /// |
Chris Lattner | 49f61c4 | 2004-05-28 01:20:58 +0000 | [diff] [blame] | 43 | #undef FindExecutable // needed on windows :( |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 44 | sys::Path llvm::FindExecutable(const std::string &ExeName, |
Reid Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame] | 45 | const std::string &ProgramPath) { |
Daniel Dunbar | 93696a3 | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 46 | // First check if the given name is a fully qualified path to an executable |
| 47 | sys::Path Result(ExeName); |
| 48 | if (Result.isAbsolute() && Result.canExecute()) |
| 49 | return Result; |
| 50 | |
| 51 | // Otherwise check the directory that the calling program is in. We can do |
| 52 | // this if ProgramPath contains at least one / character, indicating that it |
| 53 | // is a relative path to bugpoint itself. |
| 54 | Result = ProgramPath; |
Reid Spencer | dd04df0 | 2005-07-07 23:21:43 +0000 | [diff] [blame] | 55 | Result.eraseComponent(); |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 56 | if (!Result.isEmpty()) { |
Reid Spencer | dd04df0 | 2005-07-07 23:21:43 +0000 | [diff] [blame] | 57 | Result.appendComponent(ExeName); |
Reid Spencer | c7f0832 | 2005-07-07 18:21:42 +0000 | [diff] [blame] | 58 | if (Result.canExecute()) |
Reid Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame] | 59 | return Result; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 62 | return sys::Program::FindProgramByName(ExeName); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 63 | } |