Reverting back to original 1.8 version so I can manually merge in patch.
[llvm-complete.git] / lib / Support / SystemUtils.cpp
blob88c3515920ffd8095fc64c0431a58f23a4e4da62
1 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains functions used to do a variety of low-level, often
11 // system-specific, tasks.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/SystemUtils.h"
16 #include "llvm/System/Process.h"
17 #include "llvm/System/Program.h"
18 #include <iostream>
19 using namespace llvm;
21 bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check,
22 bool print_warning) {
23 if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) {
24 if (print_warning) {
25 std::cerr << "WARNING: You're attempting to print out a bytecode file.\n"
26 "This is inadvisable as it may cause display problems. If\n"
27 "you REALLY want to taste LLVM bytecode first-hand, you\n"
28 "can force output with the `-f' option.\n\n";
30 return true;
32 return false;
35 /// FindExecutable - Find a named executable, giving the argv[0] of program
36 /// being executed. This allows us to find another LLVM tool if it is built
37 /// into the same directory, but that directory is neither the current
38 /// directory, nor in the PATH. If the executable cannot be found, return an
39 /// empty string.
40 ///
41 #undef FindExecutable // needed on windows :(
42 sys::Path llvm::FindExecutable(const std::string &ExeName,
43 const std::string &ProgramPath) {
44 // First check the directory that the calling program is in. We can do this
45 // if ProgramPath contains at least one / character, indicating that it is a
46 // relative path to bugpoint itself.
47 sys::Path Result ( ProgramPath );
48 Result.eraseComponent();
49 if (!Result.isEmpty()) {
50 Result.appendComponent(ExeName);
51 if (Result.canExecute())
52 return Result;
55 return sys::Program::FindProgramByName(ExeName);