Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains functions used to do a variety of low-level, often |
| 11 | // system-specific, tasks. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Support/Streams.h" |
| 16 | #include "llvm/Support/SystemUtils.h" |
| 17 | #include "llvm/System/Process.h" |
| 18 | #include "llvm/System/Program.h" |
| 19 | #include <ostream> |
| 20 | using namespace llvm; |
| 21 | |
| 22 | bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check, |
| 23 | bool print_warning) { |
| 24 | if (stream_to_check == cout.stream() && |
| 25 | sys::Process::StandardOutIsDisplayed()) { |
| 26 | if (print_warning) { |
| 27 | cerr << "WARNING: You're attempting to print out a bitcode file.\n" |
| 28 | << "This is inadvisable as it may cause display problems. If\n" |
| 29 | << "you REALLY want to taste LLVM bitcode first-hand, you\n" |
| 30 | << "can force output with the `-f' option.\n\n"; |
| 31 | } |
| 32 | return true; |
| 33 | } |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | /// FindExecutable - Find a named executable, giving the argv[0] of program |
| 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 | b51088c | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 41 | /// empty string. Return the input string if given a full path to an executable. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 42 | /// |
| 43 | #undef FindExecutable // needed on windows :( |
| 44 | sys::Path llvm::FindExecutable(const std::string &ExeName, |
| 45 | const std::string &ProgramPath) { |
Daniel Dunbar | 8c217fd | 2009-07-01 21:36:28 +0000 | [diff] [blame] | 46 | // First check if the given name is already a valid path to an executable. |
Daniel Dunbar | b51088c | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 47 | sys::Path Result(ExeName); |
Daniel Dunbar | 8c217fd | 2009-07-01 21:36:28 +0000 | [diff] [blame] | 48 | Result.makeAbsolute(); |
| 49 | if (Result.canExecute()) |
Daniel Dunbar | b51088c | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 50 | return Result; |
| 51 | |
| 52 | // Otherwise check the directory that the calling program is in. We can do |
| 53 | // this if ProgramPath contains at least one / character, indicating that it |
Daniel Dunbar | bf8e871 | 2009-07-12 20:23:56 +0000 | [diff] [blame] | 54 | // is a relative path to the executable itself. |
Daniel Dunbar | b51088c | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 55 | Result = ProgramPath; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 56 | Result.eraseComponent(); |
| 57 | if (!Result.isEmpty()) { |
| 58 | Result.appendComponent(ExeName); |
| 59 | if (Result.canExecute()) |
| 60 | return Result; |
| 61 | } |
| 62 | |
| 63 | return sys::Program::FindProgramByName(ExeName); |
| 64 | } |