Implement a function to print a warning if bytecode output is to be sent to
[oota-llvm.git] / lib / Support / SystemUtils.cpp
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.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Support/SystemUtils.h"
16 #include "llvm/System/Program.h"
17 #include "llvm/System/Process.h"
18 #include <iostream>
19
20 using namespace llvm;
21
22 bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check) {
23   if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) {
24     std::cerr << "WARNING: You're attempting to print out a bytecode file.\n";
25     std::cerr << "This is inadvisable as it may cause display problems. If\n";
26     std::cerr << "you REALLY want to taste LLVM bytecode first-hand, you can\n";
27     std::cerr << "force output with the `-f' option.\n\n";
28     return true;
29   }
30   return false;
31 }
32
33 /// FindExecutable - Find a named executable, giving the argv[0] of program
34 /// being executed. This allows us to find another LLVM tool if it is built
35 /// into the same directory, but that directory is neither the current
36 /// directory, nor in the PATH.  If the executable cannot be found, return an
37 /// empty string.
38 ///
39 #undef FindExecutable   // needed on windows :(
40 sys::Path llvm::FindExecutable(const std::string &ExeName,
41                                const std::string &ProgramPath) {
42   // First check the directory that the calling program is in.  We can do this  
43   // if ProgramPath contains at least one / character, indicating that it is a
44   // relative path to bugpoint itself.
45   sys::Path Result ( ProgramPath );
46   Result.elideFile();
47   if (!Result.isEmpty()) {
48     Result.appendFile(ExeName);
49     if (Result.executable()) 
50       return Result;
51   }
52
53   return sys::Program::FindProgramByName(ExeName);
54 }