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 | |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 15 | #include "llvm/Support/SystemUtils.h" |
Reid Spencer | 436f23e | 2005-01-01 23:56:20 +0000 | [diff] [blame] | 16 | #include "llvm/System/Process.h" |
Misha Brukman | dca7978 | 2005-04-22 19:13:22 +0000 | [diff] [blame] | 17 | #include "llvm/System/Program.h" |
Chris Lattner | 74382b7 | 2009-08-23 22:45:37 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 20 | |
Chris Lattner | b683ea4 | 2009-08-23 21:36:09 +0000 | [diff] [blame] | 21 | bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check, |
Dan Gohman | d890de1 | 2009-07-15 17:04:50 +0000 | [diff] [blame] | 22 | bool print_warning) { |
Dan Gohman | ec08046 | 2009-09-11 20:46:33 +0000 | [diff] [blame] | 23 | if (stream_to_check.is_displayed()) { |
Dan Gohman | d890de1 | 2009-07-15 17:04:50 +0000 | [diff] [blame] | 24 | if (print_warning) { |
Chris Lattner | b683ea4 | 2009-08-23 21:36:09 +0000 | [diff] [blame] | 25 | errs() << "WARNING: You're attempting to print out a bitcode file.\n" |
Dan Gohman | 303f350 | 2010-11-03 00:24:33 +0000 | [diff] [blame] | 26 | "This is inadvisable as it may cause display problems. If\n" |
| 27 | "you REALLY want to taste LLVM bitcode first-hand, you\n" |
| 28 | "can force output with the `-f' option.\n\n"; |
Reid Spencer | 52b50a6 | 2005-01-02 00:10:03 +0000 | [diff] [blame] | 29 | } |
Reid Spencer | 436f23e | 2005-01-01 23:56:20 +0000 | [diff] [blame] | 30 | return true; |
| 31 | } |
Brian Gaeke | 8507ecb | 2004-04-02 21:26:04 +0000 | [diff] [blame] | 32 | return false; |
Chris Lattner | b234d46 | 2004-04-02 05:04:03 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Mikhail Glushenkov | d66f2b7 | 2010-11-03 16:14:16 +0000 | [diff] [blame^] | 35 | /// PrependMainExecutablePath - Prepend the path to the program being executed |
| 36 | /// to \p ExeName, given the value of argv[0] and the address of main() |
| 37 | /// itself. This allows us to find another LLVM tool if it is built in the same |
| 38 | /// directory. An empty string is returned on error; note that this function |
| 39 | /// just mainpulates the path and doesn't check for executability. |
| 40 | /// @brief Find a named executable. |
| 41 | sys::Path llvm::PrependMainExecutablePath(const std::string &ExeName, |
| 42 | const char *Argv0, void *MainAddr) { |
Dan Gohman | 197f728 | 2009-08-05 20:21:17 +0000 | [diff] [blame] | 43 | // Check the directory that the calling program is in. We can do |
Daniel Dunbar | 93696a3 | 2009-07-01 15:26:13 +0000 | [diff] [blame] | 44 | // this if ProgramPath contains at least one / character, indicating that it |
Daniel Dunbar | a00e85c | 2009-07-12 20:23:56 +0000 | [diff] [blame] | 45 | // is a relative path to the executable itself. |
Dan Gohman | 197f728 | 2009-08-05 20:21:17 +0000 | [diff] [blame] | 46 | sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr); |
Reid Spencer | dd04df0 | 2005-07-07 23:21:43 +0000 | [diff] [blame] | 47 | Result.eraseComponent(); |
Mikhail Glushenkov | 345b344 | 2010-11-02 20:32:46 +0000 | [diff] [blame] | 48 | |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 49 | if (!Result.isEmpty()) { |
Reid Spencer | dd04df0 | 2005-07-07 23:21:43 +0000 | [diff] [blame] | 50 | Result.appendComponent(ExeName); |
Mikhail Glushenkov | ed724fd | 2010-11-02 22:18:28 +0000 | [diff] [blame] | 51 | Result.appendSuffix(sys::Path::GetEXESuffix()); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Mikhail Glushenkov | 8a5ff47 | 2010-10-28 19:33:04 +0000 | [diff] [blame] | 54 | return Result; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 55 | } |