1 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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"
21 bool llvm::CheckBytecodeOutputToConsole(std::ostream
* stream_to_check
,
23 if (stream_to_check
== &std::cout
&& sys::Process::StandardOutIsDisplayed()) {
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";
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
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())
55 return sys::Program::FindProgramByName(ExeName
);